/*
 * 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 (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 ver = navigator.appVersion;
        if (ver.indexOf("MSIE") != -1 && navigator.platform.toLowerCase() == "win32") {
            menuListPos = getPos(document.getElementById("menuList"));
            menu.style.left = (menuListPos.x + this.offsetLeft - 20) + "px";
            menu.style.top = (menuListPos.y + this.offsetHeight) + "px";
        } else {
            menu.style.left = this.offsetLeft + "px";
            menu.style.top = this.offsetTop + this.offsetHeight + "px";
        }
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

function getPos(el){
for (var lx=0,ly=0;el!=null; lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
    return {x:lx,y:ly}
}
