//v2.0
var nav = (navigator.appName=="Netscape") ? true : false;
var mac = (navigator.appVersion.indexOf("Mac") != -1);
var ie = (document.all) ? true : false;

var menuId="";//global for hideAllMenus() function v2.0

function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
    } else {
	return false;
    }
} 

function getObject(objectId){
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId);
    } else if (document.layers) {
	return eval('document.'+objectId);
    } else {
	return false;
    }
}

function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
}

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	 styleObject.left = newXCoordinate + "px";
	 styleObject.top = newYCoordinate + "px";
	 return true;
    } else {
	return false;
    }
} 

function showMenu(menuNumber, eventObj, noTimeKill) {
   hideAllMenus();
   menuId = 'menu' + menuNumber;
   var obj = getObject(menuId);
   if (nav){
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEOVER);
   }
   	if (!noTimeKill) { obj.onmouseout = timeKill; }
   	obj.onmouseover = resetTimer;
	var x=(nav)?eventObj.pageX:event.clientX+document.documentElement.scrollLeft;
	var y=(nav)?eventObj.pageY:event.clientY+document.documentElement.scrollTop;
	var menuArray = menuId.charAt(0).toUpperCase()+menuId.substring(1,menuId.length);
	if(eval(menuArray+'[0]')==true){
		var imgName = menuId + "Image";
		if (!nav){
		var position = findPos(imgName);
		x = position.locationX;
		y = position.locationY;
		}else if (nav){
			x = eval("document."+imgName+".x");
			y = eval("document."+imgName+".y");
		}
	}
	if(mac&&ie){//mac ie bug fix
		winWidth = document.body.clientWidth;
		if(winWidth > 612) x -= (winWidth - 612)/2;
	}
	x += Number(eval(menuArray+'[1]'));
	y += Number(eval(menuArray+'[2]'));
	
	// Ad-hoc rightward adjustment for i-tag divs with a table inside to avoid
	// flow off the right edge of the page.
	var children;
	if (obj.children) children = obj.children; //IE
	if (obj.childNodes) children = obj.childNodes; //conforming browsers
	
	if (children) {
		if (children.length > 0 && children[0].tagName == "TABLE") {
			if (children[0].width == 300) {
				if (x + 300 > document.body.clientWidth + document.body.scrollLeft - 20) {
					x = document.body.clientWidth + document.body.scrollLeft - 320;
				}
			}
		}
		else if (children.length > 1 && children[1].tagName == "TABLE") {
			if (children[1].width == 300) {
				if (x + 300 > document.body.clientWidth + document.body.scrollLeft - 20) {
					x = document.body.clientWidth + document.body.scrollLeft - 320;
				}
			}
		}
	}
	// End ad-hoc handling
	
	// Avoid flow off the left side of the page.
	if (x < document.body.scrollLeft) x = document.body.scrollLeft + 5;

	moveObject(menuId, x, y);
    if(changeObjectVisibility(menuId, 'visible')) {
	eventObj.cancelBubble = true;
	return true;
    } else {
	return false;
    }
}

function findPos (objName){
	var oElmnt = getObject(objName);
	var loopE = "oElmnt";
	var XY = new Array;
	XY['locationX']=0;
	XY['locationY']=0;
	while((eval(loopE+".tagName")).toLowerCase()!="body"){
		loopE += ".offsetParent";
		XY['locationX'] += eval(loopE+".offsetLeft");
		XY['locationY'] += eval(loopE+".offsetTop");
	}
	return XY
}

function hideAllMenus() {
	changeObjectVisibility(menuId, 'hidden');
	if(nav){
   		document.releaseEvents(Event.MOUSEMOVE);
		document.releaseEvents(Event.MOUSEOVER);
	}
}
var timer;
function timeKill(){
	timer = setTimeout('hideAllMenus()',250);
}
function resetTimer(){
	if (timer) clearTimeout(timer);
}
document.onclick = hideAllMenus;
