$(document).ready(function(){	
	$("#top-nav ul li").each(function(n){				
		var width = $(this).width();									
		var c = $(this)[0].className;		
		var p=0;
		var pWidth = $(this).parent().width();
		var cWidth = $(this).children("ul").width();										 				
		$(this).css("padding","0px").css("width",(pWidth-10)).css("padding","5px");											
	});	
	$("#top-nav > li > ul li > ul").hide();	
	$("#top-nav > li > ul").hide();
})


$(function(){	
	$("#top-nav  li").hover(
		function(){													
			var bVersion = BrowserDetect.version;
			var browser = BrowserDetect.browser;			
			var width = $(this).width();									
			var c = $(this)[0].className;		
			var p = 0; var mt=-33;                       
			if(browser == 'Explorer' && bVersion >= 8){p=5;mt = -32;}
                        if(browser == 'Explorer' && bVersion <= 8){p=5;mt = -7;p=0;}
			else if(browser == 'Firefox' || browser == 'Chrome' || browser == 'Safari'){p = 5}						
			if(c.indexOf("sub-menu") != -1){						
				var pWidth = $(this).parent().width();
				var cWidth = $(this).children("ul").width();
				$(this).children("ul").css("height","auto");
				$(this).children("ul").css("margin-left",parseInt(pWidth-p)+"px").css("margin-top",mt+"px");                                                                                               
			}	
			else{
				var pWidth = $(this).width();
				var cWidth = $(this).children("ul").width();
				if(cWidth < (pWidth+18)){
                                    $(this).children("ul").css("width",(pWidth+18)+"px");
                                    $(this).children("ul").children("li").css("width",(pWidth+8)+"px");
                                }
			}			
			
			if(browser == 'Explorer' && c.indexOf("sub-menu") == -1){
                                if( bVersion <= 7){$(this).children("ul")[0].style.marginLeft = "-"+(width+10)+"px";}
				//else if(bVersion == 9){$(this).children("ul")[0].style.marginLeft = "-"+(width+10)+"px";}                                
			}						
			$(this).children("ul").show();																
		},
		function(){$(this).children("ul").hide();}
	);	
});

