var jq = jQuery.noConflict();

jq(document).ready( function() {
	// Header State 
		var cookiepath = {
			path: '/'
		};
	var showTop = jq.cookies.get("showTop");
	//alert(showTop);
	//alert(showTop + " cookiestate");

	// Set the user's selection for the Header State  
	if (showTop != 'expanded') {
		jq(".Menu3.ddsubmenu").hide(); 
	};
	jq(".Menu3.current").show();

	//Setup functions for replacing img src
	highlight = function() {
		this.src = this.src.replace( '_off', '_on' );
	}
	lowlight = function() {
		this.src = this.src.replace( '_on', '_off' );
	};
	
	//Precache Nav Highlight Imgs
	var precache = [];
	var precacheCounter = 0;
	
	//Collect Precaching Imgs into Array
	//jq('.Menu2 .section img, .Menu2 .current img, .Menu1 .section img, .Menu1 .current img').each(function(i){
	//	precache[precacheCounter] = new Image();
	//	precache[precacheCounter].src = this.src.replace( '_off', '_on' );
	//	precacheCounter++;
	//});
	jq('.Menu2 .section img, .Menu2 .current img, .Menu1 .section img, .Menu1 .current img').each(highlight);
	jq('.Menu2 .link img, .Menu1 .link img, #MiniMenu .Menu0 .link img').each(function(i){
		precache[precacheCounter] = new Image();
		precache[precacheCounter].src = this.src.replace( '_off', '_on' );
		precacheCounter++;
	});
	
	jq('.Menu2 .link img, .Menu1 .link img, #MiniMenu .Menu0 .link img').hover(highlight,lowlight);
	
	//Setup Menu hidden states
	jq("#MainMenu").find(".Menu4").animate({"height":"hide"},50); //Needs to be set individually for IE
	jq("#MainMenu").find(".Menu3").animate({"height":"hide"},50); //stupid IE
	jq("#MainMenu").find(".Menu2").animate({"height":"hide"},50); //why is IE even used anymore


	var mainmenu = {		//mainmenu dropdown setup
		sensitivity: 3, 	// number = sensitivity threshold (must be 1 or higher)
		interval: 100,		// number = milliseconds for onMouseOver polling interval
		over: expand,		// function = onMouseOver callback (REQUIRED)
		timeout: 250,		// number = milliseconds delay before onMouseOut
		out: contract		// function = onMouseOut callback (REQUIRED)
	};
	
	var ddmenu = {		//mainmenu dropdown setup
		sensitivity: 3, 	// number = sensitivity threshold (must be 1 or higher)
		interval: 100,		// number = milliseconds for onMouseOver polling interval
		over: ddexpand,		// function = onMouseOver callback (REQUIRED)
		timeout: 500,		// number = milliseconds delay before onMouseOut
		out: ddcontract		// function = onMouseOut callback (REQUIRED)
	};
	
	jq(".Menu1 li").hoverIntent(mainmenu);
	
	function expand(){
		jq(this).contents().next(".submenu:first").animate({"height":"show"},100);
	};
	
	function contract(){
		jq(this).contents(".submenu").animate({"height":"hide"},50);
	};
	
	//jq("#LeftCol dt a").click(function(){
	//	jq("dd:visible").slideUp("slow");
	//	jq(this).parent().next().slideDown("fast");
	//	return false;
	//});
	jq("#LeftCol ul.Menu2 li a.DDM").hoverIntent(ddmenu);
	
	function ddexpand(){
		jq(".ddsubmenu:visible").animate({"height":"hide"},100);
		jq(this).next(".ddsubmenu").animate({"height":"show"},100);
		opencookie();
	};
	
	function ddcontract(){
	};
	
	// COOKIES
	// Functions to set showTop versions
	closedcookie = function() {
		jq.cookies.set('showTop', 'collapsed');
	};
	opencookie = function() {
		jq.cookies.set('showTop', 'expanded');
	};
	
	jq("#LeftCol ul.Menu2 li a.DDM").click(closedcookie);
	jq("#LeftCol ul.Menu3 a").hover(opencookie);
	jq("#LeftCol ul.Menu3 a").click(opencookie);
	
});