/*
 * fhiDropdown.js - implements an dropdown menu based on a HTML list, based
 * largely on menuDropdown.js by Dave Lindquist (http://www.gazingus.org), but
 * several changes were needed to work across the FHI supported platforms.
 */

var currentMenu = null;

if (!document.getElementById)
	document.getElementById = function() { return null; }

function initializeFhiMenus() {
	initializeMenu("services-menu", "services-actuator");
	initializeMenu("challenges-menu", "challenges-actuator");
	initializeMenu("about-menu", "about-actuator");
}

function initializeMenu(menuId, menubarId) {
	var menu = document.getElementById(menuId);
	var menubar = document.getElementById(menubarId);

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

	menubar.onmouseover = function() {
		if (currentMenu == null) {
			this.showMenu();
		}
	}

	menubar.onmouseout = function() {
		if (currentMenu) {
			currentMenu.style.visibility = "hidden";
			currentMenu = null;
		}
	}
  
	menubar.showMenu = function() {
		height = document.getElementById('cell-menu').offsetHeight;
		menu.style.left = this.offsetLeft + "px";
		menu.style.top = height + "px";
		menu.style.visibility = "visible";
		currentMenu = menu;
	}
}
