var currentMenu = null;
var mytimer = null;
var timerOn = false;
var opera = window.opera ? true : false;

if (!document.getElementById)
{
  document.getElementById = function() { return null; }
}

function initialiseMenu(menuId, starterId)
{
  var menu = document.getElementById(menuId);
  var starter = document.getElementById(starterId);

  if (menu == null || starter == null)
  {
    return;
  }
  
  currentMenu = menu;

  starter.onmouseover = function()
  {
    if (currentMenu)
    {
      currentMenu.style.visibility = "hidden";
      currentMenu = null;
      this.showMenu();
      stopTime();
    }
  }

  menu.onmouseover = function()
  {
    if (currentMenu)
    {
      currentMenu.style.visibility = "hidden";
      currentMenu = null;
      this.showMenu();
    }
  }

  starter.showMenu = function()
  {
    if (!opera)
    {
      menu.style.left = this.offsetLeft + "px";
      menu.style.top = this.offsetTop + this.offsetHeight + "px";
    }
    else
    {
      menu.style.left = this.offsetLeft + "px";
      menu.style.top = this.offsetHeight + "px";
    }
    
    menu.style.visibility = "visible";
    currentMenu = menu;
  }

  starter.onfocus = function()
  {
    this.onmouseover();
  }

  starter.onblur = function()
  {
    this.onmouseout();
  }

  menu.showMenu = function()
  {
    menu.style.visibility = "visible";
    currentMenu = menu;
    stopTime();
  }

  menu.hideMenu = function()
  {
    if (!timerOn)
    {
      mytimer = setTimeout("killMenu('" + menuId + "');", 500);
      timerOn = true;
    }
  }

  menu.onmouseout = function(event)
  {
    this.hideMenu();
  }

  starter.onmouseout = function()
  {
    menu.hideMenu();
  }
}

function killMenu(amenu)
{
  var menu = document.getElementById(amenu);
  menu.style.visibility = "hidden";
  stopTime();
}

function stopTime()
{
  if (mytimer)
  {
     clearTimeout(mytimer);
     mytimer = null;
     timerOn = false;
  }
}

window.onload = function()
{
  initialiseMenu("menu1", "menu1Starter");
  initialiseMenu("menu2", "menu2Starter");
  initialiseMenu("menu3", "menu3Starter");
  initialiseMenu("menu4", "menu4Starter");
  initialiseMenu("menu5", "menu5Starter");
  initialiseMenu("menu6", "menu6Starter");
  initialiseMenu("menu7", "menu7Starter");
  initialiseMenu("menu8", "menu8Starter");
}

ie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ))
ns4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 ))

if (ns4)
{
  layerRef="document.layers";
  styleRef="";
}
else
{
  layerRef="document.all";
  styleRef=".style";
}

function afficheCalque(calque)
{
  eval(layerRef + '["' + calque +'"]' + styleRef + '.visibility = "visible"');
}

function cacheCalque(calque)
{
  eval(layerRef + '["' + calque +'"]' + styleRef + '.visibility = "hidden"');
}

