// Créé par Nicolas LEVIEIL pour la CRE - Studio SQLI 01/2007

/* import css menu */
document.write('<'+'link rel="stylesheet" type="text/css" media="all" href="stylesheets/menu.css"/>');

var IE = (document.all)?1:0;
var SAF = (navigator.userAgent.toLowerCase().indexOf('safari')>=0);
var MAC = (navigator.appVersion.indexOf("Mac") != -1);
var MACIE = (IE&&MAC);
var MOZ = (navigator.appName=="Netscape")&&(!document.layers);
var mobj = null, thedge = null, stpos = null, curd = new Array(), curli = new Array(), licol = new Array(), nb = new Array(), pv = 0;
var baseright = 0;
var selectcol = null;
var SAFload = 1;
var chldimg = null;

/* Navigation 1 */
function init_menu(img){
 chldimg = document.createElement("IMG");
 chldimg.src = img;
 if(SAF&&SAFload){
  SAFload = 0;
  window.setTimeout("init_menu(img)", 100);
 }
 curd[0] = document.getElementById("menu");
 stpos = curd[0].offsetParent;
 curd[pv].onmouseover = tm_clear;
 curd[pv].onmouseout = tm_hide;
 curd[pv].clickhide = clickhide;
 if(pv>0){
  curli[pv-1].coo = findxy(curli[pv-1]);
  curd[pv].be = curli[pv-1];
  curli[pv-1].lievt.chld = curd[pv];
  if(pv==1){
   curd[pv].style.left = curli[pv-1].coo.x + 'px';
   curd[pv].style.top = curli[pv-1].coo.y + 20 + 'px';
  }
  else {
   curd[pv].style.left = parseInt(curli[pv-1].offsetWidth) + 'px';
   curd[pv].style.top = parseInt(curli[pv-1].offsetTop) + 'px';
   curli[pv-1].getElementsByTagName("A")[0].appendChild(chldimg);
  }
 }
 if(!MACIE)
  curd[pv].style.display = "block";
 if(pv==1){
  baseleft = parseInt(curli[pv-1].coo.x);
  thew = parseInt(curd[pv].getElementsByTagName("A")[0].offsetWidth);
  redge = baseleft + thew - baseright;
  if(redge>=0)
   curd[pv].style.left = baseright - thew - ((MOZ)?2:0) + 'px';
 }
 if(pv==2){
  baseleft = parseInt(curd[pv-1].style.left) + parseInt(curli[pv-1].offsetWidth);
  thew = parseInt(curd[pv].getElementsByTagName("A")[0].offsetWidth) + 2;
  redge = baseleft + thew - baseright;
  if(redge>=0)
   curd[pv].style.marginLeft = - parseInt(curli[pv-1].offsetWidth) - thew + 'px';
 }
 else
  baseright = curd[0].offsetWidth;
 licol[pv] = curd[pv].getElementsByTagName("LI");
 nb[pv] = 0;
 while(nb[pv]<licol[pv].length){
  if(licol[pv][nb[pv]++].parentNode.parentNode!=curd[pv])
   continue;
  curli[pv] = licol[pv][nb[pv]-1];
  curli[pv].lnko = curli[pv].getElementsByTagName("A").item(0);
  curli[pv].lievt = (pv==0)?curli[pv].lnko:curli[pv];
  curli[pv].lievt.lnk = curli[pv].lnko.href;
  curli[pv].lievt.linkable = (curli[pv].lievt.lnk.substring(curli[pv].lievt.lnk.length-1, curli[pv].lievt.lnk.length)!="#");
  curli[pv].lievt.fclass = curli[pv].lievt.className;
  curli[pv].lievt.be = curd[pv];
  curli[pv].lievt.be.last = curli[pv].lievt;
  curli[pv].lievt._show = m_show;
  curli[pv].lievt._hide = m_hide;
  curli[pv].lnko.prt = curli[pv].lievt;
  if(pv==0){
   curli[pv].lievt.onmouseover = curli[pv].lievt.f_mover = function(){ tm_hclear(); this.be.last = this._show();}
  }
  else{
   curli[pv].lievt.onmouseover = curli[pv].lievt.f_mover = function(){ this.be.last = this._show();}
   if(!IE)
    curd[pv].style.width = curd[pv].getElementsByTagName("A")[0].offsetWidth + 'px';
  }
//  curli[pv].lnko.onfocus = function(){ this.prt.f_mover(); this.className = 'on';}
  curli[pv].lnko.tm_khide = tm_khide;
//  curli[pv].lnko.onblur = function(){ this.tm_khide();}
  
  curli[pv].lievt._go = _go;
  curli[pv].lievt.onclick = function(){ this.blur(); return this._go();}
  	
  if(MACIE)
   curd[pv].style.display = "block";
  if(curli[pv].getElementsByTagName("DIV").length>0){
   curd[pv+1] = curli[pv++].getElementsByTagName("DIV").item(0);
   init_menu(img);
   pv--;
  }
 }
}

function m_show(){
 if(document.all){
  if(selectcol==null)
    selectcol = document.getElementsByTagName('SELECT');
  for(i=0;i<selectcol.length;i++)
    selectcol[i].style.visibility = 'hidden';
 }
 this.be.last._hide();
 this.className = "on";
 if(this.chld){
  this.childNodes[0].className = "on";
  this.chld.style.visibility = 'visible';
 }
 return this;
}

function m_hide(){
 if(this.chld){
  this.childNodes[0].className = "off";
  this.chld.style.visibility = 'hidden';
  this.chld.last._hide();
 }
 this.className = this.fclass;
}

function tm_khide(){
 this.className = 'off';
/* thedge = this.prt.be.last;
 window.setTimeout('hide(thedge)', 100);*/
}

function clickhide(){
  thedge = this.last;
  hide(thedge);
}

function tm_hide(e){
  if(IE){
   if(this.contains(event.toElement))
    return;
  }
	else if(e){
   if(e.relatedTarget!=null){
	   if(e.relatedTarget.tagName!="BODY"){
	    trgt = (e.relatedTarget.nodeType!=1)?e.relatedTarget.parentNode:e.relatedTarget;

	    while(trgt.tagName!="DIV")
	     trgt = trgt.parentNode;
	    if(trgt.be){
	     if(trgt.be.lievt.chld==trgt)
	      return;
	    }
 	  }
 	 }
  }
  thedge = this.last;
  window.setTimeout('hide(thedge)', 10);
}

function tm_clear(){
 if(IE){
  if(this.contains(event.fromElement))
   return;
 }
 if(thedge==null)
  return;
 if(this.be!=thedge)
  thedge._hide();
 thedge = null;
}

function tm_hclear(){
 if(thedge!=null)
  hide(thedge);
 thedge = null;
}

function hide(o){
 if(o!=null)
  o._hide();
 if(document.all){
  if(selectcol!=null){
   for(i=0;i<selectcol.length;i++){
    selectcol[i].style.visibility = 'visible';
   }
   selectcol = null;
  }
 }
}

function findxy(o) {
 rd = {x:0, y:0};
 rd.x += o.offsetLeft;
 rd.y += o.offsetTop;
 if(MOZ||SAF)
  return rd;
 while ((o=o.offsetParent)&&(o.offsetParent!=stpos)){
  rd.x += o.offsetLeft;
  rd.y += o.offsetTop;
 }
 return rd;
}

function _go(){
 // lien # inactif
 if(this.lnk.indexOf('#')==(this.lnk.length-1))
  return false;
 document.location.href = this.lnk;
 return true;
}
