// JavaScript Document
$(document).ready(function(){
	$("ul#mainNav li").mouseover(function() {   
			 ddValue = $(this).width(); 
			 dropdownWidth(ddValue);
	});
	
	
	function dropdownWidth(altVal)
	{
		var ddNewValue =  altVal;
		if(ddNewValue <= 140){
			$("ul#mainNav li ul").width(140);
			$("ul#mainNav li ul li").width(140);
		}
		else{
			$("ul#mainNav li ul").width(ddNewValue);
			$("ul#mainNav li ul li").width(ddNewValue);	
		}
	}
   
   
	$('ul#mainNav li').each(function(index) {		
		if($(this).hasClass("activestate").toString()=="true"){
			hidenavigation();
		}
	});
   
	
	function hidenavigation(){	
		$('ul#mainNav li.activestate ul').attr('style', 'display:none !important');
	}
	
	
	var config = {over: mainNavFlyoutShow, timeout: 0, out: mainNavFlyoutHide};
	
	$("ul#mainNav>li>ul").parent("li").hoverIntent(config);
	
	function mainNavFlyoutShow() {
		if($(this).hasClass("activestate").toString()!="true"){
			$(this).find("ul").slideDown(200);
		}	
		
	}
	
	function mainNavFlyoutHide() {
		$(this).find("ul").slideUp(100);
	}

	$("ul#mainNav li").hover( mainNavHoverShow, mainNavHoverHide );
	
	function mainNavHoverShow() {
		if($(this).hasClass("activestate").toString()!="true"){			
			$(this).addClass("hover");			
		}			
	}
	
	function mainNavHoverHide() {
		$(this).removeClass("hover");
	}
   
   
 	if($("#searchform").length == 0){	
		$("#utilNav").css("right", "0");		
	}
   
	if($.browser.msie){	   
	   userAgent = $.browser.version;
	   userAgent = userAgent.substring(0,userAgent.indexOf('.'));
	   var version = userAgent;
	   
		$('#bodycontainer').find("ol").css("padding", "0 0 4px 22px !important");
		$('#rightsection').find("ol").css("padding", "0 0 4px 22px !important");	
		
		if(version == "8"){
			$('#search-form-button').css("top","3px");
			$("#utilNav").css("top","13px");
		}
	}
	else{
		$('#search-form-button').css("top","3px");		
	}
	
	if($.browser.mozilla){
		$('#search-form-button').css("top","3px");
	}
		
		
	var deviceAgent = navigator.userAgent.toLowerCase();	
	var agentValue = deviceAgent.match(/(iphone|ipod|ipad)/);
	
	if (agentValue) { 	
			agentValue  = agentValue.toString();
			agentValueArray = new Array();
			agentValueArray  = agentValue.split(',');
			if(agentValueArray[0] == "ipad"){
				$('ul#mainNav').css('top',"71px");
			}
			$('#utilNav').css('right',"178px");
	}	
   
	// Jquery Ends
});
