var d = document;
var gDelayToggle = "on";
var myGlobalVar1 = null;
var myGlobalVar2 = null;
var gHideTimer = null; //global timer for the hide timeout

function prepareNav(){
	if (!d.getElementById("mainnav")) return false;
	if (!d.getElementsByTagName("DD")) return false;
	var nav = d.getElementsByTagName("DD");
	for (var i = 0; i < nav.length; i++) {
		addNav(nav[i]);
	}
}

function addNav(whichnav){
	//this function will add the mouseover and mouseout events to the whichnav object
	if (whichnav.className == "nav" || whichnav.className == "nav_adj_left") {
		whichnav.onmouseover = function(){
			myGlobalVar1 = this;
			showNav(myGlobalVar1, 'show');
		}
		whichnav.onmouseout = function(){
			myGlobalVar1 = this;
			if (gDelayToggle == "off") {
				showNav(myGlobalVar1, 'hide');
			}
			else {
				gHideTimer = setTimeout("showNav(myGlobalVar1, 'hide')", 4000);
			}
		}
		//the first "dd" nav bar does not have the "nav" class and requires only the show mouseover event.
	}
	else if (whichnav.className == "on") {
		whichnav.onmouseover = function(){
			myGlobalVar1 = this;
			showNav(myGlobalVar1, 'hide');
		}
	}
}

function showNav(whichnav, navtype){
	//this function toggles the nav to the specific object.
	//whichnav is the object, navtype is the toggle switch.  it can be either "show" or "hide"
	if (navtype == "show") {
		if (gHideTimer) { //if the hide timer is currently counting..
			clearTimeout(gHideTimer); //disable the hide timer
		}
		var list = whichnav.getElementsByTagName("UL");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className == "nav_off") {
				clearNav();
				list[i].className = "nav_display";
				var nav = d.getElementsByTagName("UL");
				for (var j = 0; j < nav.length; j++) {
					if (nav[j].className == "nav_current") {
						nav[j].className = "nav_current_off";
					}
				}
			}
		}
	}
	else if (navtype == "hide") {
		if (!d.getElementById("mainnav")) return false;
		if (!d.getElementsByTagName("UL")) return false;
		var list = d.getElementById("mainnav").getElementsByTagName("DD");
		for (var i = 0; i < list.length; i++) {
			var nav = d.getElementsByTagName("UL");
			for (var j = 0; j < nav.length; j++) {
				if (nav[j].className == "nav_current_off") {
					nav[j].className = "nav_current";
				}
				else if (nav[j].className == "nav_display") {
					nav[j].className = "nav_off";
				}
			}
			if (list[i].className == "off") {
				list[i].className = "on";
			}
		}
	}
}

function clearNav(){
	//This function clears the navigation menu entirely.
	var list = d.getElementById("mainnav").getElementsByTagName("DD");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className == "nav" || list[i].className == "on") {
			var lista = list[i].getElementsByTagName("UL");
			for (var j = 0; j < lista.length; j++) {
				if (lista[j].className == "nav_current" || lista[j].className == "nav_current_off") {
					lista[j].className = "nav_current_off";
				}
				else {
					lista[j].className = "nav_off";
				}
			}
			if (list[i].className == "on") {
				list[i].className = "off";
			}
		}
	}
}

addLoadEvent(prepareNav);
