// ## globalNav.js
// 	Contains the dynamic functionality for the drop down navigation found at the top of most templates.

// FUNCTION LIST:
// 	init();
// 	menuOn();
// 	menuOff();
//	menuLinkOn();
// 	menuLinkOff();
// 	linkSwap();
// 	arrowSwap();


var menuTimeout;
var currentMenu;
var imgPathNav;
var imgPath;
var BaseHREF;

if (BaseHREF) {
	var imgPathNav = BaseHREF + "/pix/menu/"; 	// Image path location for Global Nav menu images.
	var imgPath = BaseHREF + "/pix/menu/"; 	// Image path location for all other images.
} else {
	var imgPathNav = "/pix/menu/"; 	// Image path location for Global Nav menu images.
	var imgPath = "/pix/menu/"; 		// Image path location for all other images.
}

var navIsLoaded = false;

// Initializing the global navigation

// change init() to globalNavInit()
function init() {
	DynLayerInit()
	navIsLoaded = true;	// boolean to true when initialization is complete
}

// Display the dropdown menu.
// inputs: menuName  - name of the menu DIV layer without the Div.  ie. vehicles
// output: none
function menuOn(menuName) {
	var theMenu
	if (!navIsLoaded) return;	// check if initialization is complete
	if (menuTimeout) clearTimeout(menuTimeout);	// clear the timeout

	if (currentMenu) {			// hide the current menu
		theMenu = eval(currentMenu);
		theMenu.hide();
	}
	currentMenu = menuName;
	theMenu = eval(currentMenu);
	theMenu.show();				// display menuName
	menuTimeout = setTimeout(currentMenu + '.hide()', 3000);		// set the timeout
	if (menuName == 'news') {
		document.news_main.src = '/pix/menu/menu1_on.jpg';
	} else if (menuName == 'about') {
		document.about_main.src = '/pix/menu/menu2_on.jpg';
	} else if (menuName == 'products') {
		document.products_main.src = '/pix/menu/menu3_on.jpg';
	} else if (menuName == 'content') {
		document.content_main.src = '/pix/menu/menu4_on.jpg';
	} else if (menuName == 'faq') {
		document.faq_main.src = '/pix/menu/menu5_on.jpg';
	}
}

// Hides the dropdown menus
// inputs: menuName - name of the menu DIV layer without the Div.  ie. vehicles
// outputs: none
function menuOff(menuName) {

	if (!navIsLoaded) return	// check if initialization is complete

	if (menuTimeout) clearTimeout(menuTimeout)	// clear the current timeout
	menuTimeout = setTimeout(menuName + '.hide()', 330)		// set the new timeout
	if (menuName == 'news') {
		document.news_main.src = '/pix/menu/menu1_off.jpg';
	} else if (menuName == 'about') {
		document.about_main.src = '/pix/menu/menu2_off.jpg';
	} else if (menuName == 'products') {
		document.products_main.src = '/pix/menu/menu3_off.jpg';
	} else if (menuName == 'content') {
		document.content_main.src = '/pix/menu/menu4_off.jpg';
	} else if (menuName == 'faq') {
		document.faq_main.src = '/pix/menu/menu5_off.jpg';
	}
}

// Swaps the menu image to the ON state.
// input: imgName - name of the image to turn on
// output: swaps the image to the ON state
function menuLinkOn(imgName) {
	var theImage;

	if (menuTimeout) clearTimeout(menuTimeout);
	theImage = (is.ns4) ? eval("document.layers['" + currentMenu + "Div'].document.images['" + imgName + "']") : eval("document." + imgName);
	theImage.src = imgPathNav + imgName + "_on.gif";
}

// Swaps the menu image to the OFF state.
function menuLinkOff(imgName) {
	var theImage;
	theImage = (is.ns4) ? eval("document.layers['" + currentMenu + "Div'].document.images['" + imgName + "']") : eval("document." + imgName);
	theImage.src = imgPathNav + imgName + ".gif";
	menuOff(currentMenu);
}

// Swaps the link image.
// input: 	imgName - name of the image
//			ON - on or off state
function linkSwap(imgName, ON) {
	var theImage = eval("document." + imgName);
	theImage.src = imgPath + imgName + ((ON) ? "_on":"") + ".gif"
}


