<!--
//Filename:  menu.js
//Created:   04/03/2003
//Purpose:   This contains the client-side javascript used by the TopMenu server control
//Edited:    04/03/2003, Christopher Hall, Adding comments
//-->
<!--

//Global variables
var MN_intFailsafeDuration = 8000;						//Maximum duration for which menu will remain open
var MN_intMenuDuration = 1500;								//Milliseconds for which menu will display
var	MN_intTimerInterval = 30;								//Milliseconds between timer decrements
var MN_bolTimerRunning = false;								//Boolean indicating if timer is running
var MN_bolFailsafeTimerRunning = false;						//Boolean indicating if failsafe timer is running
var MN_intCurrentTimer = MN_intMenuDuration;				//Current timer value (milliseconds)
var MN_intCurrentFailsafeTimer = MN_intFailsafeDuration;	//Current failsafe timer value (milliseconds)
var MN_bolResetTimer = false;								//Boolean indicating that timer should be reset
var MN_strSelectedMenu = '';							//String indicating currently selected menu

//Hide menu when mouse is clicked
document.onclick = MN_ClearMenus;

//Set menu state if item within has been selected
if (typeof(UTL_Request) != 'undefined' && typeof(UTL_Request.QueryString("pageid")) != 'undefined')
{
	var MN_pageIdentifier = UTL_Request.QueryString("pageid").toLowerCase();

	if(MN_pageIdentifier.indexOf("ai") > -1) {
		MN_strSelectedMenu = '0';
	}
	else if (MN_pageIdentifier.indexOf("ob") > -1) {
		MN_strSelectedMenu = '1';
	}
	else if (MN_pageIdentifier.indexOf("fi") > -1) {
		MN_strSelectedMenu = '2';
	}
	document.onload = MN_ChangeStateOver(MN_strSelectedMenu);
}

//Displays selected menu at correct position on page, called from element event handler
function MN_PopUp(strMenuIdentifier, e)
{
	//Define variables
	var x = 0;
	var y = 0;
	
	//Determine correct position (browser dependent)
	if (IE) {
		//IE
		x = UTL_GetElementLeft(e.srcElement);
		y = UTL_GetElementTop(e.srcElement) + e.srcElement.height;
		
		//Change cursor style
		e.srcElement.style.cursor = 'hand';
	} else {
		//Netscape 4.X +
		x = UTL_GetElementLeft(e.target);
		y = UTL_GetElementTop(e.target) + e.target.height;
		
		//Change cursor style
		e.target.cursor = 'hand';
	}
	
	//Actually display menu item on screen
	MN_ShowMenu(strMenuIdentifier, x, y);
	return true;
}

//Hides other menus, moves menu to correct position, displays
function MN_ShowMenu(strMenuIdentifier, x, y)
{
	//Hide other menu items
	var i = 0;
	while (UTL_GetObject('menu' + i)) {
		if (i != parseInt(strMenuIdentifier)) {
			MN_HideMenu(i);
		}
		i++;
	}
	
	//Move menu item to correct position on page
	menuObject = UTL_GetObjectStyle('menu'+strMenuIdentifier);
	
	//If menu object found, set position and visibility
	if (menuObject) {
	
		//Set menu position
		if (x) { menuObject.left = x; }
		if (y) { menuObject.top = y; }

		//Change menu state
		MN_ChangeStateOver(strMenuIdentifier);

		//Show menu item
		UTL_ChangeVisibility(menuObject, true);
	}
		
	//Reset timer
	MN_ResetTimer();
}

//Initialises hiding of specified menu
function MN_PopDown(strMenuIdentifier)
{
	MN_BeginTimer();
}

//Hides selected menu
function MN_HideMenu(strMenuIdentifier)
{
	//Get reference to menu object style collection
	menuObject = UTL_GetObjectStyle('menu'+strMenuIdentifier);
	
	//If menu object found, set image and visibility
	if(menuObject) {
	
		//If not currently selected top-level menu, change state
		if (strMenuIdentifier != MN_strSelectedMenu)
		{
			//Change menu state
			MN_ChangeStateOut(strMenuIdentifier);
		}
		
		//Hide object
		UTL_ChangeVisibility(menuObject, false);
	}
}

//Ensure that the timer is running
function MN_EnsureTimer()
{
	if (!MN_bolTimerRunning)
	{
		MN_BeginTimer();
	}
}

//Ensures that the failsafe timer is running
function MN_EnsureFailsafeTimer()
{
	if (!MN_bolFailsafeTimerRunning)
	{
		MN_BeginFailsafeTimer();
	}
}

//Begin timer for menu items
function MN_BeginTimer()
{
	//Reset timer
	MN_intCurrentTimer = MN_intMenuDuration;

	//Set timer running if not already
	if (!MN_bolTimerRunning)
	{
		MN_bolResetTimer = false;
		MN_bolTimerRunning = true;
		MN_DecrementTimer();
	}
	
	//Make sure failsafe timer is operating
	MN_EnsureFailsafeTimer();
}

//Begins failsafe timer
function MN_BeginFailsafeTimer()
{
	//Reset timer
	MN_intCurrentFailsafeTimer = MN_intFailsafeDuration;

	//Set timer running if not already
	if (!MN_bolFailsafeTimerRunning)
	{
		MN_bolFailsafeTimerRunning = true;
		MN_DecrementFailsafeTimer();
	}
}

//Resets timer if it is running
function MN_ResetTimer()
{
	if (MN_bolTimerRunning) {
		MN_bolResetTimer = true;
	} else {
		MN_bolResetTimer = false;
	}
}

//Hides all menu items immediately
function MN_ClearMenus()
{
	var i = 0;
	while (UTL_GetObject('menu' + i)) {
		MN_HideMenu(i);
		i++;
	}
	
	//Reset failsafe timer
	MN_bolFailsafeTimerRunning = false
	MN_intCurrentFailsafeTimer = MN_intFailsafeDuration
}

//Decrements menu timer, repeats until timer is <= 0
function MN_DecrementTimer()
{
	//If timer has expired, hide all menu items
	if(MN_intCurrentTimer <= 0)
	{
		//If timer has expired ( <= 0 ), hide all menu items
		MN_ClearMenus();
		MN_bolTimerRunning = false;
	}
	else
	{
		//Check if timer should be stopped/reset
		if (!MN_bolResetTimer && MN_bolTimerRunning) {
			//Decrement timer, call decrement again
			MN_intCurrentTimer -= MN_intTimerInterval;
			window.setTimeout('MN_DecrementTimer();', MN_intTimerInterval);
		} else {
			//Reset timer to initial value
			MN_intCurrentTimer = MN_intMenuDuration;
			MN_bolResetTimer = false;
			MN_bolTimerRunning = false;
		}
	}
}

//Decrements failsafe timer, repeats until timer is <= 0
function MN_DecrementFailsafeTimer()
{
	//If timer has expired, hide all menu items
	if(MN_intCurrentFailsafeTimer <= 0)
	{
		//If timer has expired ( <= 0 ), hide all menu items
		MN_ClearMenus();
		MN_bolFailsafeTimerRunning = false;
	}
	else
	{
		//Check if timer should be stopped/reset
		if (MN_bolFailsafeTimerRunning) {
			//Decrement timer, call decrement again
			MN_intCurrentFailsafeTimer -= MN_intTimerInterval;
			window.setTimeout('MN_DecrementFailsafeTimer();', MN_intTimerInterval);
		} else {
			//Reset timer to initial value
			MN_intCurrentFailsafeTimer = MN_intFailsafeDuration;
			MN_bolFailsafeTimerRunning = false;
		}
	}
}

//Displays the mouseover image for the selected menu item
function MN_ChangeStateOver(strMenuIdentifier)
{
	//Change menu image
	imageObject = document.images['menuImg'+strMenuIdentifier];
	
	if (typeof(imageObject) != 'undefined')
	{
		if(eval('typeof(menuImg' + strMenuIdentifier + 'over) != \'undefined\'')) {
			imageObject.src = eval('menuImg'+strMenuIdentifier+'over').src;
		} else {
			imageObject.src = 'images/menu/menu' + strMenuIdentifier + '_over.gif';
		}
	}
}

//Displays the mouseout image for the selected menu item
function MN_ChangeStateOut(strMenuIdentifier)
{
	//Change menu image
	imageObject = document.images['menuImg' + strMenuIdentifier];
	
	if (typeof(imageObject) != 'undefined')
	{
		if(eval('typeof(menuImg' + strMenuIdentifier + ') != \'undefined\'')) {
			imageObject.src = eval('menuImg' + strMenuIdentifier).src;
		} else {
			imageObject.src = 'images/menu/menu' + strMenuIdentifier + '.gif';
		}
	}
}

//-->