$(document).ready(function() {

	$("#nav > li").hover(function(e) { //Hover over event on list item
		//var padLeft = this.offsetLeft;	
		//var widthCal = 1000-padLeft;
		//$(this).find("ul:first").css({paddingLeft:padLeft+'px',width:widthCal+'px',visibility: "visible",display: "none"}).show('fast'); //Show the subnav
		//$(this).find("ul:first").css({paddingLeft:0+'px',width:widthCal+'px',visibility: "visible",display: "none"}).show('fast'); //Show the subnav	
		$(this).find("ul:first").css({visibility: "visible",display: "none"}).show('fast'); //Show the subnav	
		$(this).find("ul:first a:first").css({paddingLeft:'15px'});
		
		$(this).find('a:first').css({backgroundPosition : '0 -76px'});
		$(this).find('span:first').css({backgroundPosition : '100% -76px',color:'white'});	
		
		$("ul#nav > li").filter(".current").find('a:first').css({backgroundPosition : '0 0'});
		$("ul#nav > li").filter(".current").find('span:first').css({backgroundPosition : '100% 0',color:'#0188c6'});	
		if ($(this).hasClass('current')) {
			$(this).find('a:first').css({backgroundPosition : '0 -76px'});
			$(this).find('span:first').css({backgroundPosition : '100% -76px',color:'white'});			
		} else {
		
		}		
	},function() { //on hover out...		
		$(this).find("ul:first").hide('fast'); //Hide the subnav
		$(this).find('a:first').css({backgroundPosition : '0 0'});
		$(this).find('span:first').css({backgroundPosition : '100% 0',color:'#0188c6'});	
	});

	$("ul#nav > li a span").wrapInner('<div></div>');	
	$("#nav > li div").css({ position:'relative', top:'3px' });
	
	/*/
	if( window.devicePixelRatio &&  window.getMatchedCSSRules ){
		$("#nav_wrapper > ul ul").css({ paddingTop:'8px'});
	}
	$("#nav_wrapper > ul ul").css({border:'1px solid red'}); 
	/**/
	
	$("ul#nav > li").filter(".current").find("ul:first").css({visibility: "visible",display: "none"}).show('fast');	
	$('ul#nav > li.current a:first').css({backgroundPosition : '0 -76px'});		
	$("ul#nav > li.current span:first").css({backgroundPosition : '100% -76px',color:'white'});	

	$("ul#nav > li").not('.current').mouseenter(function(e) { 
		$("ul#nav > li").filter(".current").find("ul:first").css({visibility: "visible",display: "none"}).hide('fast');	
	});		
	$("#nav").mouseleave(function(e) { 		
		$("ul#nav > li").filter(".current").find("ul:first").css({visibility: "visible",display: "none"}).show('fast');	
		$("ul#nav > li").filter(".current").find('a:first').css({backgroundPosition : '0 -76px'});
		$("ul#nav > li").filter(".current").find('span:first').css({backgroundPosition : '100% -76px',color:'white'});			
	});
});
