/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 *
 * tweaked to float over HTML SELECTS in IE using code from
 * http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
 *  
 */
function hideSelect(menu) {
    var mask = document.getElementById('selMask');
    mask.style.width = menu.offsetWidth;
    mask.style.height = menu.offsetHeight;
    mask.style.top = menu.style.top;
    mask.style.left = menu.style.left;
    mask.style.zIndex = menu.style.zIndex - 1;
    mask.style.display = "block";
}

function unhideSelect() {
    var mask = document.getElementById('selMask');
    mask.style.display = "none";
}

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 == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
            unhideSelect();
        }

        return false;
    }
    
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
            unhideSelect();
        }

        return false;
    }

    actuator.showMenu = function() {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        menu.style.zIndex = 100;
        currentMenu = menu;
        hideSelect(menu);
    }
}
