var menuItem = 0;
var menuItemChildren = 0;
var closeTimer = 0;
var timeOut = 350;

/* showMenu (id)
 * Shows a menu by id
 *  -called when the user hovers the cursor over a pulldown menu
**/
function showMenu (id)
{
	if (closeTimer)
	{
		clearTimeout(closeTimer);
	}
	if (menuItem)
	{
		hideAllMenu();
	}

	menuItem = document.getElementById (id);
	menuItemChildren = menuItem.childNodes;
	menuItemChildren.item(0).style.visibility = 'visible';
	
	menuItemChildren = menuItemChildren.item(0).childNodes;

	for (i = 0; i < menuItemChildren.length; i++)
	{
		menuItemChildren.item(i).style.visibility = 'visible';	
	}
	
	//show markers
	
	if (id == 'prodpd')
	{
		document.getElementById ('battpdmark').style.visibility = 'visible';
		document.getElementById ('acspdmark').style.visibility = 'visible';
	}
}


function showNestedMenu (id, hideId)
{
	if (closeTimer)
	{
		clearTimeout(closeTimer);
	}
	if (hideId)
	{
		hideMenu (hideId);
	}
	
		
	//hide and show marker
	if (id == 'battpd')
	{
		document.getElementById ('battpdmark').style.visibility = 'hidden';
		document.getElementById ('acspdmark').style.visibility = 'visible';
	}
	else if (id == 'acspd')
	{
		document.getElementById ('acspdmark').style.visibility = 'hidden';
		document.getElementById ('battpdmark').style.visibility = 'visible';
	}
	
	menuItem = document.getElementById (id);
	menuItemChildren = menuItem.childNodes;
	menuItemChildren.item(0).style.visibility = 'visible';
	
	menuItemChildren = menuItemChildren.item(0).childNodes;

	for (i = 0; i < menuItemChildren.length; i++)
	{
		menuItemChildren.item(i).style.visibility = 'visible';	
	}
}


/* hideMenu (id)
 * Hides a menu by id
 *  -called when the user switches pulldown menus
**/
function hideMenu (id)
{
	//if nested menu, show marker
	/*
	if (id == 'battpd')
	{
		document.getElementById ('battpdmark').style.visibility = 'visible';
	}
	else if (id == 'acspd')
	{
		document.getElementById ('acspdmark').style.visibility = 'visible';
	}*/
	

	menuItem = document.getElementById(id);
	//since <div> is the child nodes of menuitem, the links are the childnode of <div>
	menuItemChildren = menuItem.childNodes;
	menuItemChildren.item(0).style.visibility = 'hidden';
	
	menuItemChildren = menuItemChildren.item(0).childNodes;

	for (i = 0; i < menuItemChildren.length; i++)
	{
		menuItemChildren.item(i).style.visibility = 'hidden';
	}
}

/* hideAllmenu()
 * Hides every pull down menu
 *  -called when the user is not hovering their cursor over any pulldown
**/
function hideAllMenu()
{
	//main pulldowns
	hideMenu('prodpd');
	hideMenu('applpd');
	hideMenu('supportpd');
	hideMenu('ordpd');
	
	//nested pulldowns
	hideMenu('battpd');
	hideMenu('acspd');
	
	document.getElementById ('battpdmark').style.visibility = 'hidden';
	document.getElementById ('acspdmark').style.visibility = 'hidden';
}

/* stopTimer ()
 * Stops the hide timer
 *  -called when a link is hovered over, or a pulldown is activated
**/
function stopTimer ()
{
	if (closeTimer)
	{
		clearTimeout(closeTimer);
	}
}

/* startTimer ()
 * Starts the hide timer
 *  -called when the cursor is not activating a pulldown menu
**/
function startTimer ()
{
	closeTimer = setTimeout("hideAllMenu()", timeOut);
}


/**OLD FUNCTIONS**/
/* showMenu (id)
 * Shows a menu by id
 *  -called when the user hovers the cursor over a pulldown menu
**//*
function showMenu (id)
{
	if (closeTimer)
	{
		clearTimeout(closeTimer);
	}
	if (menuItem)
	{
		hideAllMenu();
	}
	menuItem = document.getElementById (id);
	menuItemChildren = menuItem.childNodes;
	menuItemChildren.item(1).style.visibility = 'visible';
	
	menuItemChildren = menuItemChildren.item(1).childNodes;

	for (i = 1; i < menuItemChildren.length; i += 2)
	{
		menuItemChildren.item(i).style.visibility = 'visible';	
	}
}


function showNestedMenu (id, hideId)
{
	if (closeTimer)
	{
		clearTimeout(closeTimer);
	}
	if (hideId)
	{
		hideMenu (hideId);
	}
	
	menuItem = document.getElementById (id);
	menuItemChildren = menuItem.childNodes;
	menuItemChildren.item(1).style.visibility = 'visible';
	
	menuItemChildren = menuItemChildren.item(1).childNodes;

	for (i = 1; i < menuItemChildren.length; i += 2)
	{
		menuItemChildren.item(i).style.visibility = 'visible';	
	}
}


function hideNestedMenu (id)
{
	hideMenu (id);
	startTimer();
}

/* hideMenu (id)
 * Hides a menu by id
 *  -called when the user switches pulldown menus
**//*
function hideMenu (id)
{
	menuItem = document.getElementById(id);
	//since <div> is the child nodes of menuitem, the links are the childnode of <div>
	menuItemChildren = menuItem.childNodes;
	menuItemChildren.item(1).style.visibility = 'hidden';
	
	menuItemChildren = menuItemChildren.item(1).childNodes;

	for (i = 1; i < menuItemChildren.length; i += 2)
	{
		menuItemChildren.item(i).style.visibility = 'hidden';
	}
}

/* hideAllmenu()
 * Hides every pull down menu
 *  -called when the user is not hovering their cursor over any pulldown
**//*
function hideAllMenu()
{
	//main pulldowns
	hideMenu('prodpd');
	hideMenu('applpd');
	hideMenu('supportpd');
	
	//nested pulldowns
	hideMenu('battpd');
	hideMenu('acspd');
}

/* stopTimer ()
 * Stops the hide timer
 *  -called when a link is hovered over, or a pulldown is activated
**//*
function stopTimer ()
{
	if (closeTimer)
	{
		clearTimeout(closeTimer);
	}
}

/* startTimer ()
 * Starts the hide timer
 *  -called when the cursor is not activating a pulldown menu
**//*
function startTimer ()
{
	closeTimer = setTimeout("hideAllMenu()", timeOut);
}
*/
