/* JavaScript Document - Cascading menu functions

author: Carol Thomson, cthomson@firestreammedia.com
*/

var isNS4	= (document.layers) ? true : false;
var isIE4	= (document.all && !document.getElementById) ? true : false;
var isIE5	= (document.all && document.getElementById) ? true : false;
var isNS6	= (!document.all && document.getElementById) ? true : false;

//menu colors
var dark = "#CCCCCC";
var light = "#EBEBEB";  
var white = "#FFFFFF";
var red = "#CC0000";
var black = "#000000";

var timerId;
var numMenus = 5;  //total number of top-level menus
var menuNum = -1;  //global for menu timeout

function showPage(page) {

	document.location = path + page;
}

function hlItem(div) {
	/*  highlight the menu item 
		div is the menu item div
    */
	
	//set the highlight background color for the menu item
	if (div != null) { 
		div.style.backgroundColor = light;	
		div.style.color = red;
	}
	
}

function rstItem(div) {
	/*  restore the menu item 
		div is the menu item div
    */
	if (div != null) {
		//restore the menu item
		div.style.backgroundColor = dark;	
		div.style.color = black;
	}
}

function highlightItemById(id,num) {
	hlItem(getElement(id),num);
}

function restoreItemById(id,num) {
	rstItem(getElement(id),num);
}

function restoreMainItem(num) {
	//restore background color on main menu item
	div = getElement('item'+num);
	if (div != null) {
		div.style.backgroundColor = light;
	}
}

function showMenu(num) {
	//display the top level menu and hide any menus that are open
	//alert("show " + num);
	
	div = getElement("item"+num);
	if (div != null) {
		div.style.backgroundColor = white;	
	}
	
	for (var i=1; i<=numMenus; i++) {
		if (i != num) { 
			hideDiv('menu'+i);
			restoreMainItem(i);
		}
	}
	showDiv('menu'+num);
}

function hideMenus() {
	hideDiv('menu'+menuNum);
	restoreMainItem(menuNum);
}

function startTimer(num) {
	menuNum = num;
	timerId = setTimeout("hideMenus()", 500);	
}

function stopTimer() {
	clearTimeout(timerId);
}

function swapDivs(showDivName, hideDivName) {
	hideDiv(hideDivName);
	showDiv(showDivName);
}

function hideDiv(divName) {
	getElement(divName).style.display = "none";
}

function showDiv(divName) {
	//alert("show " + divName);
	getElement(divName).style.display = "block";
}

function getElement(id) {
	//return a reference to an element (div, image, form, etc) given is id
	var elem;
	if (id == "") { return null; }
	if (isNS4) {												   // NS4 is not supported
	} 
	else if (isNS6) {											   // Netscape 6 +
		elem = document.getElementById(id);
	} 
	else {													   // IE and everything else
		elem = document.all[id];
	}

	return elem;
}


