// The following functions are by Guillaume Fallet.



function jsmenu_hover(obj,state)
{
  UL = obj.getElementsByTagName('ul');
  if (UL.length > 0) {
    submenu = UL[0].style;
    if (state == 1) {
      submenu.display = 'block';
    } else {
      submenu.display = 'none';
    }
  }
}

function jsmenu_clean()
{
  LI = document.getElementById('menu').getElementsByTagName('li');
  nLI = LI.length;
  // hide all nested popup menus (in reverse order because hiding parents before their childs doesn't work properly)
  for (i=nLI-1; i >= 0; i--) {
      jsmenu_hover(LI[i],0);
  }
}

var jsmenu_timeout;

function jsmenu_init()
{
  jsmenu_timeout=-1;
  LI = document.getElementById('menu').getElementsByTagName('li');
  nLI = LI.length;

  for (i=0; i < nLI; i++) {
    // add onmousexxx events on all LI elements
    LI[i].onmouseover = function() {
        if (jsmenu_timeout != 0) {
            clearTimeout(jsmenu_timeout);
            jsmenu_timeout = 0;
            jsmenu_clean();
        }
        jsmenu_hover(this,1);
    }
    LI[i].onmouseout = function() {
        if (jsmenu_timeout == 0)
            jsmenu_timeout = setTimeout(jsmenu_clean, 500);
    }
  }
}
