var mainNavTimer;
var mainNavTimerInterval = 200;
$(document).ready(function() {	
	$("#mainNav>ul>li>a").mouseover(function() {
		$("select").blur();
		var tempLinkWidth = 0;
		clearTimeout(mainNavTimer);															  
		$("#mainNav>ul>li").removeClass("navOver");
		$("#mainNav>ul>li").removeClass("navOverNoChild");
		$("#mainNav>ul>li>ul").hide();	
		if($(this).next().html() !== null){
			$(this).parents().addClass("navOver");
		}else{
			$(this).parents().addClass("navOverNoChild");			
		}		
		var offset = $(this).parents().position();
		var menuLeft = offset.left;
		var menuTop = offset.top + $(this).parents().height();
					
		$(this).next().css("left",menuLeft); 
		$(this).next().css("top",menuTop); 		
		$(this).next().show();	
		
		var pageOffset = $(this).parents().offset();	
		
		for(var linkLoop=0; linkLoop < $(this).next().find("a").length; linkLoop++){			
			if ($(this).next().find("a").eq(linkLoop).width() > tempLinkWidth){				
				tempLinkWidth = $(this).next().find("a").eq(linkLoop).width();
			}					
		}	
		if($(this).width() >= tempLinkWidth){
			tempLinkWidth = $(this).parents().width();
		}
		for(var linkLoop=0; linkLoop < $(this).next().find("a").length; linkLoop++){				
			$(this).next().find("a").eq(linkLoop).css("width",tempLinkWidth);							
		}		
		if(menuLeft + $(this).next().width() > $("#page").width()){
			var paddingWidth = $(this).parents().css("paddingLeft").split("px");
			paddingWidth = parseFloat(paddingWidth[0]);				
			$(this).next().css("left",(menuLeft - $(this).next().width()) + ($(this).parents().width() + paddingWidth)); 
		}
		var menuWidth = $(this).next().width();	
		var menuHeight = $(this).next().height() + $("#mainNav").height();	
		hideSelectBoxes(pageOffset.left,pageOffset.top,menuWidth,menuHeight);
	});	
	$("#mainNav>ul>li>a").mouseout(function() {					
		mainNavTimer = setTimeout("$(\"#mainNav>ul>li>ul\").hide();$(\"#mainNav>ul>li\").removeClass(\"navOver\");$(\"#mainNav>ul>li\").removeClass(\"navOverNoChild\");showAllSelectBoxes();",mainNavTimerInterval);	     
	});	
	$("#mainNav>ul>li>ul").mouseover(function() {
		clearTimeout(mainNavTimer);			
	});	
	$("#mainNav>ul>li>ul").mouseout(function() {					
		mainNavTimer = setTimeout("$(\"#mainNav>ul>li>ul\").hide();$(\"#mainNav>ul>li\").removeClass(\"navOver\");$(\"#mainNav>ul>li\").removeClass(\"navOverNoChild\");showAllSelectBoxes();",mainNavTimerInterval);	     
	});		
});  
