/****javascript for the navigation menu ****/

//global variables
var layerRef="null";
var styleSwitch="null";
var visible="null";
var hidden="null";

function init() {
	if (document.layers) {
		//alert("you are using NS4+");
		layerRef = "document.layers";
		styleSwitch = "";
		visible = "show";
		hidden = "hide";
		//document.captureEvents(Event.MOUSEMOVE);
		//document.onmouseout = closeallmenus;
	} else if (document.all) {
		//alert("you are using IE4+");
		layerRef = "document.all";
		styleSwitch = ".style";
		visible = "visible";
		hidden = "hidden";
	} else if (document.getElementById && !document.all) {
		//alert("you are using NN6 or IE5/5.5");
		layerRef = "document.getElementById";
		styleSwitch = ".style";
		visible = "visible";
		hidden = "hidden";
	}
}


//showMenu: if the object specified in the passed variable menu is not visible, show the object
function showMenu(menu) {
	if (document.getElementById && !document.all) {
		//using NN6 or IE5/5.5;
		menuE = layerRef+'("'+menu+'")'+styleSwitch;
		//alert(menuE);
	} else {
		menuE = layerRef+'["'+menu+'"]'+styleSwitch;
		//alert(menuE);
	}

	//alert(menuE+".visibility="+visible);
	if (eval(menuE+".visibility!="+visible)) {
		eval(menuE+".visibility="+visible);
	}
}
//hideMenu: if the object specified in the passed variable menu is visible, hide the object
function hideMenu(menu) {
	if (document.getElementById && !document.all) {
		//using NN6 or IE5/5.5;
		menuE = layerRef+'("'+menu+'")'+styleSwitch;
	} else {
		menuE = layerRef+'["'+menu+'"]'+styleSwitch;
	}

	//alert(menuE+".visibility=="+visible);
	if (eval(menuE+".visibility=="+visible)) {
		//alert("visible");
		eval(menuE+".visibility="+hidden);
	}
}

//document.getElementById("moreMonkeyDiv").onmouseout = closeMenu;

/*closeMenu: determine where the mouse is moving to. If it has moved onto an element 
within the menu DIV, it should ignore the event. Only when it moves onto an element 
outside the menu DIV should it hide the menu.*/
function closeMenu(event,link,menu) {

	var current, related;

	if (window.event) {
		//alert("event orignated from "+window.event.target.id); IE Mac, Safari
		//alert("event orignated from "+window.event.srcElement.id); IE windows
		current = link;
		//toElement sets or retrieves a reference to the object toward
		//which the user is moving the mouse pointer
		related = window.event.toElement;
	}
	else {	
		//currentTarget is the node that this event handler is assigned to
		current = event.currentTarget;
		//relatedTarget: onmouseover, indicates the node that the mouse
		//has left, onmouseout, indicates the node the mouse has moved onto
		related = event.relatedTarget;
	}

	if (current != related && !contains(current, related)) {
		hideMenu(menu);
	}
}

//contains: determine if one element is nested inside another
function contains(a, b) {

// Return true if node a contains node b.
	while (b.parentNode) {
		if ((b = b.parentNode) == a) {
			//element is nested inside another
			return true;
		}
	}
	return false;
}


