
var mainMenuTimerTicks;
var mainMenuTimerID = null;
var mainMenuTransition = null;
var subMenuIDs = new Array();
var mainMenuIDs = new Array();
var mainMenuActiveSubMenu = '';

function mainMenuInit()
{
	var element = document.getElementById('main_menu');
	element.onmouseout = mainMenuDoMouseOut; // the event gets passed as the 1st argument
	element.onmouseover = mainMenuDoMouseEnter; // the event gets passed as the 1st argument

	var i;
	var k = 0;
	
	for ( i = 0; i < element.childNodes.length; i++)
	{
		if (element.childNodes[i].nodeName == 'LI')
		{
			var liElement = element.childNodes[i];
			var j;
			
			for ( j = 0; j < liElement.childNodes.length; j++)
			{
				if ( liElement.childNodes[j].nodeName == 'DIV')
				{
//					log( liElement.childNodes[j].id);
//					subMenuIDs.push("foo");
					subMenuIDs.push( liElement.childNodes[j].id);
//					subMenuIDs[k] = liElement.childNodes[j].id;
					k = k + 1;
					liElement.onmouseout = mainMenuDoMouseOut; // the event gets passed as the 1st argument
					liElement.onmouseover = mainMenuDoMouseEnter; // the event gets passed as the 1st argument
				} else if ( liElement.childNodes[j].nodeName == 'A')
				{
					mainMenuIDs.push( liElement.childNodes[j].id);
				}
			}
		}
	}

	for ( i = 0; i < subMenuIDs.length; i++)
	{
//		element = document.getElementById( subMenuIDs[i] + '-r-shadow');
		var anImage = new OpacityObject( subMenuIDs[i] + '_r_shadow', gBase_URL + '/images/css/home/drop-down-shadow-r');
		anImage.setBackground();
		anImage = new OpacityObject( subMenuIDs[i] + '_b_shadow', gBase_URL + '/images/css/home/drop-down-shadow-b');
		anImage.setBackground();
	}

}

function mainMenuDoMouseEnter()
{
	if ( mainMenuTimerID != null) clearTimeout( mainMenuTimerID);
	mainMenuTimerID = null;
}

function mainMenuRevealSubMenu( elementID, doReveal)
{
	var i;
	for ( i = 0; i < subMenuIDs.length; i++)
	{
		var element = document.getElementById( subMenuIDs[i]);
		var a_element = document.getElementById( mainMenuIDs[i]);
		if ( subMenuIDs[i] == elementID)
		{
			if ( doReveal > 0)
			{
				element.style.visibility = 'visible';
				if ( a_element.className != 'active')
					a_element.className = 'highlight';
			}
		} else
		{
			element.style.visibility = 'hidden';
			if ( a_element.className != 'active')
				a_element.className = '';
		}
	}
	mainMenu_refreshTimeout( true);
}


function mainMenuDoMouseOut()
{
	mainMenu_refreshTimeout( true);
}

/* function bookMenu_refreshTimeout( doRestart)
updates the main menu timeout timer; if doRestart is true then restarts
the timer; handles fading of the currently visible main menu element
*/


function mainMenu_refreshTimeout( doRestart)
{
	if ( doRestart)
	{
		mainMenuTimerTicks = 10;
		if ( mainMenuTimerID != null) clearTimeout( mainMenuTimerID);
		mainMenuTimerID = null;
	}
	if ( mainMenuTimerID == null)
	{
		mainMenuTimerID = self.setTimeout("mainMenu_refreshTimeout( false)", 20);
	} else
	{
		mainMenuTimerTicks = mainMenuTimerTicks - 1;
		if ( mainMenuTimerTicks <= 0)
		{

			var i;
			for ( i = 0; i < subMenuIDs.length; i++)
			{
				var element = document.getElementById( subMenuIDs[i]);
				var a_element = document.getElementById( mainMenuIDs[i]);
				if ( subMenuIDs[i] == mainMenuActiveSubMenu)
				{
					element.style.visibility = 'visible';
					if ( a_element.className != 'active')
						a_element.className = "highlight";
				} else
				{
					element.style.visibility = 'hidden';
					if ( a_element.className != 'active')
						a_element.className = "";
				}
					
			}
		
		} else
		{
			if (( mainMenuTimerTicks < 18))
			{
				//mainMenuElement_changeOpacity( visibleMainMenuItem, (mainMenuTimerTicks / 18) * 100);
			}
			mainMenuTimerID = self.setTimeout("mainMenu_refreshTimeout( false)", 20);
		}
	}

}
addEvent(window,'load',mainMenuInit);

