	var elementToOpen = 0
    var lastElement = 0
    var bAnimation = false
	var myTimer
	
	var openWaitTime = 100
	
    jQuery(document).ready(function(){
	//number of elements multiplied by the height of the link
	//var iHomeHeight = jQuery("#VertMenu li.Home").find("li.Level1").length * 16;
	//jQuery("#VertMenu li.Level0 ul:first").height(iHomeHeight);
	//jQuery("#VertMenu li.Level0 ul.Admin").height("auto");
	//jQuery("#VertMenu li.Level0 ul.Host").height("auto");

		if (lastElement == 0){
		//Store the last element that was animated
			lastElement = jQuery("#VertMenu li.Level0.Active").attr("id")
			if (lastElement == undefined){
				lastElement = jQuery("#VertMenu li.Level0.ActiveParent").attr("id")
			}
		}
		
		//Add an  event to the menu items
        jQuery("#VertMenu li.Level0").mouseenter(
        function ChangeMenu(){
			elementToOpen = jQuery(this).attr("id")
			countDownToAnimation()
		});
    });
	
	function OpenCloseMenu(){
		//only run if the animation is not running
		if (!bAnimation){ 
			if (elementToOpen != lastElement && jQuery("#" + lastElement).find("ul:first").length > 0) {
			//Close the open menu
			jQuery("#" + lastElement).find("ul:first").slideUp(600);
			//We are animating now..
			bAnimation = true
			}
			//Open the hovered menu item
			if (jQuery("#" + elementToOpen).find("ul:first").length > 0){
				jQuery("#" + elementToOpen).find("ul:first").slideDown(600, AnimationReady);
			}
			else{
				AnimationReady()
			}
			//jQuery(this).addClass("Active");
			lastElement = elementToOpen
		}
		else{
			countDownToAnimation ()
		}
	}
	
	function countDownToAnimation (){
		clearTimeout(myTimer)
		myTimer = setTimeout(OpenCloseMenu, openWaitTime) 
	}

    function AnimationReady(){
        setTimeout(resetAnimation, 1) 
    }
    
    function resetAnimation(){
        bAnimation = false
    }

