/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (dave@gazingus.org)
 *
 * Modifications by Andrew Groom (andrew@aphid.co.nz)
 */

var currentMenu = null;
var menuTimerID = 0;
var timeoutMS = 200;

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;

	menu.onmouseover = function() {
		// Just cancel the timer event that will cause this menu to disappear.
		clearTimeout(menuTimerID);
	}

	menu.onmouseout = function() {
		// We've moused directly out of a submenu, so we need to set the timer again
		// because we might be going back into the main menu or leaving the menus altogether.
		menuTimerID = window.setTimeout("HideMenu()", timeoutMS);
	}

    actuator.onmouseover = function() {
        if (currentMenu) {
			if (menuTimerID) {
				clearTimeout(menuTimerID);
				menuTimerID = null;
			}
            currentMenu.style.visibility = "hidden";
        }
        this.showMenu();
    }
  
    actuator.onmouseout = function() {
		// On mouseout, just trigger a timeout event that will fire in enough time to allow
		// the mouse to travel to the menu div.
		if (menuTimerID) {
			clearTimeout(menuTimerID);
		}
		menuTimerID = window.setTimeout("HideMenu()", timeoutMS);
    }
  
    actuator.showMenu = function() {
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

// Hide the selected menu
function HideMenu() {
    if (currentMenu && menuTimerID) {
        currentMenu.style.visibility = "hidden";
		currentMenu = null;
    }
}



