
// processes the mega drop down menu
$(document).ready(function() {

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		//$(this).addClass("selected");
		//console.log($(this));
	}
	
	function megaHoverOut(){ 
	  	$(this).find(".sub").stop().fadeTo('fast', 0, function() {
			  $(this).hide(); 
		});
		//$(this).removeClass("selected");
		//console.log($(this));
	}

	// setup the menu hover configuration
	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	
	
	// fix the menu backgrounds for the top level items
	$("ul#topnav li a.toplevel").each(function(index,item){

		// determine the background position to use
		var bgPos = (($(item).parent().position().left) * -1) - (5 * index) + "px 0px";
		
		// set the background position for the menu item
		$(item).css("backgroundPosition", bgPos);

	});
	
	// fix the menu arrows so that the left position is in the middle of hte parent
	$("ul#topnav .sub div.arrow").each(function(index,item){

		// set the left position for the arrow item
		$(item).css("left", (($(item).parent().parent().width() / 2) - 3) + "px");
	});
});
