var MOZ = (navigator.appName=="Netscape")&&(!document.layers);
var bloaded = false; // permet de lancer les scripts après chargement du dernier élément de la page
var _onresize = "function(){ bloaded = false; window.setTimeout('bloaded = true;', 100);";
var _onload = "function(){ ";
var IE501 = (navigator.appVersion.indexOf("5.01")>=0);
var selcheck = ((document.all)&&(!IE501));
var scol = 1;
var TMPO_arr = new Array();
TMPO_arr[0] = 250; // temporisation menu haut
TMPO_arr[1] = 1000; // temporisation menu gauche

function init_menu(mid, mtype, rtype){ // ajout de rtype pour gestion du déclenchement rollover (0) ou click (1)
 var mobj = document.getElementById(mid); 
 mobj.cura = null;
 mobj.mtype = mtype;
 mobj.placed = 0;
 mobj.TMPO = TMPO_arr[mtype];
 mobj.tm = 0;
 var mobjacol = mobj.getElementsByTagName("A");
 var dchld = null;
 
 for(a=0;a<mobjacol.length;a++){
  aobj = mobjacol[a];
  lobj = aobj.parentNode.parentNode.parentNode.parentNode;
  if(lobj.id!=mid){
   aobj.dprt = dchld;
   aobj.lobj = lobj.parentNode.parentNode.parentNode;

   aobj.onmouseup = function(){
    this.blur();
   }

   continue;
  }

  dchld = aobj.chld = aobj.parentNode.parentNode.getElementsByTagName("DIV")[0];

  if((selcheck==1)&&(dchld!=null)){
   dchld.ifr = aobj.ifr = document.createElement("IFRAME");
   dchld.ifr.src = aobj.ifr.src = "javascript:false";
   aobj.ifr.frameBorder = 0;
   aobj.appendChild(aobj.ifr);
  }

  aobj.prt = mobj;
  if(aobj.chld!=null)
   aobj.chld.prt = mobj;
  aobj.refclass = aobj.className;

  if(aobj.refclass=='')
   aobj.refclass = 'off';

   aobj.onmouseover = function(){
    if(this.prt.cura!=null){
     if(this.prt.cura==this){
      if(this.prt.tmo)
       window.clearTimeout(this.prt.tmo);
      this.prt.tm = 0;
     }
    }
   }
   
   aobj.mshow = function(){
    if(this.prt.tmo)
     window.clearTimeout(this.prt.tmo);
    this.prt.tm = 0;
    if(this.prt.cura!=null){
     if(this.prt.cura==this)
      return;
    }
   }

   if(rtype){
   aobj.onclick = function(){
   	if(!this.prt.placed)
   	 place_menu(this.prt.id);
    if(this.prt.tmo)
     window.clearTimeout(this.prt.tmo);
    this.prt.tm = 0;
	if(this.prt.cura!=null){
	 if(this.prt.cura==this)
	  return;
	 else
	  this.prt.cura.mhide();
     }
    this.prt.cura = this;
    this.className = 'on';
    if(this.chld!=null){
     if(selcheck==0)
      show_select_col(0);
     else if(selcheck==1)
      this.ifr.style.visibility = 'visible';
     this.chld.style.visibility = 'visible';
    }
    return false;
   }
  }

  if(aobj.chld!=null){
   aobj.chld.onmouseover = function(){
    this.prt.tm = 0;
   }
  }

  aobj.onmouseup = function(){
   this.blur();
  }

  aobj.onmouseout = function(){
   if(this.prt.cura!=null){
   	if(this.prt.cura==this){
     this.prt.tm = 1;
     this.prt.tmo = window.setTimeout("tm_mhide('"+this.prt.id+"')", this.prt.TMPO);
    }
   }
  }
  
  if(aobj.chld!=null){
   aobj.chld.onmouseover = function(){
    if(this.prt.tmo)
     window.clearTimeout(this.prt.tmo);
    this.prt.tm = 0;
   }

   aobj.chld.onmouseout = function(){
    this.prt.tm = 1;
    this.prt.tmo = window.setTimeout("tm_mhide('"+this.prt.id+"')", this.prt.TMPO);
   }
  }

  aobj.mhide = function(){
   if(this.chld!=null){
     if(selcheck==0)
      show_select_col(1);
     else if(selcheck==1)
      this.ifr.style.visibility = 'hidden';
     this.chld.style.visibility = 'hidden';
    if(this.chld.cura!=null)
     this.chld.cura.dmhide();
   }
   this.className = this.refclass;
  }
 }
 adjust_widths(mid);
}

function show_select_col(v){
 if(scol==1)
  scol = document.getElementsByTagName("SELECT");
 for(i=0;i<scol.length;i++){
  if(scol[i].refv==null)
   scol[i].refv = scol[i].style.visibility; 
  scol[i].style.visibility = (v)?'visible':'hidden';
 }
}
 
function tm_mhide(mid){
 mobj = document.getElementById(mid);
 if(mobj.tm==0)
  return;
 if(mobj.cura!=null)
  mobj.cura.mhide();
 mobj.cura = null;
 mobj.tm = 0;
 mobj.tmo = null;
}

function adjust_widths(mid){
 var mobj = document.getElementById(mid);
 mobjdcol = mobj.getElementsByTagName("DIV");
 if(selcheck==1)
  mobjifrcol = mobj.getElementsByTagName("IFRAME");
 brdw = ((document.compatMode)?0:2); // 2 correspond à la largeur totale de la bordure gauche + droite des blocs "DIV" et est indispensable pour obtenir une apparence similaire sous IE5.x et 6
 for(d=0;d<mobjdcol.length;d++){
  dulcol = mobjdcol[d].getElementsByTagName("UL");
  dulcol[dulcol.length-1].style.border = 'none';
  if(!MOZ)
   dulcol[dulcol.length-1].style.marginRight = '-3px';
  mobjdcol[d].style.width = dulcol.length * parseInt(dulcol[0].offsetWidth) - (2*(dulcol.length)) + brdw + 'px';
  if(selcheck==1){
   mobjifrcol[d].style.width = parseInt(mobjdcol[d].style.width) + 'px';
   mobjifrcol[d].style.height = parseInt(mobjdcol[d].clientHeight) + 1 + 'px';
  }
 } 
}
 
function place_menu(mid){
 var mobj = document.getElementById(mid);
 var mtype = mobj.mtype;
 var mobjdcol = mobj.getElementsByTagName("DIV");
 if(selcheck==1)
  mobjifrcol = mobj.getElementsByTagName("IFRAME");
 for(d=0;d<mobjdcol.length;d++){
  mobjdcol[d].style.left = mobjdcol[d].style.top ='0px';
  if((selcheck==1)&&(mobjdcol[d].ifr!=null)){
   mobjifrcol[d].style.left = mobjifrcol[d].style.top = '0px';
  }
 }

 refobj = document.getElementById("maiInfomenu");
 rright = parseInt(refobj.offsetWidth) + parseInt(refobj.offsetLeft);
 // - 16*(document.body.scrollHeight>0)
 if(MOZ){
  rbot = Math.max(parseInt(refobj.offsetHeight), parseInt(window.innerHeight));
 }
 else {
  if (document.compatMode)
   rbot = Math.max(parseInt(document.body.clientHeight), parseInt(document.documentElement.offsetHeight) - 4);
  else
   rbot = Math.max(parseInt(document.body.clientHeight), parseInt(document.body.scrollHeight));
 }

 for(d=0;d<mobjdcol.length;d++){
  dobj = mobjdcol[d];
  if(selcheck==1)
   ifrobj = mobjifrcol[d];

  aref = dobj.parentNode.getElementsByTagName("A")[0];

  var ard = findxy(aref);
  switch(mtype){
   case 0:
   dobj.style.top = ard.y + parseInt(aref.offsetHeight) - ((MOZ)?0:(parseInt(document.getElementById("maiInfomenu").offsetTop))) + 'px';
   nleft = ard.x- ((MOZ)?0:(parseInt(document.getElementById("maiInfomenu").offsetLeft)));
/*   nwidth = parseInt(dobj.offsetWidth);
   nright = nleft + nwidth;
   if(nright>rright)
    dobj.style.left = rright - nwidth + 'px';
   else*/
    dobj.style.left = nleft + 'px';
   if(!MOZ&&dobj.parentNode.className=="myaccount"){
    dobj.style.left = parseInt(dobj.style.left) - parseInt(dobj.parentNode.offsetLeft) + 'px';
    dobj.style.top = parseInt(dobj.style.top) - parseInt(dobj.parentNode.offsetTop) + 'px';
   }
   break;
   case 1:
   dobj.style.left = ard.x + parseInt(aref.offsetWidth) + 'px';
   ntop = ard.y - ((MOZ)?1:0);
/*   nheight = parseInt(dobj.offsetHeight);
   nbot = ntop + nheight;
   if(nbot>rbot)
    dobj.style.top = rbot - nheight + 'px';
   else*/
    dobj.style.top = ntop - ((MOZ)?0:(parseInt(document.getElementById("maiInfomenu").offsetTop) + 1)) + 'px';
   break;
  }
  if((selcheck==1)&&(mobjifrcol[d]!=null)){
   ifrobj.style.left = dobj.style.left;
   ifrobj.style.top = dobj.style.top;
  }
 }
 mobj.placed = 1;
}
 
function findxy(o){
 rd = {x:0, y:0};
 rd.x += parseInt(o.offsetLeft);
 rd.y += parseInt(o.offsetTop);
 if(MOZ)
  return rd;
 while (o=o.offsetParent){
  rd.x += parseInt(o.offsetLeft);
  rd.y += parseInt(o.offsetTop);
 }
 return rd;
}

