var timeOut = null;
// set this to id list of available menus
var menuIds = new Array(9, 10, 11, 12, "null");
// set this to the id of the opened menu
var menuOpen = null;
// amount of milliseconds to wait before hideAllMenus is executed when starting the timer
var menuHideDelay = 2000;

/**
 * Stops the time out that will hide all menus but the default one (menuOpen).
 */
function stopTimeOut() {
	if (timeOut != null) {
		clearTimeout(timeOut);
		timeOut = null;
	}
}

/**
 * Called when unfocusing a top level menu item:
 * - rollOut on the top menu image and 
 * - start a timeout to to hideAllMenus
 */
function fnTopOut(index, imageName, subMenuIndex, eventObj) {
	//	alert("fnTopOut, starting time out");
	fnRollOut(index, imageName);
//	stopTimeOut();
//	timeOut = setTimeout("hideAllMenus();",menuHideDelay);
}

/**
 * Called when focusing a top level menu item:
 * - rollOver on the top menu image, and
 * - show this top menus sub menu
 *
 * @param  index         the top image's index in the Image Arrays (rollOver and rollOut)
 * @param  imageName     the image tag's name attribute, ie the image to flip
 * @param  subMenuIndex  the index of the sub menu to show, or null
 * @param  eventObj      the eventObject
 */
function fnTopOver(index, imageName, subMenuIndex, eventObj) {
	//	alert("fnTopOver, showing sub menu" + subMenuIndex);
	fnRollOver(index, imageName);
//	showMenu(subMenuIndex, eventObj);
}

/**
 * Shows a sub menu.
 *
 * @param  menuNumber  the DIV tag with name "menu" + menuNumber will be set to visible
 * @param  eventObj    the eventObject
 */
function showMenu(menuNumber, eventObj) {
	//	alert(eventObj);
	hideAllMenus();
	var menuId = 'menu' + menuNumber;
	if (changeObjectVisibility(menuId, 'visible')) {
		eventObj.cancelBubble = true;
		return true;
	} else {
		return false;
	}
}

/**
 * Hides all submenus, but the default (menuOpen) if it's not null.
 */
function hideAllMenus() {
	return;
    for (counter = 0; counter < menuIds.length; counter++) {
    	if (menuIds[counter] != menuOpen) {
			changeObjectVisibility('menu' + menuIds[counter], 'hidden');
		}
    }
    stopTimeOut();
}

document.onclick = hideAllMenus;

/**
 * Image rollover-over-function.
 */
function fnRollOver(index, imageName) {
	document.images[imageName].src = rollOver[index].src;
//	stopTimeOut();
}

/**
 * Image rollover-out-function.
 */
function fnRollOut(index, imageName) {
	document.images[imageName].src = rollOut[index].src;
}

if (document.images) {
	var rollOver = new Array();
	var rollOut = new Array();
}

