/*
########################################################
/lib/js/standard.js

Common javascript sources, including menu construction.
The javascript menu functions in this file are partial;
the rest are generated on-the-fly from assorted navigation
files by nav.php.

Accepted Inputs:
none

11th October 2004
Rowan Beentje
Assanka Ltd
########################################################
*/


var browserType = "none";
var menusLoaded = false;
var theTimer = null; 
var timerRunning = false; 
var timerLimit = 500;

// initMenus handles initial setup
function initMenus() {
	if(document.getElementById && document.createElement) {
		layerRef="document.getElementByID";
		styleSwitch=".style";
		browserType="dom";
	}
	// Disable IE Mac menus
	if (navigator.userAgent.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Opera') == -1 && document.all) {
		browserType="none";
	}
	menusLoaded = true;
}

// showMenu draws a menu, which is essentially a hidden layer.
function showMenu(theMenu) { 
	if ((browserType == "none") || (menusLoaded == false)) { 
 		return; 
	} else { 
		parentId = theMenu+"link";
		document.getElementById(theMenu).style.display="block";
		if (document.getElementById(theMenu).offsetWidth < document.getElementById(theMenu+"link").offsetWidth) document.getElementById(theMenu).style.width=(document.getElementById(theMenu+"link").offsetWidth)+'px';
		if (document.getElementById('frontrotate')) {
			document.getElementById('frontrotate').style.display = 'none';
		}
	}
}

function hideMenu(theMenu) {
	if((browserType == "none") || (menusLoaded == false)) {
		return;
	} else {
		document.getElementById(theMenu).style.display="none";
	}
}

// startTimer creates a JS timer to hide all the menus; this is used to handle menus disappearing too soon.
function startTimer() {
	if (timerRunning == false) {
		theTimer = setTimeout("hideAll()", timerLimit);
		timerRunning = true;
	}
}

// clearTimer stops and resets the timer.
function clearTimer() {
	if (timerRunning) {
		clearTimeout(theTimer);
		theTimer = null;
		timerRunning = false;
	}
}

// createMenus creates the menus from an inline navitems array.  The format
// of each navitem is Array('Item Title', 'ID of parent', 'URL', tab number)
function createMenus() {
	if (navigator.userAgent.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Opera') == -1 && document.all) return;
	for (var i=0; i<navitems.length; i++) {
		var thisID = document.getElementById(navitems[i][1]);
		var newLink = document.createElement('a');
		newLink.setAttribute('href',navitems[i][2]);
		var newText = document.createTextNode(navitems[i][0]);
		newLink.appendChild(newText);
		thisID.appendChild(newLink);
		thisID.className = 'jsmenu bgcolor'+navitems[i][3];
	}
	extraScripts();
}
