// Some of this code was based on a tutorial at:
// http://www.quirksmode.org/js/events_mouse.html		

// Check if this element is contained in the element with the specified id.
function isChildNode(elt, parentid)
{
	var o = elt;
	
	if (o == null) return(false);

	// Go through all parents until you hit the "body" element or there's an ID match.
	while (o.id != parentid && o.nodeName != 'BODY')	
		o = o.parentNode					

	if (!o.id) return(false);
	if (o.id == parentid) return(true);
	
	return(false);	
}

function GetTarget()
{
	if (!e) var e = window.event;		
	var target = (e.relatedTarget) ? e.relatedTarget : e.toElement;			
	return(target);
}

function HideMenu(e) 
{								
    var target = GetTarget();	
	var child = isChildNode(target, 'menu');				
	if (child) return;		
		
	// Hide the menu.	
	var obj = GetMenuObject();
	obj.style.visibility = 'hidden';											
}

function HideExpMenu(e) 
{								
	var target = GetTarget();	
	var child = isChildNode(target, 'menu-exp');			
	
	if (child) return;		
		
	// Hide the menu.	
	var obj = GetExpMenuObject();
	obj.style.visibility = 'hidden';											
}
function HideLoginMenu(e) 
{								
	var target = GetTarget();	
	var child = isChildNode(target, 'menu-log');			
	
	if (child) return;		
		
	// Hide the menu.	
	var obj = GetLoginMenuObject();
	obj.style.visibility = 'hidden';											
}

function GetMenuObject()
{
	var obj = document.getElementById("menu");																											
	return(obj);
}

function GetExpMenuObject()
{
	var obj = document.getElementById("menu-exp");
	return(obj);
}
function GetLoginMenuObject()
{
	var obj = document.getElementById("menu-log");
	return(obj);
}


function CloseOpenMainMenu()
{			
	var obj = GetMenuObject();	
	if (obj == null) return;
	
	obj.style.visibility = 'hidden';		
}

function CloseOpenExpMenu()
{			
	var obj = GetExpMenuObject();	
	if (obj == null) return;
	
	obj.style.visibility = 'hidden';
	
	
}

function CloseOpenLoginMenu()
{			
	var obj = GetLoginMenuObject();	
	if (obj == null) return;
	
	obj.style.visibility = 'hidden';
	
	
}
function ShowMenu()
{	
	CloseOpenExpMenu();
	CloseOpenLoginMenu();
	var obj = GetMenuObject();
	
	if (obj.style.visibility == 'visible')
		obj.style.visibility = 'hidden';
	else	
		obj.style.visibility = 'visible';				
}

function ToggleVisibility(obj)
{
	if (obj.style.visibility == 'visible')
		obj.style.visibility = 'hidden';
	else	
		obj.style.visibility = 'visible';
}

function ShowExpMenu()
{		
	CloseOpenMainMenu();
	CloseOpenLoginMenu();
	
	var obj = GetExpMenuObject();
		
	ToggleVisibility(obj);		
						
				
}
function ShowLoginMenu()
{		
	CloseOpenMainMenu();
	CloseOpenExpMenu();
	
	var obj = GetLoginMenuObject();
		
	ToggleVisibility(obj);		
						
			
}

function StartPage()
{		
	var menu = GetMenuObject();		
	document.body.onclick = CloseAllMenus;			    	
}


function CloseAllMenus()
{        
    return;
    
    var target = GetTarget();        
	CloseOpenMainMenu();
    CloseOpenExpMenu();	
	CloseOpenLoginMenu();            
    
    var menu = GetMenuObject();    
    HideMenu(menu);    
}

