
function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.isIE		  = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 
	this.isOpera	  = (ua.indexOf('opera') != -1); 	
	if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	this.versionMajor = parseInt(this.versionMinor); 
	this.isDOM1 = (document.getElementById);
	this.isMac	= (ua.indexOf('mac') != -1);
}
var browser = new BrowserDetectLite();


var timeout = 300;
var nbI = 0;
var BrowserOK = browser.isDOM1 && !( browser.isMac && browser.isIE )  && !( browser.isOpera && browser.versionMajor < 7 ) && !( browser.isIE && browser.versionMajor < 5 );

for( var i = 0; i < 150; i++ )
{
	eval("var timeoutli" + i + " = false;");
}

function InitMenu(mID)
{
	if ( BrowserOK )
	{
		var menu = document.getElementById(mID);
		var lis = menu.getElementsByTagName("li");
		
		cClass( menu, mID );

		for ( var i=0; i<lis.length; i++ )
		{
			if ( lis.item(i).getElementsByTagName('ul').length > 0 )
			{
				addEvt(lis.item(i),'mouseover',show);
				addEvt(lis.item(i),'focus',show);
				addEvt(lis.item(i),'mouseout',timeoutHide);
				addEvt(lis.item(i),'blur',timeoutHide);

				lis.item(i).setAttribute( 'id', "li"+eval(nbI+i) );

				if( lis.item(i).parentNode.id != menu.id && mID=="hm")
				{
					if( lis.item(i).getElementsByTagName('span').length > 0 )
						cClass( lis.item(i).getElementsByTagName('span')[0], 'hm-arrow' );
					else
						cClass( lis.item(i).getElementsByTagName('a')[0], 'hm-arrow' );
				}
			}
		}
		nbI=i;
	}
}

function cClass( target, className )
{
	if ( browser.isIE )	{target.setAttribute( 'className', className );}
	else		{target.setAttribute( 'class', className );}
}

function addEvt( target, eventName, functionName )
{
	if ( browser.isIE )	{eval('target.on'+eventName+'=functionName');}
	else		{target.addEventListener( eventName , functionName , false );}
}

function timeoutHide()
{
	eval( "timeout" + this.id + " = window.setTimeout('hideUl( \"" + this.id + "\" )', " + timeout + " );");
}

function hideUl( id )
{
	document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
}

function show()
{
	this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
	eval ( "clearTimeout( timeout"+ this.id +");" );
	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 )
		{
			hideLi( ul.childNodes[i] );
		}
	}
}

function hideLi( li )
{
	var uls = li.getElementsByTagName('ul');
	for ( var i=0; i<uls.length; i++ )
	{
		uls.item(i).style['visibility'] = 'hidden';
	}
}
