
// the timeout for the menu
var timeout = 1000;
function timeoutHide(obj)
{
obj.style.backgroundColor="#8B1313";
    eval( "timeout" + obj.id + " = window.setTimeout('hideUlUnder( \"" + obj.id + "\" )', " + timeout + " );");
}
function hideUlUnder( id )
{
    var uls=document.getElementById(id).getElementsByTagName('ul');
    if (uls.length>=1)
      uls[0].style['visibility'] = 'hidden';
}
function show(obj)
{
obj.style.backgroundColor="#0E0E61";
    var uls=obj.getElementsByTagName('ul');
    if (uls.length>=1) {
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 );
}
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 )
{
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ )
    {
        uls.item(i).style['visibility'] = 'hidden';
    }
} 
function nwGetY(obj) {
  return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+nwGetY(obj.offsetParent) );
}

