/*
JavaScript methods needed for the menu-tree mouseover effects.
*/

var childPanelIdPrefix = '';

var timerMs = 1000;
var timerActive = true;

function tick()
{
	if(timerActive)
	{
		timerMs -= 100;
		
		if(timerMs > 0)
		{
			setTimeout('tick()', 100)
		}
		else
		{
			timerActive = false;
			timerAlarm();
		}		
	}	
}

function toggleTimer(start)
{
	if(start)
	{
		timerActive = true;
		timerMs = 1000;
		tick();
	}
	else
	{
		timerActive = false;
	}
}

function timerAlarm()
{
	//switch back to 'original' submenu
	var allDivs = document.getElementsByTagName('div');	

	for(var panel in allDivs)
	{
		//make sure ID is set
		if(allDivs[panel].id)
		{
			if(allDivs[panel].id.indexOf(childPanelIdPrefix) > -1)
			{
				if(allDivs[panel].getAttribute('expanded'))
				{
					allDivs[panel].style.visibility = 'visible';
				}
				else
				{
					allDivs[panel].style.visibility = 'hidden';
				}				
			}
		}		
	}			
}

function hideSubmenus(childPanelName)
{
    //alert(childPanelIdPrefix);
	//loop through all panels and find child navigation panels
	var allDivs = document.getElementsByTagName("div");	

	for(var panel in allDivs)
	{
		//make sure ID is set
		if(allDivs[panel].id)
		{
			if(allDivs[panel].id.indexOf(childPanelName) > -1)
			{
				//hide child menu panel
				allDivs[panel].style.visibility = 'hidden';
			}
		}		
	}
}

function toggleSubmenu(link, childPanel, childPanelName)
{
	//var linkElement = $get(link);
	var childPanelElement = $get(childPanel);		
	
	//make sure the selected menu item's child panel can be found
	if(childPanelElement)
	{	
		hideSubmenus(childPanelName);

		//show selected child menu panel
		childPanelElement.style.visibility = 'visible';	
	}	
}

function linkMouseOver()
{
	toggleTimer(false);	
}

function linkMouseOut()
{
	toggleTimer(true);
}