/*#############################################################################
===============================================================================
	Andera 		Fyout Menu
	Author: 	Niklas Wahlberg
	Version:	1.0
	Date:		7/6/2004

	History:
	7/6/04		File Created
===============================================================================
#############################################################################*/

/*
//------------------------------------------------------------------------------
//	Global variables
//------------------------------------------------------------------------------
var menuTimeOut=300;
var timeOutMenu="";

//------------------------------------------------------------------------------
// toggleMenu
//
// 	Hides/shows the menu div
//------------------------------------------------------------------------------
function toggleMenu(menuID,status){
	// don't run this if the browser does not support DOM referencing
	if (document.getElementById){
		var theElement=document.getElementById(menuID);

		// clear the time out variable
		timeOutMenu=null;

		if (status == "inline"){
			//alert();
			theElement.style.display=status;
		}
		else {
			timeOutMenu=window.setTimeout("turnMenuOff('"+menuID+"')", menuTimeOut);
		}
	}
}

//------------------------------------------------------------------------------
// turnMenuOff
//
// 	Hides/shows the menu div
//------------------------------------------------------------------------------
function turnMenuOff(menuID){
	// don't run this if the browser does not support DOM referencing
	if (document.getElementById){
		var theElement=document.getElementById(menuID);
		theElement.style.display="none";
	}
}

//------------------------------------------------------------------------------
// clearWinTimeout
//
// 	this clears the timeout of the currently visible menu div, using the global
//	var 'timeOutMenu'
//------------------------------------------------------------------------------
function clearWinTimeout(){
	window.clearTimeout(timeOutMenu);
}
*/

//rramaiah: new functions to handle sub menus

//this object serves as an associative array to handle the "in menu" state for all main menus
var isInMenuObj = new Object();

//activates a main menu
function mainMenuOn(mainMenuID) {
    document.getElementById(mainMenuID).style.display="inline";

	//start thread that will periodically check "in menu" state for this menu
	window.setTimeout("runMenuThread('" + mainMenuID + "')", 100);
}

//sets "in menu" state for a main menu
function setInMenu(mainMenuID, bool) {
	isInMenuObj[mainMenuID] = bool;
}

//thread that periodically checks "in menu" state for a main menu
function runMenuThread(mainMenuID) {

	if (!isInMenuObj[mainMenuID]) {

		//hide main menu and all its sub menus
		document.getElementById(mainMenuID).style.display="none";
		hideSubMenus(mainMenuID);

	}
	else {
		window.setTimeout("runMenuThread('" + mainMenuID + "')", 100);
	}
}

//called upon entry into any of the main menu's items; hides all sub menus and optionally shows one of them
function handleSubMenus(mainMenuID, subMenuIndex) {


	hideSubMenus(mainMenuID);

	if (subMenuIndex) {
		document.getElementById(mainMenuID + subMenuIndex).style.display="inline";
	}
}

//hides all sub menus for this main menu
function hideSubMenus(mainMenuID) {

	//sub menus should be of the form <mainMenuID><x> where x is 1,2,3...
	var subMenuCtr = 1;
	var subMenuID = "";
	while (true) {
		subMenuID = mainMenuID + subMenuCtr;
		if (document.getElementById(subMenuID)) {
			document.getElementById(subMenuID).style.display="none";
			subMenuCtr++;
		}
		else {
			break;
		}
	}

}

/**
 * This function came from "Nice Titles"
 * http://www.kryogenix.org/code/browser/nicetitle/
 */
function findLinkPosition( oLink ) {
  if(!document.getElementById)return;
  oLink = document.getElementById(oLink);
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oLink.x, oLink.y ];
  }
}