/*Dropdownmegamenu javascript to delay the disappearance of the menu when the user mouses out.  Uses jquery library.*/

$(document).ready(function() {

	var timer =null;
	var delay = 500; //change this number for shorter or longer delay
	
	$("#dropdownmegamenu > ul > li").hover(
	
		//what happens on hover over
   	 	 function(){
		 	//end timer and stop hiding if they are mousing back in.
		 	if (timer != null) {
		 		clearTimeout(timer);
				timer=null;
			}
       	 	// Find the hovered menu's sub-menu
			var $menu = $(this);
        	var $submenu = $(this).find('.megamenu_container');

        	// hide any other submenus that are open
        	$('.megamenu_container').not($submenu).css('display','none');
			$('.megamenu_over').not($menu).removeClass('megamenu_over');

        	// show current menu
        	$submenu.css('display','block');
			$menu.addClass('megamenu_over');
    	},
		
		//what happens on mouse out
		function(){
    		var $submenu = $(this).find('.megamenu_container');
			var $menu = $(this);
			// delay disappearance
			timer = setTimeout(function(){$submenu.css('display','none');$menu.removeClass('megamenu_over'); timer=null;}, delay);
		}
		
	)

});


