// ## 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();
// 	modelarrowSwap();


var menuTimeout;
var submenuTimeout;
var currentMenu;
var currentsubMenu;
var imgPathNav;
var imgPath;
//var BaseHREF = "http://localhost/college/templates/default";
//var BaseHREF = "..";

if (BaseHREF) {
	var imgPathNav = BaseHREF + "/images/"; 	// Image path location for Global Nav menu images.
	var imgPath = BaseHREF + "/images/"; 	// Image path location for all other images.
} else {
	var imgPathNav = "/images/"; 	// Image path location for Global Nav menu images.
	var imgPath = "/images/"; 		// 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. menu categories
// 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()', 6000);		// 3000 set the timeout
}

function submenuOn(submenuName) {
	var thesubMenu
	if (!navIsLoaded) return;	// check if initialization is complete
	if (submenuTimeout) clearTimeout(submenuTimeout);	// clear the timeout

	if (currentsubMenu) {			// hide the current menu
		thesubMenu = eval(currentsubMenu);
		thesubMenu.hide();
	}
	currentsubMenu = submenuName;
	thesubMenu = eval(currentsubMenu);theMenu = eval(currentMenu);
	thesubMenu.show();theMenu.show();				// display menuName
	submenuTimeout = setTimeout(currentsubMenu + '.hide()', 6000);	// 3000 set the timeout
}

// Hides the dropdown menus
// inputs: menuName - name of the menu DIV layer without the Div.  ie. menu categories
// 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()', 1500);		// 500 set the new timeout
}

function submenuOff(submenuName) {

	if (!navIsLoaded) return	// check if initialization is complete

	if (submenuTimeout) clearTimeout(submenuTimeout)	// clear the current timeout
	submenuTimeout = setTimeout(submenuName + '.hide()', 1000);		// 330 set the new timeout
}


// 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 + "tnav_lnk_" + 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 + "tnav_lnk_" + imgName + ".gif";
	menuOff(currentMenu);
}

function submenuLinkOn(imgName) {
	var theImage;

	if (menuTimeout) clearTimeout(menuTimeout);
	//Next line added by AG: 12/19/2002
	if (submenuTimeout) clearTimeout(submenuTimeout);
	
	//Next line modifies by AG: 12/19/2002. Changed currentMenu to currentsubMenu.
	theImage = (is.ns4) ? eval("document.layers['" + currentsubMenu + "Div'].document.images['" + imgName + "']") : eval("document." + imgName);
	theImage.src = imgPathNav + "tnav_lnk_" + imgName + "_on.gif";
}

// Swaps the menu image to the OFF state.
function submenuLinkOff(imgName) {
	var theImage;
	
	//Next line modifies by AG: 12/19/2002. Changed currentMenu to currentsubMenu.
	theImage = (is.ns4) ? eval("document.layers['" + currentsubMenu + "Div'].document.images['" + imgName + "']") : eval("document." + imgName);
	theImage.src = imgPathNav + "tnav_lnk_" + imgName + ".gif";
	
	submenuOff(currentsubMenu);
	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"
}

// Swaps the arrow image.
// input: 	imgName - name of the image
//			ON - on or off state
function arrowSwap(linkName, ON, obj, obj2) {
	var theImage = 'document.'

	if (obj && is.ie) {
		theImage += 'all.'
	} else if (obj && is.ns) {
	 	theImage += obj + '.document.'
	}

	if (obj2 && is.ns) {
			theImage += obj2 + '.document.'
		}
	
	theImage += linkName
	
	theImageObj = eval(theImage);
	theImageObj.src = imgPath + "gl_arrow" + ((ON) ? "_on":"") + ".gif";
}

// Swaps the arrow image.
// input: 	imgName - name of the image
//			ON - on or off state
function modelarrowSwap(linkName, ON, obj, obj2) {
	var theImage = 'document.'

	if (obj && is.ie) {
		theImage += 'all.'
	} else if (obj && is.ns) {
	 	theImage += obj + '.document.'
	}

	if (obj2 && is.ns4) {
		theImage += "layers['" + obj2 + "Div'].document.images['";
	}
	
	theImage += (is.ns4) ? linkName + "']" : linkName;

	theImageObj = eval(theImage);
	theImageObj.src = imgPath + "model_arrow" + ((ON) ? "_on":"") + ".gif";
	
}



// Swaps the 'up' arrow image.
// input: 	imgName - name of the image
//			ON - on or off state
function arrowSwapUp(linkName, ON, obj, obj2) {
	var theImage = 'document.'

	if (obj && is.ie) {
		theImage += 'all.'
	} else if (obj && is.ns) {
	 	theImage += obj + '.document.'
	}

	if (obj2 && is.ns) {
		theImage += obj2 + '.document.'
	}

	theImage += linkName
	theImageObj = eval(theImage);

	theImageObj.src = imgPath + "gl_arrow_up" + ((ON) ? "_on":"") + ".gif";
}

// this function is used gobally to open a popup window
//usage
//<A HREF="javascript:displayWindow('sample/csc_258.htm')">CSC 258</A>
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=500' + width + ',height=400' + height + ',resizable=yes,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,status=yes' );
}

