
// the timeout for the menu
var timeout = 100;

// not very clean but simple
// the function can be run in the HTML for faster display
// window.onload=initMenu;

// hide the first ul element of the current element
function timeoutHide(obj)
{
//obj.style.visibility='hidden';

//hideUlUnder(this.id);

//eval("timeoutA"+obj.id+" = window.setTimeout('document.getElementById(\""+obj.id+"\").style.backgroundColor=\"#73D0FF\"' ,100);");
obj.style.backgroundColor="#ffffff";

    // start the timeout

    eval( "timeout" + obj.id + " = window.setTimeout('hideUlUnder( \"" + obj.id + "\" )', " + timeout + " );");

}

// hide the ul elements under the element identified by id
function hideUlUnder(id)
{

var imgs = document.getElementById(id).getElementsByTagName('IMG');
	 if (imgs[0]) {
      var newimgsrc = imgs[0].src.replace(/_on.gif/, ".gif");
      imgs[0].src = newimgsrc;
	 }



    var uls=document.getElementById(id).getElementsByTagName('ul');
    if (uls.length>=1) {
      uls[0].style['visibility'] = 'hidden';
      
     
      
      
    }
}

// show the first ul element found under this element
function show(obj)
{
	//if (img && imgsrc) MM_swapImage(img,'',imgsrc,1);

	var imgs = obj.getElementsByTagName('IMG');
	if (imgs[0]) {
      var newimgsrc = imgs[0].src;
      if (!newimgsrc.match(/_on.gif/)) {
      newimgsrc = newimgsrc.replace(/.gif/, "_on.gif");
      imgs[0].src = newimgsrc;
      }
	}

if(!obj.childNodes[0].childNodes[0]||obj.childNodes[0].childNodes[0].tagName!='IMG')
	obj.style.backgroundColor="#ffffff";

//if (eval("typeof(timeoutA"+obj.id+")") != "undefined") eval ( "clearTimeout( timeoutA"+ obj.id +");" );

    // show the sub menu
    var uls=obj.getElementsByTagName('ul');
    if (uls.length>=1) {


// see whether we should move the menu
var ul=uls[0];
var botWin =  document.body.clientHeight;
var topPos = nwGetY(ul);
var botPos = topPos + ul.offsetHeight;
if (botPos > botWin) {
  var newPos = ul.offsetTop - (botPos - botWin);
  ul.style.top = newPos;
}



      uls[0].style['visibility'] = 'visible';
    }
    // clear the timeout
if (eval("typeof(timeout"+obj.id+")") != "undefined")
    eval ( "clearTimeout( timeout"+ obj.id +");" );
    hideAllOthersUls( obj );
}

// hide all ul on the same level of  this list item
function hideAllOthersUls( currentLi )
{
    var ul = currentLi.parentNode;
    //alert(lis.childNodes.length);
    for ( var i=0; i<ul.childNodes.length; i++ )
    {
        if ( ul.childNodes[i].id && ul.childNodes[i].id != currentLi.id )
        {
            hideUlUnderLi( ul.childNodes[i] );
        }
    }
}

// hide all the ul wich are in the li element
function hideUlUnderLi( li )
{
	
	var imgs = li.getElementsByTagName('IMG');
	if (imgs[0]) {
      var newimgsrc = imgs[0].src.replace(/_on.gif/, ".gif");
      imgs[0].src = newimgsrc;
	}
	
	
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ )
    {
        uls.item(i).style['visibility'] = 'hidden';
	
	
      
      
    }
} 

// get Y position of the object on a page
function nwGetY(obj) {
  return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+nwGetY(obj.offsetParent) );
}





