// Author : Larry Abas, Barry Dowsett
// (c) ISTCL 2004

var numMenus = 0;
var numItems = 0;
var Items;
var bLoaded = 0;

var menuUp = 0;
var itemUp = 0;
var subUp = 0;

//Marks loaded status to 1, and if specified sets focus to an
//element (like the searchbox)
function Start(toFocusOn)
{
	if (toFocusOn)
	{
		ObjectToFocusOn = document.getElementById(toFocusOn);
		ObjectToFocusOn.focus();
	}

	bLoaded = 1;
}

function initItem(vtype, vmenu)
{
	Items[numItems] = new Array(4);
	Items[numItems][0] = vtype;
	Items[numItems][1] = vmenu;
	//Items[numItems][2] = null;
	//Items[numItems][3] = null;
	if(vmenu > 0)
	{
		numMenus ++;
	}
	numItems ++;
}

//Shows popup window, hides others
//slightly optimized for better performance
function showPopup(toShow)
{
	if (bLoaded == 1 && toShow != menuUp)
	{
		if(toShow > 0)
		{
			if(!Items[toShow][3])
			{
				Items[toShow][3] = document.getElementById("Menu" + Items[toShow][1]); //Load only first time
			}

			if(Items[toShow][3])
			{
				Items[toShow][3].style.visibility = 'visible';
				Items[toShow][3].style.display = 'block';
			}
		}

		if(menuUp > 0)
		{
			if(!Items[menuUp][3])
			{
				Items[menuUp][3] = document.getElementById("Menu" + Items[toShow][1]); //Load only first time
			}

			if(Items[menuUp][3])
			{
				Items[menuUp][3].style.visibility = 'hidden';
				Items[menuUp][3].style.display = 'none';
			}
		}

		menuUp = toShow;
	}
}

//Highlights the targeted item, and popups the necessary menu
//if necessary
function highlight(toHighlight)
{
	//alert("Mouseover: " + toHighlight);
	//alert("itemUp = " + itemUp + "\nsubUp = " + subUp + "\nmenuUp = " + menuUp);
	if(bLoaded)
	{
		if(toHighlight == 0)
		{
			showPopup(0);
			if(itemUp > 0)
			{
				change(itemUp, 0);
				itemUp = 0;
			}
			if(subUp > 0)
			{
				change(subUp, 0);
				subUp = 0;
			}
		}
		else if(!(toHighlight == itemUp || toHighlight == subUp))
		{
			change(toHighlight, 1);
			if(Items[toHighlight][0] == 3)
			{
				if(subUp > 0)
				{
					change(subUp, 0);
				}
				subUp = toHighlight;
			}
			else
			{
				if(Items[toHighlight][1] > 0) //Items[toHighlight][0] == 0)
				{
					showPopup(toHighlight);
				}
				else
				{
					showPopup(0);
				}

				if(itemUp > 0)
				{
					change(itemUp, 0);
				}
				if(subUp > 0)
				{
					change(subUp, 0);
					subUp = 0;
				}
				itemUp = toHighlight;
			}
		}
	}
}

function change(toDo, raise)
{
	if(bLoaded)
	{
		if(!Items[toDo][2])
		{
			Items[toDo][2] = document.getElementById("Item" + toDo); //Load first time only
		}

		//double check to make sure the item exists
		if(Items[toDo][2])
		{
			if(raise == 1)
			{
				if(Items[toDo][0] < 2)
					Items[toDo][2].style.background="#000000";
				else
					Items[toDo][2].style.background="#FFFFFF";
			}
			else
			{
				if(Items[toDo][0] < 2)
					Items[toDo][2].style.background="#0083b2";
				else
					Items[toDo][2].style.background="#94CAE0";
			}
		}
	}
}

function takeMeTo(x)
{
	loc = x.options[x.selectedIndex].value;
	if(loc != "")
	{
		window.self.location.href = loc;
	}
	return false;
}
