// JavaScript Document


// JavaScript Array DropDown Menu
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;



// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose;






//----- DAVE COLARIK MENU VARIABLE MODIFICATIONS ------//
//COOKIE VARIABLES






//------FUNCTIONS-----//


//if COOKIE EXISTS:  Set the class if innerHTML matches COOKIE
function testForSelectedNav(navHolderElement) {
	
	//Initialize Local/Temp Variables
	var navMenuArray = document.getElementById(navHolderElement).getElementsByTagName('a');
	//alert(navMenuArray.length + " navMenuArray.length");
	
	
	//Loop thru Stored "live" nodeList and test to see if innerHTML matches the COOKIE.innerHTML
	for(i=0; i<navMenuArray.length; i++) {
		
		
		if(navMenuArray[i].innerHTML == readCookie("navClickedCookie") ) {	
			//set className
			navMenuArray[i].className="selected";
			//alert(navMenuArray[i].innerHTML + " array.innerHTML");
		}
		else {
			//reset className
			navMenuArray[i].className="";
		}
		
	}
	//end for-loop
	
}



function navClicked(obj) {
	
	
	//Test for What's between the <open></close>
	//alert(obj.innerHTML + " obj.innerHTML");
	
	

	//SET COOKIES:  ----- DOES NOT TEST WELL IN LOCAL BROWSER -- NOT SURE WHY, But this Does work on the Server
	
	//EXCEPTION FOR LOGO:  if Logo Clicked...Overwrite Cookie to "home"
	if(obj.id == "logo") {
		//Create/Set a cookie for Conditional that stores the innerHTML
		createCookie("navClickedCookie", "home", 0);
		if(readCookie("navClickedCookie") != "") {
			//alert(readCookie("navClickedCookie") + " COOKIE");
		}
	}
	else {
		//Create/Set a cookie for Conditional that stores the innerHTML
		createCookie("navClickedCookie", obj.innerHTML, 0);
		if(readCookie("navClickedCookie") != "") {
			//alert(readCookie("navClickedCookie") + " COOKIE");
		}
	}
	
	
	//PUT HERE TO TEST ON LOCAL MACHINE
	//test COOKIE with Array ----- PUT INSIDE  <body onload="testForSelectedNav('nav');testForSelectedNav('footer');">
	//								So it runs when the new page is loaded and tests COOKIE and sets appropriate SELECTED NAVIGATION LINK
	//testForSelectedNav("nav");
	//testForSelectedNav("footer");
	

}



//---------------- EXECUTEABLE APPLICATION  ?? Seems you need to call function in <body onload> ?? ----------------------//


