
var activeMenu=null;

var browser=new Browser();
function Browser() {
	this.isIE=false;
	this.isMac=false;

	var ua=navigator.userAgent;

	if (ua.indexOf('MSIE')>0) this.isIE=true;
	if (ua.indexOf('Mac')>0) this.isMac=true;
}


function menuActivate(menuButton,menuId) {
	activeMenu=document.getElementById(menuId);

	// setup the menu's position
	var left=getOffsetLeft(menuButton);
	var top=getOffsetTop(menuButton)+menuButton.offsetHeight;

	// fix for IE mac
	if (browser.isIE && browser.isMac) {
		left+=document.body.leftMargin;
		top+=document.body.topMargin;
		activeMenu.style.left=left+'px';
		activeMenu.style.top=top+'px';
	} else {
		activeMenu.style.left=left+'px';
		activeMenu.style.top=top+'px';
	}

	// make it visible
	activeMenu.style.visibility='visible';
}

function menuMouseOut(event) {
	var to; // element mouse is switching into
	var toParent; // menu element mouse is switching to

	if (activeMenu==null) return;

	if (browser.isIE) to=window.event.toElement;
	else if (event.relatedTarget.tagName) to=event.relatedTarget;
	else to=event.relatedTarget.parentNode;

	// hide if we are leaving the menu
	toParent=findParentWithClass(to,"DIV","menu");
	if (toParent==null) {
		activeMenu.style.visibility='hidden';
		activeMenu=null;
	}
}

// Utility functions

function findParentWithClass(obj,tagName,className) {
	while (obj!=null) {
		if (obj.tagName==tagName && obj.className==className) return obj;

		obj=obj.parentNode;
	}
	return null;
}

function getOffsetTop(obj) {
	var pixel=obj.offsetTop;
	if (obj.offsetParent) pixel+=getOffsetTop(obj.offsetParent);
	return(pixel);
}

function getOffsetLeft(obj) {
	var pixel=obj.offsetLeft;
	if (obj.offsetParent) pixel+=getOffsetLeft(obj.offsetParent);
	return(pixel);
}


