var oFCurrentMenu = 0;


function getMenu(event)
{
	if ( window.browser.ie ) {
		return window.event.srcElement;
	} else {
		return event.currentTarget;
	}
}

function getParentMenu(ASubMenu)
{
	while ( ASubMenu.tagName != null ) 
	{
		if ( ( ASubMenu.tagName == 'UL' ) ) 
		{ 
			return ASubMenu;
		}
		ASubMenu = ASubMenu.parentNode;
	}
	return ASubMenu;
}

function getSubmenu( _id )
{
	for ( var i = 0; i < window.submenus.length; i++ ) {
		//if ( window.submenus[ i ].indexOf( 'sub_' + _id /*+ '_'*/ ) != -1 ) {
		if ( window.submenus[ i ] == 'sub_' + _id ) {
			return window.submenus[ i ];
		}
	}
	return null;
}

function getX( _menu ) {
	var _x = _menu.offsetLeft ;
	
	/*if ( _menu.offsetParent != null )	{
	  if ( _menu.offsetParent.id != 'headerCntr' ) // Filter out Main Container 
			_x += window.getX( _menu.offsetParent ) ;
	} ;*/
	
	return _x ;
}

function getY( _menu ) {
	var _y = _menu.offsetTop ;
	/*
	if ( _menu.offsetParent != null ) {
	 	if ( _menu.offsetParent.id != 'headerCntr' ) // Filter out Main Container 
			_y += window.getY( _menu.offsetParent ) ;
	} ;
	*/
	return _y ;
}

function hideSubmenu(AMenu)
{
	//AMenu.className = AMenu.className.replace('Active', '') ;
	if ( AMenu.submenu != null ) 
  {
		window.hideSubsubmenu( AMenu.submenu ) ;
		AMenu.submenu.style.visibility = 'hidden' ;
    AMenu.style.backgroundColor = '';
	}
}

function hideSubsubmenu(ASubMenu) 
{
	if ( ASubMenu.activeItem == null ) {
		return ;
	} ;
	
	if ( ASubMenu.activeItem.submenu != null ) {
		window.hideSubsubmenu( ASubMenu.activeItem.submenu ) ;
		ASubMenu.activeItem.submenu.style.visibility = 'hidden' ;
		ASubMenu.activeItem.submenu = null ;
	} ;
	
	//ASubMenu.activeItem.className = ASubMenu.activeItem.className.replace( 'Active' , '' ) ;
	ASubMenu.activeItem = null ;
} ;


function menuHide()
{	
	if ( window.activeMenu != null ) 
  {
		window.hideSubmenu( window.activeMenu );
		window.activeMenu = null;
	}	
	clearTimeout( window.hidetimer );
}

function menuOver(event)
{
 	var _menu = window.getMenu(event);
	if ( window.hidetimer != null ) 
  {
		clearTimeout(window.hidetimer);
		window.hidetimer = null;
	}
	
  if ( _menu != null )
  {
  	if ( _menu.tagName == 'A' && !_menu.id ) _menu = _menu.parentNode;
  
  	if ( _menu != window.activeMenu ) 
    {
  		if ( _menu.id.indexOf( 'm_' ) != -1 ) 
      {
  			_menu.number = _menu.id.replace( 'm_' , '' );
  			window.showSubmenu( _menu ) ;
  		} else {
  			//_menu.number = _menu.id.replace( 's_' , '' );
  			//window.showSubsubmenu( _menu ) ;
  		}
  	}
  }
	return false
}

function menuOut(event)
{
 	var _menu = window.getMenu(event);
	if ( window.activeMenu == null ) 
	{
		return;
	}
	if ( window.hidetimer != null )
	{ 
		clearTimeout(window.hidetimer);
		window.hidetimer = null;
	}	  
	window.hidetimer = setTimeout('menuHide()' , 300);
	return false;
}

function showSubmenu(_menu)
{
	if ( _menu.submenu == null ) {
		var _thisSubmenu = window.getSubmenu( _menu.number ) ;
		if ( _thisSubmenu != null ) {
			_menu.submenu = document.getElementById( _thisSubmenu ) ;
		}
	}
	
	if ( window.activeMenu != null ) {
		window.hideSubmenu( window.activeMenu ) ;
	}
	
	window.activeMenu = _menu;
	window.mainMenu = _menu;
	
	if ( _menu.submenu != null ) {
		var _x = window.getX( _menu ) - 1; // -4
	
		var _y = window.getY( _menu ) + 13 ; // 11
		
		if ( window.browser.ie  ) {
			_y += 3 ;
      //if ( window.browser.major < 8 )
        //_menu.submenu.style.position = 'fixed';
		}
    
		//_menu.submenu.style.left = _x + 'px' ;
		//_menu.submenu.style.top = _y + 'px' ;
		_menu.submenu.style.zIndex = 5;
		_menu.submenu.style.visibility = 'visible' ;
    _menu.style.backgroundColor = '#777263';
	}
}

function showSubsubmenu(ASubMenu)
{
	var _thisSubmenu = window.getSubmenu( ASubMenu.number ) ;
	var _parentMenu = window.getParentMenu( ASubMenu ) ;

	  	

	if ( _parentMenu.activeItem != null ) 
	{
		window.hideSubsubmenu( _parentMenu ) ;
	}

	if ( _thisSubmenu != null ) 
	{
		_parentMenu.activeItem = ASubMenu ;

		window.activeMenu = window.mainMenu;

		if ( ASubMenu.submenu == null ) 
		{
			ASubMenu.submenu = document.getElementById( _thisSubmenu ) ;
		} ;
		
		var _x = window.getX( ASubMenu ) + ASubMenu.offsetWidth ; // ; //+ 3; 
		
		var _y = window.getY( ASubMenu ); // -3; 
		
		/*if ( window.browser.ie )
    {
    	if ( window.browser.major >= 8 )
				ASubMenu.submenu.style.position = 'relative';
       else
				ASubMenu.submenu.style.position = 'absolute';
    }*/
		ASubMenu.submenu.style.left = _x + 'px' ;
		ASubMenu.submenu.style.top = _y + 'px' ;
		ASubMenu.submenu.style.zIndex = 5;
		ASubMenu.submenu.style.visibility = 'visible' ;
	} else {
		_parentMenu.activeItem = null ;
	}
	return;
}


function browser() { 
	var agt = navigator.userAgent.toLowerCase();
	
	// Browser version
	this.major = parseInt( navigator.appVersion);
	this.minor = parseFloat( navigator.appVersion );
	this.nav = ( ( agt.indexOf( 'mozilla' ) != -1 ) && ( ( agt.indexOf( 'spoofer' ) == -1 ) && ( agt.indexOf( 'compatible' ) == -1 ) ) );
	this.nav2 = ( this.nav && ( this.major == 2 ) );
	this.nav3 = ( this.nav && ( this.major == 3 ) );
	this.nav4 = ( this.nav && ( this.major == 4 ) );
	this.navonly = ( this.nav && ( agt.indexOf( ';nav' ) != -1 ) );
	this.ie = ( agt.indexOf( 'msie' ) != -1 );
	this.ie3 = ( this.ie && ( this.major == 2 ) );
	this.ie4 = ( this.ie && ( this.major == 4 ) );
	this.opera = ( agt.indexOf( 'opera' ) != -1 );
};


window.onload = function() {
	window.submenus = new Array();
	window.browser = new window.browser();
	window.activeMenu = null;
	window.mainMenu = null;
	window.hidetimer = null;
	
	var _uls = document.getElementsByTagName( 'UL' );
	
	for ( var i = 0 ; i < _uls.length ; i++ ) {
		if ( _uls[ i ].id.indexOf( 'sub_' ) == 0 ) {
			window.submenus[ window.submenus.length ] = _uls[ i ].id;
			//window.resizeSubmenu( _uls[ i ].id );
		}
	}
	
	return true;
  
}

