var scftimer=new Object;

//Sets the visibility of the DOM element el to hidden
function hide_el(el)
{
	el.style.visibility='hidden';
}

//Sets the visibility of the DOM element el to visible
function show_el(el)
{
	el.style.visibility='visible';
}

//Cancels hiding of all menus
function cancel_hide()
{
	if (scftimer['linkbar'])
		clearTimeout(scftimer['linkbar']);
	scftimer['linkbar']=0;
}

//Displays the menu with ID which
function sm(which)
{
	cancel_hide();

	element=document.getElementById(which);
	if (!element)
		return;
	
	if (scftimer[which])
		clearTimeout(scftimer[which]);
			
	show_el(document.getElementById(which));
}

//Hides the menu with ID which after a brief delay
function hm(which)
{
	element=document.getElementById(which);
	if (!element)
		return;

	if (scftimer[which])
		clearTimeout(scftimer[which]);

	scftimer[which]=setTimeout("reset_menu('"+which+"')", 30);
}

//Hides all menus after a delay
function hmd()
{
	if (scftimer['linkbar'])
		clearTimeout(scftimer['linkbar']);
	
	scftimer['linkbar']=setTimeout("hide_menus()", 500);
}

//Hides all menus
function hide_menus()
{
	scftimer['linkbar']=0;

	element=document.getElementById('linkbar');
	if (!element) {
		return;
	}

	hide_children(element);
}

//Hides the menu with ID which, and all submenus
function reset_menu(which)
{
	scftimer[which]=0;
	element=document.getElementById(which);
	if (!element)
		return;
		
	hide_el(element);
	hide_children(element);
}

//Shows the menu with ID which while hiding any sibling menus
function showonly(which)
{
	sm(which);
	hs(which);
}

//Hides the sibling menus of the menu with ID which
function hs(which)
{
	var menu;
	var subm;
	
	var element=document.getElementById(which);
	if (!element)
		return;
	
	for (var i=0; i < element.parentNode.parentNode.childNodes.length; i++)
	{
		subm=element.parentNode.parentNode.childNodes.item(i);
		
		if (subm.nodeType == 1 && classForElement(subm) == 'menuitem')
		{
			for (var j=0; j < subm.childNodes.length; j++)
			{
				menu=subm.childNodes.item(j);
				if (menu.nodeType == 1 && classForElement(menu) == 'menu' && menu.getAttribute('id') != which)
				{
					hide_el(menu);
					hide_children(menu);
				}
			}
		}
	}
}

//Hides the children of the menu with ID which
function hc(which)
{
	element=document.getElementById(which);
	if (!element)
		return;
		
	hide_children(element);
}

//Returns the class attribute for the DOM element el
//MSI rewrites the attribute name from class to className for no reason
function classForElement(el)
{
	c=el.getAttribute('class');
	if (!c)
		c=el.getAttribute('className');	//IE is a pile of shite
	return c;
}

//Hides all child menus of the DOM element el
function hide_children(el)
{
	var j;

	for (j=0; j < el.childNodes.length; j++)
	{
		var menu=el.childNodes.item(j);
		if (menu.nodeType == 1)
		{
			if (classForElement(menu) == 'menu')
			{
				hide_el(menu);
				hide_children(menu);
			}
			else if (classForElement(menu) == 'menuitem')
				hide_children(menu);
		}
	}
}
