var ie4 = document.all ? true : false;
var ns4 = document.layers ? true : false;
var ns6 = document.getElementById && !document.all ? true : false;

var currentMenu = null;
var menuCount = 0;
var bIsLoaded = false;

function showMenu(id) {
	clearTimer();
	if(currentMenu != null && currentMenu != id) {
		hideMenu(currentMenu);
		currentMenu = id;
	}
	var divo = null;
	if(ie4) {
		divo = document.all[id];
		divo.style.visibility = "visible";		
	}
	else if(ns4) {		
		divo = document.layers[id];
		divo.captureEvents();
		divo.visibility = "show";		
	}
	else if(ns6) { 		
		document.getElementById(id).style.visibility = "visible";		
	}
	currentMenu = id;
}	
function hideMenu(id) {	
	if(ie4) {
		divo = document.all[id];
		divo.style.visibility = "hidden";		
	}
	else if(ns4) {
		divo = document.layers[id];
		divo.visibility = "hidden";
	}
	else if(ns6) {
		document.getElementById(id).style.visibility = "hidden";
	}
}

function itemHighlightOn(item) {
	if(ns6 || ie4) 
		item.style.backgroundColor = "khaki";

}
function itemHighlightOff(item) {
	if(ns6 || ie4)
		item.style.backgroundColor = "#ffffcc";
}

var lTimerID = null;

function setTimer()	{
	clearTimer();
	if (bIsLoaded && !ns4)
		lTimerID = setTimeout('resetMenu()',600);
}

function clearTimer() {
	if (lTimerID != null && !ns4)
		clearTimeout(lTimerID);
}
	
function resetMenu() {
	clearTimer();	
	if(currentMenu != null)
		hideMenu(currentMenu);
}

function addMenu(
	menuName,
	bgColor, 
	rollOverColor, 
	className,
	xPosition, 
	yPosition, 
	width, 
	menuItems) {
	// Menuitems should be a two dimensional array
	//  array[menuitem#][0] = display text
	//  array[menuitem#][1] = link (http://...)
	tableOrLayerHeader = "";
	if(ns4) {
		tableOrLayerHeader =  "<layer style=\"border:1;\" id=\"" + menuName +  "\"";
		tableOrLayerHeader += " name=\"" + menuName + "\" bgcolor=\"" + bgColor + "\""; 
		tableOrLayerHeader += " top=\"" + yPosition + "\" width=\"" + width + "\"";
		tableOrLayerHeader += " left=\"" + xPosition + "\" onMouseOut=\"hideMenu(this.name);\" visibility=\"hidden\" position=\"relative\">";		
	}
	else if(ie4 || ns6) {
		a_style = "top: " + yPosition + "; left: " + xPosition + "; width: " + width + "; background-color: " + bgColor + "; z-index: 4; position: absolute; visibility: hidden;";
		tableOrLayerHeader = "<div id=\"" + menuName + "\" name=\"" + menuName + "\" style=\"" + a_style + "\"onMouseOut=\"setTimer();\" class=\"" + className + "\">";
	}

	document.writeln(tableOrLayerHeader);
	document.writeln("<table cellpadding=\"2\" cellspacing=\"0\" class=\"dropDownTable\" onMouseOver=\"showMenu('" + menuName + "'); clearTimer();\">");

	if((ie4 || ns4 || ns6) && menuItems != null) {
		for(i = 0; i < menuItems.length; i++) {			
			document.writeln('<tr><td width="' + width + '" class="dropDownItem" onMouseOver="itemHighlightOn(this);" onMouseOut="itemHighlightOff(this);">');
			document.write('<a href="' + menuItems[i][1] + '" onMouseOver="showMenu(\'' + menuName + '\');"  class="dropDownItemLink">' + menuItems[i][0] + '</a></td></tr>');

		}
	}

	document.writeln("</table>");

	if(ns4)	
		document.writeln('</layer>');
	else if(ie4 || ns6) 
		document.writeln('</div>');	
}