/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 */

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
	if (navigator.appName.match(/Netscape/))
	{
		actuator.style.position = "relative";
	}
    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu();
        }
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
        var left_margin = getElementOffsetLeft(this);
        var top_margin = (getElementOffsetTop(this) + this.offsetTop + this.offsetHeight);
        if (navigator.appName.match(/Netscape/))
		{
			left_margin = this.offsetLeft;
			top_margin = this.offsetHeight + this.offsetTop;
		} else if (navigator.appName.match(/Microsoft/)) {
			left_margin -= 10;
		}
		menu.style.left = left_margin+"px";
		menu.style.top = top_margin+"px";
		menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

function getElementOffsetTop(elem)
{
	if (!elem.parentNode)
		return 0;
	if ((elem.parentNode.offsetTop == null)&&
		(!navigator.appName.match(/Netscape/)))
		return 0;
	// Node.ELEMENT_NODE
	return elem.parentNode.offsetTop + getElementOffsetTop(elem.parentNode);
} // function getElementOffsetTop(elem)

function getElementOffsetLeft(elem)
{
	if (!elem.parentNode)
		return 0;
	if ((elem.parentNode.offsetLeft == null)&&
		(!navigator.appName.match(/Netscape/)))
		return 0;
	// Node.ELEMENT_NODE
	return elem.parentNode.offsetLeft + getElementOffsetLeft(elem.parentNode);
} // function getElementOffsetTop(elem)

/*
function getElementOffsetTop(elem)
{
	if (!elem.parentNode)
	{
		return 0;
	} else if (elem.parentNode.offsetTop == undefined) {
		return 0;
	} else if (elem.nodeType == 1) {
	// Node.ELEMENT_NODE
		return elem.parentNode.offsetTop + getElementOffsetTop(elem.parentNode);
	}
}
*/
