/*********************/
/*        TODO       */
/*********************/

//Display step != 1
//Apparition des separations ?

//Needed by some functions
var menu_state = new Array();
var menu_decalage = new Array();
var timeout_handle;
//Time intervall between callback during animation
var menu_timeout_intervall = 10;
//Time intervall between callback during animation
var menu_button_height = 21;
//Pixel deplacement on each callback
var menu_display_delta = 4;
//Menu management :
//  0: User choose
//  1: Open/Close at same time
//  2: Close then Open
var menu_close_before_opening = 0;



function mouse_event()
{
  var i, id, nsmenu, step, delta_interval;
  step = 1;
  delta_interval = 10;
  id = this.id.substr(4, this.id.length - 1);
  if (menu_close_before_opening != 0)
  {
    for(i=0;i<menu_state.length;i++)
      menu_state[i] = 0;
  }
  menu_state[id-1] = !menu_state[id-1];
  for(i=0;i<menu_state.length;i++)
  {
    if (menu_state[i] == 0)
    {
        document.getElementById('menu' + (i+1)).className = 'menu_p';
    }
    else
    {
        document.getElementById('menu' + (i+1)).className = 'menu_p_selected';
    }
  }

  clearTimeout(timeout_handle);
  timeout_handle = setTimeout('menu_animation()', menu_timeout_intervall);
}

function menu_ret_false()
{
  return false;
}

function hover_item()
{
  this.style.color = 'orange';
  var i, id, nsmenu, step, delta_interval;
  step = 1;
  delta_interval = 10;
  id = this.id.substr(4, this.id.length - 5);
  if (menu_close_before_opening != 0)
  {
    for(i=0;i<menu_state.length;i++)
      menu_state[i] = 0;
  }
  menu_state[id-1] = 1;
   for(i=0;i<menu_state.length;i++)
  {
    if (menu_state[i] == 0)
    {
        document.getElementById('menu' + (i+1)).className = 'menu_p';
    }
    else
    {
        document.getElementById('menu' + (i+1)).className = 'menu_p_selected';
    }
  }

  clearTimeout(timeout_handle);
  timeout_handle = setTimeout('menu_animation()', menu_timeout_intervall);
}

function hover_item_out()
{
  this.style.color = 'white';
  var i, id, nsmenu, step, delta_interval;
  step = 1;
  delta_interval = 10;
  id = this.id.substr(4, this.id.length - 5);
  if (menu_close_before_opening != 0)
  {
    for(i=0;i<menu_state.length;i++)
      menu_state[i] = 0;
  }
  menu_state[id-1] = 0;
  for(i=0;i<menu_state.length;i++)
  {
    if (menu_state[i] == 0)
    {
        document.getElementById('menu' + (i+1)).className = 'menu_p_selected';
    }
    else
    {
        document.getElementById('menu' + (i+1)).className = 'menu_p_selected';
    }
  }

  clearTimeout(timeout_handle);
  timeout_handle = setTimeout('menu_animation()', menu_timeout_intervall);
}

function menu_init()
{
  menu_state = new Array();
  menu_decalage = new Array();
  var i, j, nmenu, nsmenu;
  mmenu = menu_get_menu_p_number();
  for(i=1;i<menu_get_menu_p_number()+1; i++)
  {
    menu_state.push(0);
    menu_decalage.push(0)
    menu_state[i-1] = 0;
    menu_decalage[i-1] = 0;
    msmenu = menu_get_menu_s_number(i);
    document.getElementById('menu' + i).style.zIndex = msmenu;
    document.getElementById('menu' + i).onmouseover = mouse_event;
    document.getElementById('menu' + i).onmouseout = mouse_event;
    document.getElementById('menu' + i).onmousedown = menu_ret_false;
    for(j=1;j<menu_get_menu_s_number(i)+1;j++)
    {
      document.getElementById('menu' + i + j).style.left = 144 * (i-1);
      document.getElementById('menu' + i + j).onmouseover = hover_item;
      document.getElementById('menu' + i + j).onmouseout = hover_item_out;
      document.getElementById('menu' + i + j).style.zindex = msmenu - j;
    }
  } 
  menu_redraw();
}

function menu_get_menu_p_number()
{
  var i;
  i = 1;
  while(document.getElementById('menu' + i)) { i++; };
  return (i - 1);
}

function menu_get_menu_s_number(i)
{
  var j;
  j = 1;
  while(document.getElementById('menu' + i + j)) { j++; };
  return (j - 1);
}      

