// Not sure about the origin of this code
// Do not add a Daisy license header to this file
var nbsec = 0.5;
var currentMenu = null;

window.lastmenu = null;
window.menuactive = 0;
window.inactivedelay = 0;

if (!document.getElementById) {
    document.getElementById = function() { return null; }
}

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
    var tid=0;

    if (menu == null || actuator == null) return;

    actuator.onmouseover  = function() {
       if (currentMenu == null) {
         this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
          this.showMenu();
        }

    }

    actuator.onmouseout = function() {
        window.clearTimeout(tid);
    window.menuactive=1;
    }

    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            this.hideMenu();
        }
        return true;
    }

    actuator.showMenu = function() {
        menu.style.left = actuator.offsetLeft + "px";
        menu.style.top = actuator.offsetTop + actuator.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
        window.lastmenu=actuator;
        window.menuactive=0;
        window.inactivedelay = 0;
    }
    actuator.hideMenu = function() {
         if (currentMenu != null) {
          currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }
            window.menuactive=0;
    }

    menu.onmouseover = actuator.showMenu;
    menu.onmouseout = actuator.onmouseout;
}

function autohide() {
    if (window.menuactive==1) {
        if (++window.inactivedelay==3 && window.lastmenu != null) {
            window.lastmenu.hideMenu();
        }
    }
    else
        window.inactivedelay = 0;
}
window.setInterval("autohide()",nbsec*1000/3);

