/*
 * 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; }


//added by bwigton to enable auto menu close with timer//
//var keepMenuOpen = null;
function closeMenu(){
	if(currentMenu){
		currentMenu.style.visibility = "hidden";
    	currentMenu = null;
	}
}

/// end patch 1 of 2 //

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; 

    actuator.onmouseover = function() {
        if (currentMenu) {  // if there is another menu open
			//keepMenuOpen = true;
            currentMenu.style.visibility = "hidden";
            this.showMenu();
        }
		//patched from onclick event handler to enable drop down functionality
		// bwigton 12/06/04
		if(currentMenu==null) {  //if there is not another menu open.
			//keepMenuOpen = true;
            this.showMenu();
        }
        return false;
    }
	
	// added by bwigton 12/6/04 to enable hiding menus with a timer //
	actuator.onmouseout = function() {
		if (currentMenu) {
			window.setTimeout(closeMenu, 5000);
		}
    }
	////end patch 2 of 2 /////////
  
    /*actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }*/

    actuator.showMenu = function() {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}
