/* 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;


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

var path = "http://ewh.org/ewhsys/template_files/images/";

function highlightTab(num) {
	//set background image on main menu item
	div = getElement('atab'+num);
    
    //alert("hl " + num);

	if (div != null) {
        div.style.backgroundImage = "url('" + path + "tab_bkgd_on.gif')";
	}
}

function restoreTab(num) {
	//restore background image on main menu item

	div = getElement('atab'+num);
    
    //alert(num);

	if (div != null && num != active_page) {
        div.style.backgroundImage = "url('" + path + "tab_bkgd.gif')";
	}
}
function showMenu(num) {
	//display the top level menu and hide any menus that are open
	
	for (var i=1; i<=numMenus; i++) {
		if (i != num) { 
			hideDiv('menu'+i); //hide open menus
			restoreTab(i); 
		}
	}
	showDiv('menu'+num);
}

function hideMenus() {

	hideDiv('menu'+menuNum);
	restoreTab(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;
}


