var timeout = 500;
var ua = navigator.userAgent.toLowerCase(); 
var isIE = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 

function initMenu(identity) {

	if (Br.DOM) {
		var menu = getE(identity);
		var lis = menu.getElementsByTagName('li');
		
		for ( var i=0; i<lis.length; i++ ) {
		
			if ( lis.item(i).getElementsByTagName('ul').length > 0 ) 
			{
				if ( Br.IE ) {addAnEvent(lis.item(i),'keyup',show); }
				addAnEvent(lis.item(i),'mouseover',show);
				addAnEvent(lis.item(i),'mouseout',timeoutHide);
				addAnEvent(lis.item(i),'blur',timeoutHide);
				addAnEvent(lis.item(i),'focus',show);
				lis.item(i).id = "li"+i; eval("timeoutli" + i + " = false;");
			}
		}
	}	
}

function addAnEvent( target, eventName, functionName ) {
	if ( Br.IE ) {eval('target.on'+eventName+'=functionName');}
	else         {target.addEventListener( eventName , functionName , true ); }
}

function timeoutHide() { try { eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );"); } catch(e) {}}

function hideUlUnder( id ) 
{   
	if (document.getElementById(id)) {
	    document.getElementById(id).className = document.getElementById(id).className.replace(/sel/g, ""); ;
		document.getElementById(id).getElementsByTagName('ul')[0].style.visibility = 'hidden';
		SelectHide('visible');
	}
}

function show() 
{
	this.getElementsByTagName('ul')[0].style.visibility = 'visible';
	SelectHide('hidden');
	if (this.className.search('sel') == -1) this.className += " sel"; 
	try { if (eval("timeout"+ this.id)) eval ( "clearTimeout( timeout"+ this.id +");" ); } catch(e) {} 
	hideAllOthersUls( this );
}

function hideAllOthersUls( currentLi ) 
{
	var ul = currentLi.parentNode;
	for ( var i=0; i<ul.childNodes.length; i++ ) {
		if ( ul.childNodes[i].id && ul.childNodes[i].id != currentLi.id ) {hideUlUnderLi( ul.childNodes[i] );}
	}
}

function hideUlUnderLi( li ) 
{
    li.className = li.className.replace(/sel/g, "");
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ ) { 	uls.item(i).style.visibility = 'hidden'; }
} 

