//var gl_menuBar_f = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
var gl_menuBar_f = new Array(0, 0, 0, 0, 0, 0);
var visible_niveau3 = 0;
//var visible_niveau2 = 0;

function menuBar_on(num)
{
   if (gl_menuBar_f[num] == 1)
   {
      menuBar_reset_flags();
   }
   else
   {
      gl_menuBar_f[num] = 2; // en attente.
      setTimeout("menuBar(" + num + ")", 100);
   }

   // On clear le timeout
   if (timerAllMenu)
   {
      clearTimeout(timerAllMenu);
      timerAllMenu = null;
   }
   if (timer_reveal)
   {
      clearTimeout(timer_reveal);
   }
   if (timer)
   {
      clearTimeout(timer);
      timer = null;
   }

}

function menuBar_reset_flags()
{
  //for (cpt = 0; cpt < 9; ++cpt)
    for (cpt = 0; cpt < 6; ++cpt)
      if (gl_menuBar_f[cpt] != 1)
         gl_menuBar_f[cpt] = 0;
}

function reset_menu()
{
   visible_niveau3 = 0;
}

function menuBar_all_hidden()
{
  // visible_niveau3 = 0;

   // On masque tous les sous-menus
  /*
   var elts_du_dom = document.getElementById('menuBar').getElementsByTagName('div');
   for (var i = 0; i < elts_du_dom.length ; i++)
   {
      if ((elts_du_dom[i].id).substr(0, 7) == 'level3_')
      {
         $('#'+elts_du_dom[i].id).slideUp();
         visible_niveau3 = 0;
      }
   }
   */

}


function menuBar_out(num)
{
   menuBar_reset_flags();
   visible_niveau3 = 0;
}

function menuBar(num)
{
   if (gl_menuBar_f[num] == 2)
   {
      gl_menuBar_f = new Array(0, 0, 0, 0, 0, 0);
	  // gl_menuBar_f = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
      gl_menuBar_f[num] = 1;
      var cpt;
      for (cpt = 0; cpt < 6; ++cpt)
         if (cpt != num && document.getElementById("menuBarTab_" + cpt) != null)
         {
            document.getElementById("menuBarTab_" + cpt).setAttribute("class", "tabOff_" + cpt);
            document.getElementById("menuBarTab_" + cpt).setAttribute("className", "tabOff_" + cpt);
            document.getElementById("menuBarContent_" + cpt).style.display = "none";
         }
      if (document.getElementById("menuBarTab_" + num) != null)
      {
         document.getElementById("menuBarTab_" + num).setAttribute("class", "tabOn_" + num);
         document.getElementById("menuBarTab_" + num).setAttribute("className", "tabOn_" + num);

         //if ( visible_niveau2 == 0 )
         //   $('#'+"menuBarContent_" + num).slideDown("fast");
         //else
            document.getElementById("menuBarContent_" + num).style.display = "block";

         //visible_niveau2 = 1;
      }
   }
}


/*******************************************
 **                                       **
 ** Fonction pour la gestion du Sous-Menu **
 **             Merci à CBS               **
 **                                       **
 *******************************************/
var timer = null;
var timer_reveal = null;
var timerAllMenu = null;
var slideEnCours = 0;
var menuEnCours = null;

function afficherMenu(obj)
{
   if (timer_reveal)
   {
      clearTimeout(timer_reveal);
   }
   if (timer)
   {
      clearTimeout(timer);
      timer = null;
   }
   timer_reveal = setTimeout('afficherMenuDo("' + obj +'")', 40);
}

/**
 ** Affiche le sous Menu
 ** @string obj   l'identifiant de la div du menu
 **/
function afficherMenuDo(obj)
{
   // On masque tous les sous-menus
   var elts_du_dom = document.getElementById('menuBar').getElementsByTagName('div');
   for (var i = 0; i < elts_du_dom.length ; i++)
   {
      if ((elts_du_dom[i].id).substr(0, 7) == 'level3_')
      {
         document.getElementById(elts_du_dom[i].id).style.display = 'none';
      }
   }

   // On clear le timeout
   if (timer_reveal)
   {
      clearTimeout(timer_reveal);
   }
   if (timer)
   {
      clearTimeout(timer);
      timer = null;
   }

   // On clear le timeout
   if (timerAllMenu)
   {
      clearTimeout(timerAllMenu);
      timerAllMenu = null;
   }


   // affichage du sous menu sélectionné
   var menu_layer = document.getElementById(obj);
   var menu_item = obj;

   menuEnCours = obj;

   if (!visible_niveau3)
   {
      $('#'+obj).slideDown("normal",annoncerFinSlide);
      slideEnCours = 1;
   }
   else
   {
      if (!slideEnCours)
      {
         menu_layer.style.display = 'block';
      }
   }

   visible_niveau3 = 1;
}

function annoncerFinSlide()
{
   slideEnCours = 0;
   if (menuEnCours)
   {
      afficherMenu(menuEnCours);
   }
}

/**
 ** Masque le sous Menu
 ** @string obj   l'identifiant de la div du menu
 **/
function masquerMenu(obj)
{
   var menu_layer = document.getElementById(obj);
   if (menu_layer)
   {
      $('#'+obj).slideUp();
      //menu_layer.style.display="none";
      visible_niveau3 = 0;
      menuEnCours = null;
   }
}

/**
 ** affecte le timeout de masquage du menu
 ** @string obj   l'identifiant de la div du menu
 **/
function timerMenu(obj)
{
   if (timer_reveal)
   {
      clearTimeout(timer_reveal);
   }
   if (timer)
   {
      clearTimeout(timer);
      timer = null;
   }
   timer = setTimeout('masquerMenu("' + obj +'")', 250);
}

function timerFullMenu()
{
   timerAllMenu = setTimeout('menuBar_all_hidden()', 1000);
}

