// Collapse menu by DAD - Digital Age Design (http://www.dad.be)
// Aug 01 2001
// Last version pierre@dad.be

var d = 50; //speed of the collapsing menu
var iblockN = null //Number of first level div

var increment=null
var itm_h = new Array();
var cnt_h = new Array();
var blockDiv = new Array();
var itmDiv = new Array();
var cntDiv = new Array();
var itmTotal = 0; //height of the global containers ?!
var cntTotal = 0; //height of the global containers ?!
var arrBOpen = new Array(); //Contains the open/close state of the menus
var active = false;
var sMenu = new Array();
var opened = new Array();
var num = 0; //Used by slideMenuToggle function

//tid contains a time counter (to slow down the opening or closing of menu, for nice visual effect)
tid = null; 


// _dom: 1 = Mozilla NN6, 2 = NN4, 3 = IE, 0 = others
_dom=(document.all?3:(document.getElementById?1:(document.layers?2:0)));
// _ie5: true = IE5+
_ie5=(navigator.appName.indexOf('Microsoft Internet Explorer')>=0 && parseInt(navigator.appVersion)>=5);
// _mac : true = macintosh, false = other os
_mac=navigator.userAgent.indexOf('Mac')!=-1;
//=======================================================================

function expand(n,action) { //n = div number, action = show or hidde
	arrBOpen[n]=1;dd=n
	increment=increment+1
	MM_showHideLayers('b' + n + '_item','',action)
	for(var i=0; i<iblockN-1; i++) MM_showHideLayers('b' + i + '_content','','hide')
	if (action=='hide'){MM_showHideLayers('b' + n + '_content','','show')}
	if(sMenu[n]&&!active)slideMenuToggle(n)
}

function getDivTop(div){
  if(_dom==1) return parseInt(div.style.top);
  if(_dom==2) return div.top;
  if(_dom==3) return _ie5?div.offsetTop:div.style.pixelTop;
  return 0;
}
function moveDivTo(div,left,top){
  if(_dom==1){
    div.style.left=left+'px';
    div.style.top =top +'px';
    return;
  }
  if(_dom==2){ div.moveTo(left,top); return; }
  if(_dom==3){
    div.style.pixelLeft=left;
    div.style.pixelTop =top;
    return;
  }
}
function moveDivBy(div,left,top){
  if(_dom==1){
    div.style.left=parseInt(div.style.left)+left;
    div.style.top =parseInt(div.style.top )+top;
    return;
  }
  if(_dom==2){ div.moveBy(left,top); return; }
  if(_dom==3){
    if(_ie5){
      div.style.pixelLeft=div.offsetLeft+left;
      div.style.pixelTop=div.offsetTop+top;
    } else  {
      div.style.pixelLeft+=left;
      div.style.pixelTop+=top;
    }
    return;
  }
}
function initDivSize(div){
  if(_dom==1){
    div.style.width =div.offsetWidth +'px';
    div.style.height=div.offsetHeight+'px';
    return;
  }
  if(_dom==3){
    div.style.pixelWidth =div.offsetWidth;
    div.style.pixelHeight=div.offsetHeight;
    return;
  }
}
function getDivWidth (div){ 
  if(_dom==1) return div.offsetWidth;
  if(_dom==2) return div.clip.width;
  if(_dom==3) return _ie5?div.offsetWidth:div.style.pixelWidth;
  return 0;
}
function getDivHeight(div){ 
  if(_dom==1) return div.offsetHeight;
  if(_dom==2) return div.clip.height;
  if(_dom==3) return _ie5?div.offsetHeight:div.style.pixelHeight;
  return 0;
}
function resizeDivTo(div,width,height){
  if(_dom==1){
    div.style.width =width +'px';
    div.style.height=height+'px';
    return;
  }
  if(_dom==3){
    div.style.pixelWidth =width;
    div.style.pixelHeight=height;
    return;
  }
  if(_dom==2){
    div.resizeTo(width,height);
    return;
  }
}
function setDivVisibility(div,visible){
  if(_dom==2){ div.visibility=(visible)?'inherit':'hide'; return; }
  if(_dom==1 || _dom==3){
    div.style.visibility=(visible)?'inherit':'hidden';
    return;
  }
}
if(_dom==1){
  document.write(
     '<style type="text/css">\n'
    +'.item{ padding:0px; }\n' // valeur par defaut 1px : probleme avec NN6
    +'<\/style>'
  );
}

function SlideMenu(div,d){
  this.div = div; 
  this.d = d;
}

SlideMenu.prototype.open = function(k){

  var div = this.div;
  this.dx = 0; this.dy = this.d;
  if( getDivTop(div)<(itm_h[k]+cnt_h[k])-this.d && !opened[k]){  
		moveDivBy(div,this.dx,this.dy);
		return false;
  }else{
    moveDivTo(div,0,itm_h[k]+cnt_h[k]); 
   	opened[k] = true; active = false;
			// definition de la valeur de la variable 'increment' en fonction de l'item
			if (increment == 2 && dd!=activ_menu){
				increment=1
				MM_showHideLayers('b'+activ_menu+'_item','','show') // ferme le folder actif si un autre item est ouvert
				slideMenuToggle(activ_menu) // deroule ou referme l'item actif si autre item ouvert
			}
    return true;
  }
}

SlideMenu.prototype.close = function(k){
  var div = this.div;
  this.dx = 0; this.dy =-this.d;
  if(getDivTop(div)>(itm_h[k]+this.d) && opened[k]){  
    moveDivBy(div,this.dx,this.dy);
		return false;
  }else{
    moveDivTo(div,0,itm_h[k]);
    opened[k] = false; active = false;
    return true;
  }
}

/* ______________________________________________________________________________________________________________ */

function slideMenuToggle(j){
	if (increment == 1){
		for (i=0;i<iblockN;i++){
			if (arrBOpen[i]==1){
				arrBOpen[i]=0; activ_menu=i;
			}
		}		
	}

	if (increment >= 2 && dd==activ_menu){
		for (i=0;i<iblockN;i++){
			if (arrBOpen[i]==1) {
				arrBOpen[i]=0; activ_menu=i;
			}
		}
		increment=0
		dd=null
   }
	 
 		active = true;
 		num = j;
		
 		if(!opened[num]){
   		if(!sMenu[num].open(num)) tid = setTimeout('slideMenuToggle(num)',d);
 		} else { 
			if(!sMenu[num].close(num)) tid = setTimeout('slideMenuToggle(num)',d);
		}
}


/* ______________________________________________________________________________________________________________ */

//Get pointer to layer
function getCoDivFromName(nm,id,c){
 if(_dom==2){
  if(arguments.length>1){
   var s='';
   switch(c){
    case 0: for(var i=0; i<=id; i++) s+='document.layers.'+'b'+i+'.'; break;    
    case 1: for(var i=0; i<id; i++)  s+='document.layers.'+'b'+i+'.'; break;
   }
   return eval(s+'document.layers.'+nm);
  } 
  else{ return eval('document.layers.'+nm); }
 } 
 else if(_dom==1){ return document.getElementById(nm); }
 else if(_dom==3){ return _ie5?document.getElementById(nm):document.all(nm); }
 return null;
}
/* ______________________________________________________________________________________________________________ */

function init(a_iblockN){
		iblockN = a_iblockN;
		//Initialise the opened/closed state array
		for (i=0;i<iblockN;i++){
			arrBOpen[i]=0;
		}		
	 for(var i=0; i<iblockN-1; i++){
	  itmDiv[i] = getCoDivFromName('b'+i+'_item',i,0);
	  initDivSize(itmDiv[i]); itm_h[i] = getDivHeight(itmDiv[i]);
	  itmTotal+=itm_h[i]; 
	  cntDiv[i] = getCoDivFromName('b'+i+'_content',i,0);
	  initDivSize(cntDiv[i]); cnt_h[i] = getDivHeight(cntDiv[i]); 
	  cntTotal+=cnt_h[i];
	  moveDivTo(cntDiv[i],null,itm_h[i]);
	 }
	 blockDiv[0] = getCoDivFromName('b0');
	 initDivSize(blockDiv[0]);  
	 mw =(_dom==1)?null:getDivWidth(blockDiv[0]);
	 resizeDivTo(blockDiv[0],mw,itmTotal+cntTotal);
	 for(var i=1; i<=iblockN-1; i++){
	  blockDiv[i] = getCoDivFromName('b'+i,i,1);  
	  moveDivTo(blockDiv[i],null,itm_h[i-1]);
	  resizeDivTo(blockDiv[i],mw,itmTotal+cntTotal-getDivTop(blockDiv[i]));
	 } 
	 setDivVisibility(blockDiv[0],true);
	 for(var i=0; i<iblockN-1; i++) sMenu[i] = new SlideMenu(blockDiv[i+1],d);
	 for(var i=0; i<iblockN-1; i++) MM_showHideLayers('b' + i + '_content','','hide')
}

/* ______________________________________________________________________________________________________________ */

function cancel(){ 
  if(tid){ clearTimeout(tid); tid=null; }
}
/* ______________________________________________________________________________________________________________ */

/* ------------------------------------------------------------
	MM_findObj and MM_showHideLayers, used to show and hide
	opened and closed layers
	 ------------------------------------------------------------ */ 
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
/* ______________________________________________________________________________________________________________ */

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
/* ______________________________________________________________________________________________________________ */

// Reloads the window if Nav4 resized
function MM_reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
/* ______________________________________________________________________________________________________________ */

MM_reloadPage(true);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                