	var gCurMenu = null; // global to hold curentMenu instance
	var gMenuIsActive = null;

	function MenuObject(menuObj, buttonObj) {
		this.menuObj = menuObj;
		this.buttonObj = buttonObj;
		this.width = (document.layers) ? parseInt(menuObj.width) : parseInt(menuObj.style.width);
		this.x = getX(this.buttonObj, this.width);
		this.buttonX = (document.layers) ? parseInt(this.buttonObj.left) : parseInt(this.buttonObj.style.left);
		this.y = (document.layers) ? parseInt(buttonObj.top) : parseInt(buttonObj.style.top);
		
		if (document.layers) {
			this.menuObj.left = this.x;
			this.buttonObj.bgColor = "";
			this.menuObj.visibility = "show";
		} else {
			this.menuObj.style.left = this.x;
			this.buttonObj.style.background = "";
			this.menuObj.style.visibility = "visible";
		}

		gMenuIsActive = true;
	}

	function getX(buttonObj, menuWidth) {
		var testX = (document.layers) ? parseInt(buttonObj.left) : parseInt(buttonObj.style.left);
		var screenWidth = (document.layers) ? document.innerWidth : document.body.clientWidth;
		
		if (testX + menuWidth > screenWidth) {
			testX -= (testX + menuWidth) - screenWidth;
			return testX
		} else {
			return testX;
		}	
	}

	function btnhighlight(htmlObj) {
		htmlObj.style.color = "#ffffff";
		htmlObj.style.textDecoration = "underline";
	}

	function btnunhighlight(htmlObj) {
		htmlObj.style.color = "#ffffff";
		htmlObj.style.textDecoration = "none";
	}

	function highlight(htmlObj) {
		htmlObj.children[0].children[0].style.textDecoration = "underline";
	}

	function unhighlight(htmlObj) {
		htmlObj.children[0].children[0].style.textDecoration = "none";
	}

	function openMenu(menuID, buttonObj) {
		if (gCurMenu != null) closeMenu();
		if (document.layers) {
			menuObj =  eval("document." + menuID)
		} else {
			menuObj = (document.all) ?  eval("document.all." + menuID) : document.getElementById(menuID);
		}	
		gCurMenu = new MenuObject(menuObj, buttonObj); // create instance of MenuObject
	}

	function closeMenu(menuObj) {
		gMenuIsActive = false;
		if (document.layers) {
			gCurMenu.menuObj.visibility = "hide";
			gCurMenu.buttonObj.bgColor = "";
		} else {
			gCurMenu.menuObj.style.visibility = "hidden";
			gCurMenu.buttonObj.style.background = "";
		}	
	}

	function checkMenuBounds(e) {
		if (gMenuIsActive) {
			y = (document.all) ? window.event.clientY : e.pageY;
			x = (document.all) ? window.event.clientX : e.pageX;
			
			var curX = gCurMenu.x + gCurMenu.width;
			
			if ((x < gCurMenu.x) || (x > curX) || (y < gCurMenu.y)) {
				closeMenu();
			}
		}
	}

	if (document.layers) {
		document.captureEvents(Event.MOUSEMOVE);
	}

	document.onmousemove = checkMenuBounds;

