/*
 * 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);
    var inMenu = 0;

    if (menu == null || actuator == null) return;

	container.onclick = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
	}

    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
	        inMenu = 0;
        }
        this.showMenu();
        inMenu = 1;
    }

    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
	        inMenu = 1;
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
	        inMenu = 0;
        }

        return false;
    }
    
    actuator.showMenu = function() {
    	o = this;
    	oLeft = o.offsetLeft;
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference
			oLeft += oParent.offsetLeft // Add parent left position
			o = oParent
		}
        menu.style.left = eval(oLeft) + "px";
        menu.style.top = this.offsetTop + eval(this.offsetHeight+13) + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}
