
/* Using prototype.js event handlers for navigation menus  */
/* See the Prototype web site: http://www.prototypejs.org/ */

function initNavigation()
{
	hideAllMenus();
}

function showMenu(primaryNav, secondaryNav)
{
	hideAllMenus();
	
	if (validId(primaryNav))
	{
		$(primaryNav).addClassName('current');
	}

	if (validId(secondaryNav))
	{
		$(secondaryNav).show();
	}
}

function validId(id)
{
	if (id != '')
	{
		if ($(id))
		{
			return true;
		}
	}
	
	return false;
}

function hideAllMenus()
{
	cancelHide('primaryNavColor'      , 'secondaryNavColor');
	cancelHide('primaryNavHowTo'      , 'secondaryNavHowTo');
	cancelHide('primaryNavProducts'   , 'secondaryNavProducts');
	cancelHide('primaryNavInspiration', 'secondaryNavInspiration');
	
	$('primaryNavHome').removeClassName('current');
	$('primaryNavColor').removeClassName('current');
	$('primaryNavHowTo').removeClassName('current');
	$('primaryNavProducts').removeClassName('current');
	$('primaryNavInspiration').removeClassName('current');
	
	$('secondaryNavColor').hide();
	$('secondaryNavHowTo').hide();
	$('secondaryNavProducts').hide();
	$('secondaryNavInspiration').hide();
}

function cancelHide(primary, secondary)
{
	// Stop any scheduled hide events on primary menu
	if (validId(primary))
	{
		if ($(primary).hideExecuter)
		{
			$(primary).hideExecuter.stop();
		}
	}

	// Stop any scheduled hide events on secondary menu
	if (validId(secondary))
	{
		if ($(secondary).hideExecuter)
		{
			$(secondary).hideExecuter.stop();
		}
	}
}

function hideMenu(primary, secondary)
{
	var delay = .05;
	
	// Hide primary menu after delay
	if (validId(primary))
	{
		$(primary).hideExecuter = new PeriodicalExecuter
		(
			function(e)
			{
				$(primary).removeClassName('current');
				e.stop();
			},
			delay
		);
	}

	// Hide secondary menu after delay
	if (validId(secondary))
	{
		$(secondary).hideExecuter = new PeriodicalExecuter
		(
			function(e)
			{
				$(secondary).hide();
				e.stop();
			},
			delay
		);
	}
}
