var popupTimerHandle = null;
var sub = null;

function stopCounting(){if(popupTimerHandle != null ){ clearTimeout(popupTimerHandle); popupTimerHandle = null; }}

function showSub(what)
 {
 if(what != 'none')
  {
   if (sub != null) { document.getElementById('es'+sub).className="HmainMenu"; }
   if (popupTimerHandle != null ) { clearTimeout(popupTimerHandle); popupTimerHandle = null; }
   if (what == null) { what = sub; }
   sub = what;

   if(s[what]==''){
    document.getElementById('top').className="levelUp";
    document.getElementById('subberName').className="levelUp2";

    document.getElementById('under').style.marginLeft=margin(what)-16;
    document.getElementById('es'+what).className="HmainMenu2";
    if(what == defVar){ document.getElementById('es'+sub).className="HmainMenuSel"; }
    document.getElementById('subberName').innerHTML = document.getElementById('es'+what).innerHTML;
    document.getElementById('bottom').style.display="none";
    document.getElementById('under').style.display="inline";
   }
   else
   {
    document.getElementById('top').className="";
    document.getElementById('subberName').className="";

    document.getElementById('under').style.marginLeft=margin(what)-16;
    document.getElementById('es'+what).className="HmainMenu2";
    if(what == defVar){ document.getElementById('es'+sub).className="HmainMenuSel"; }
    document.getElementById('subberName').innerHTML = document.getElementById('es'+what).innerHTML;
    document.getElementById('subber').innerHTML = s[what];
    document.getElementById('bottom').style.display="block";
    document.getElementById('under').style.display="inline";
    x = document.getElementById('subber');
    y = document.getElementById('es'+what);
    end = document.getElementById('es'+what);
    endPosition = end.offsetLeft+x.offsetWidth;
    if(endPosition>800) { a = endPosition-800-18; document.getElementById('bottom').style.marginLeft = '-'+a+'px'; }else{ document.getElementById('bottom').style.marginLeft = '0px'; }
   }
  }
 }

function hideSub(what) {
  if(what == null){ what = sub; }
  if(s[what]==''){popupTimerHandle = setTimeout("reallyHideSub('" + what + "');", 200);}
  else{popupTimerHandle = setTimeout("reallyHideSub('" + what + "');", 550);}
 }

function reallyHideSub(what) {

    if(what != defVar)
     {
      what = sub;
      sub = null;
      document.getElementById('es'+what).className="HmainMenu";
      document.getElementById('under').style.display="none";
      if(defVar != 'none'){setTimeout('showSub(defVar)',50);}
     }


 }


function margin(what) {
  x = document.getElementById('es'+what);
  return x.offsetLeft;
 }





function attachBehaviors(){
   if(defVar !='none'){ showSub(defVar); }
   var az = document.getElementById('subber');
   if(!az ) return;
   az.onmouseover = function(){return stopCounting();};
   az.onmouseout = function(){return hideSub(null);};
   document.getElementById('es1').onmouseover = function(){showSub(1);};
   document.getElementById('es1').onmouseout = function(){hideSub(1);};
   document.getElementById('es2').onmouseover = function(){showSub(2);};
   document.getElementById('es2').onmouseout = function(){hideSub(2);};
   document.getElementById('es3').onmouseover = function(){showSub(3);};
   document.getElementById('es3').onmouseout = function(){hideSub(3);};
   document.getElementById('es4').onmouseover = function(){showSub(4);};
   document.getElementById('es4').onmouseout = function(){hideSub(4);};
   document.getElementById('es5').onmouseover = function(){showSub(5);};
   document.getElementById('es5').onmouseout = function(){hideSub(5);};
   document.getElementById('es6').onmouseover = function(){showSub(6);};
   document.getElementById('es6').onmouseout = function(){hideSub(6);};
   document.getElementById('es7').onmouseover = function(){showSub(7);};
   document.getElementById('es7').onmouseout = function(){hideSub(7);};
 }


window.onload = attachBehaviors;

