//*** objet menuObj
function menuObj(niveau,offsetIndex){
	if (typeof niveau=="undefined") niveau=0;
	if (typeof offsetIndex=="undefined") offsetIndex=0;

	//*** propriétés
	this.niveau=niveau;
	this.offsetIndex=offsetIndex;

	this.mtab=new Array();
	this.layerObj=0;
	this.itemsCreated=0;
	this.storeIndex=-1;

	this.menuTop=144;
	this.goneUp=0;
	
	this.itemHeight=26;
	if (this.niveau==0) this.menuWidth=130;
		else if (this.niveau==1) this.menuWidth=152;
		else if (this.niveau==2) this.menuWidth=202;
	if (this.niveau==0) this.menuLeft=0;
		else if (this.niveau==1) this.menuLeft=129;
		else if (this.niveau==2) this.menuLeft=280;
	if (this.niveau==0) this.itemBgColor="#BFD1E6";
		else if (this.niveau==1) this.itemBgColor="#E2EAF3";
		else if (this.niveau==2) this.itemBgColor="#F0F4F9";
	
	//*** méthodes
	this.ai=menu_add_item;
	this.make_layer=menu_make_layer;
	this.createItems=menu_createItems;
	this.makeItem=menu_makeItem;
	this.showMenu=menu_showMenu;
	this.hideMenu=menu_hideMenu;
	this.highLightItem=menu_highLightItem;
	this.unHighLight=menu_unHighLight;
	this.fixTop=menu_fixTop;
	
	//*** initialisations
	menuObj_store[menuObj_store.length]=this;
	this.storeIndex=menuObj_store.length-1;
	this.make_layer();
}

//*** Objet itemObj
function itemObj(niveau,titre,url)
{
	//*** propriétés
	this.niveau=niveau;
	this.titre=titre;
	this.url=url;

	this.childMenu=0;
	this.bgLayer=0;
	this.eventLayer=0;
}

//*** fonction pour menuObj : lors de l'initialisation, crée tous les objets menu
function menu_add_item(niveau,titre,url)
{
	if(niveau==this.niveau){
		this.mtab[this.mtab.length]=new itemObj(niveau,titre,url);
		
	}else if(this.niveau-niveau==-1){
		index=this.mtab.length-1;
		if (this.mtab[index].childMenu==0) 
			this.mtab[index].childMenu=new menuObj(niveau,index);
		this.mtab[index].childMenu.ai(niveau,titre,url);
		
	}else if(this.niveau-niveau==-2){
		index1=this.mtab.length-1;
		index2=this.mtab[index1].childMenu.mtab.length-1;
		if (this.mtab[index1].childMenu.mtab[index2].childMenu==0)
			this.mtab[index1].childMenu.mtab[index2].childMenu=new menuObj(niveau,index1+index2);
		this.mtab[index1].childMenu.mtab[index2].childMenu.ai(niveau,titre,url);
	}
}

//*** fonction pour menuObj : fabrication du calque
function menu_make_layer()
{
	layerClass='menu'+this.niveau;

	if (document.layers){//*** Nav4
		this.layerObj=new Layer(this.menuWidth);
		with (this.layerObj){
			left=this.menuLeft;
			top=this.menuTop;
		}

	}else if (document.all){//*** IE
		layerName='menu_'+this.storeIndex;
		layerHtml='<div id="'+layerName+'" class="'+layerClass+'"></div>';
		document.body.insertAdjacentHTML("BeforeEnd",layerHtml);
		this.layerObj='document.all.'+layerName;
		myLayerObj=eval(this.layerObj);
		myLayerObj.style.visibility="hidden";
		
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		layerName='menu_'+this.storeIndex;
		layerHtml='<div id="'+layerName+'" class="'+layerClass+'"></div>';

		temp = document.body.ownerDocument.createRange();
		temp.setStartBefore(document.body);
		mylayerObj = temp.createContextualFragment(layerHtml);
		document.body.appendChild(mylayerObj);

		this.layerObj=document.getElementById(layerName);
		this.layerObj.style.visibility="hidden";
	}
}

//*** fonction pour menuObj : fabrication des éléments
function menu_createItems()
{
	//*** ajustement du fond
	totalHeigth=(this.itemHeight+1)*this.mtab.length+1;
	oldTop=this.menuTop;
	this.menuTop-=this.goneUp
	//if(this.niveau!=0) this.fixTop();//*** position verticale
	
	if (document.layers){//** nav4
		with (this.layerObj){
			bgColor="#000000";
			clip.height=totalHeigth;
			clip.width=this.menuWidth;
			myHtmlIn='<font face="Arial" size="1" color="#000000">';
			myHtmlOut='</font>';
		}
		
	}else if (document.all){//*** IE
		myLayerObj=eval(this.layerObj);
		with (myLayerObj){
			style.height=totalHeigth;
			style.visibility='hidden';
			myHtmlIn='<span class="item_off">';
			myHtmlOut='</span>';
		}
		
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		with (this.layerObj){
			style.height=totalHeigth;
			style.visibility='hidden';
			myHtmlIn='<span class="item_off">';
			myHtmlOut='</span>';
		}
	}
		
	//*** création des éléments
	for (i=0;i<this.mtab.length;i++){
		myHtml=myHtmlIn+this.mtab[i].titre+myHtmlOut;
		myUrl=this.mtab[i].url;
		myTop=(this.itemHeight+1)*i+1;
		myChildStoreIndex=(this.mtab[i].childMenu!=0)?this.mtab[i].childMenu.storeIndex:-1;
		this.makeItem(this.layerObj,1,myTop,myHtml,myUrl,i,myChildStoreIndex,this.storeIndex,this.niveau);
		
		//*** remonter les enfants si menu a été remonté
		if(myChildStoreIndex!=-1){
			this.mtab[i].childMenu.fixTop(this.goneUp);//*** position verticale
		}
	}

	this.itemsCreated=1;
}

function menu_fixTop(parentGoneUp)
{
	myTop=this.menuTop+((this.itemHeight+1)*(this.offsetIndex))-parentGoneUp;
	totalHeigth=(this.itemHeight+1)*this.mtab.length+1;
	myBottom=myTop+totalHeigth;
	
	if (document.layers){//*** Nav4
		windowHeight=window.innerHeight;
	}else if (document.all){//*** IE
		windowHeight=document.body.clientHeight;
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		windowHeight=window.innerHeight;
	}

	if(myBottom>windowHeight){//*** remonter si trop bas
		oldTop=myTop;
		myTop=windowHeight-totalHeigth;
		this.goneUp=oldTop-myTop;
	}
	
	if (document.layers){//*** Nav4
			this.layerObj.top=myTop;
	}else if (document.all){//*** IE
		myLayerObj=eval(this.layerObj);
		myLayerObj.style.top=myTop;
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		this.layerObj.style.top=myTop-12;
	}
	
	this.menuTop=myTop;
}

function menu_makeItem(myParent,myLeft,myTop,myHtml,myUrl,myIndex,myChildStoreIndex,myMenuStoreIndex,myNiveau)
{
	if(myUrl.substr(0, 6)=='blank:'){
		myUrl=myUrl.substr(6);
		myTarget='target="_blank" ';
	}else{
		myTarget='';
	}
	
	if (document.layers){//*** nav4
		//*** calque de contenu
		calk=new Layer(this.menuWidth-2,this.layerObj);
		this.mtab[myIndex].bgLayer=calk;
		with (calk){
			bgColor = this.itemBgColor;
			visibility = "inherit";
			left = myLeft;
			top = myTop;
			clip.width=this.menuWidth-2;
			clip.height=this.itemHeight;
			document.open();
			document.write(myHtml);
			document.close();
		}

		//*** calque d'évenement
		htmlStr='<a href="'+myUrl+'" '+myTarget;
		htmlStr+='onmouseover="event_item_over('+myChildStoreIndex+','+myMenuStoreIndex+','+myNiveau+',\''+calk.name+'\',\''+this.itemBgColor+'\','+myIndex+');">';
		htmlStr+='<img src="../../images/shim_transparent.gif" width="'+this.menuWidth+'" height="26" border="0" alt=""></a>';	
		ecalk=new Layer(this.menuWidth-2,this.layerObj);
		with (ecalk){
			visibility = "inherit";
			left = myLeft;
			top = myTop;
			document.open();
			document.write(htmlStr);
			document.close();
		}

	}else if (document.all){//*** IE

		//*** calque de contenu
		myCalkName='mi_'+myMenuStoreIndex+'_'+myIndex;
		myParent=eval(this.layerObj);
		htmlStr='<div id="'+myCalkName+'" style="position: absolute">';
		htmlStr+='';
		htmlStr+=myHtml;
		htmlStr+='</div>';

		myParent.insertAdjacentHTML("beforeEnd",htmlStr);
		calk=myParent.all(myCalkName);
		this.mtab[myIndex].bgLayer='document.all.'+myCalkName;
		with (calk.style){
			backgroundColor = this.itemBgColor;
			visibility = "inherit";
			width = this.menuWidth-2;
			left = myLeft;
			clip="rect (0 "+this.menuWidth+" "+(this.itemHeight)+" 0)";
			height=this.itemHeight;
			top = myTop;
		}

		//*** calque d'évenement
		myCalkName2='mio_'+myMenuStoreIndex+'_'+myIndex;
		htmlStr='<div id="'+myCalkName2+'" style="position: absolute">';
		htmlStr+='<a href="'+myUrl+'" ';
		htmlStr+='onmouseover="event_item_over('+myChildStoreIndex+','+myMenuStoreIndex+','+myNiveau+',\''+myCalkName+'\',\''+this.itemBgColor+'\','+myIndex+');">';
		htmlStr+='<img src="../../images/shim_transparent.gif" width="'+(this.menuWidth-2)+'" height="'+(this.itemHeight)+'" border="0" alt=""></a>';	
		htmlStr+='</div>';

		myParent.insertAdjacentHTML("beforeEnd",htmlStr);
		calk=myParent.all(myCalkName2);
		with (calk.style){
			visibility = "inherit";
			left = myLeft;
			top = myTop;
		}
		
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6

		//*** calque de contenu
		myCalkName='mi_'+myMenuStoreIndex+'_'+myIndex;
		//myParent=eval(this.layerObj);
		myParent=this.layerObj;
		
		htmlStr='<div id="'+myCalkName+'" style="position: absolute">';
		htmlStr+='';
		htmlStr+=myHtml;
		htmlStr+='</div>';

		//myParent.insertAdjacentHTML("beforeEnd",htmlStr);
		temp = myParent.ownerDocument.createRange();
		temp.setStartBefore(myParent);
		mylayerObj = temp.createContextualFragment(htmlStr);
		myParent.appendChild(mylayerObj);


		//calk=myParent.all(myCalkName);
		calk=document.getElementById(myCalkName);
		
		//this.mtab[myIndex].bgLayer='document.all.'+myCalkName;
		this.mtab[myIndex].bgLayer=document.getElementById(myCalkName);
		
		with (calk.style){
			backgroundColor = this.itemBgColor;
			visibility = "inherit";
			width = this.menuWidth-2;
			left = myLeft;
			clip="rect (0 "+this.menuWidth+" "+(this.itemHeight)+" 0)";
			height=this.itemHeight;
			top = myTop;
		}

		//*** calque d'évenement
		myCalkName2='mio_'+myMenuStoreIndex+'_'+myIndex;
		htmlStr='<div id="'+myCalkName2+'" style="position: absolute">';
		htmlStr+='<a href="'+myUrl+'" ';
		htmlStr+='onmouseover="event_item_over('+myChildStoreIndex+','+myMenuStoreIndex+','+myNiveau+',\''+myCalkName+'\',\''+this.itemBgColor+'\','+myIndex+');">';
		htmlStr+='<img src="../../images/shim_transparent.gif" width="'+(this.menuWidth-2)+'" height="'+(this.itemHeight)+'" border="0" alt=""></a>';	
		htmlStr+='</div>';

		//myParent.insertAdjacentHTML("beforeEnd",htmlStr);
		temp = myParent.ownerDocument.createRange();
		temp.setStartBefore(myParent);
		mylayerObj = temp.createContextualFragment(htmlStr);
		myParent.appendChild(mylayerObj);

		//calk=myParent.all(myCalkName2);
		calk=document.getElementById(myCalkName2);
		
		with (calk.style){
			visibility = "inherit";
			left = myLeft;
			top = myTop;
		}

	}
}

//*** Afficher un menu
function menu_showMenu()
{
	if (this.itemsCreated==0) this.createItems();
	this.unHighLight();

	if (document.layers){//*** nav4
		this.layerObj.visibility="visible";

	}else if (document.all){//*** IE
		myLayerObj=eval(this.layerObj);
		myLayerObj.style.visibility="visible";
		
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		this.layerObj.style.visibility="visible";
	}
}

//*** Cacher un menu
function menu_hideMenu()
{
	if (document.layers){//*** nav4
		this.layerObj.visibility="hidden";

	}else if (document.all){//*** IE
		myLayerObj=eval(this.layerObj);
		myLayerObj.style.visibility="hidden";
		
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		this.layerObj.style.visibility="hidden";
	}
}

//*** activer l'état on d'un item
function menu_highLightItem(myIndex)
{
	if(document.layers){//*** nav4
		myHtml='<font face="Arial" size="1" color="#ffffff">'+this.mtab[myIndex].titre+'</font>';
		myBgLayer=this.mtab[myIndex].bgLayer;
		with(myBgLayer){
			bgColor="#829AB3";
			document.open();
			document.write(myHtml);
			document.close();
		}
		
	}else if(document.all){//*** IE
		myBgLayer=eval(this.mtab[myIndex].bgLayer);
		myBgLayer.style.backgroundColor="#829AB3";
		myBgLayer.all[0].style.color="#ffffff";
		
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		myBgLayer=this.mtab[myIndex].bgLayer;
		myBgLayer.style.backgroundColor="#829AB3";
		myBgLayer.firstChild.style.color="#ffffff";
	}
}

//*** desactiver l'état on des items d'un menu
function menu_unHighLight()
{
	myBgColor=this.itemBgColor;
	for(i=0;i<this.mtab.length;i++){
	
		if(document.layers){//*** nav4
			myHtml='<font face="Arial" size="1" color="#000000">'+this.mtab[i].titre+'</font>';
			myBgLayer=this.mtab[i].bgLayer;
			with(myBgLayer){
				bgColor=myBgColor;
				document.open();
				document.write(myHtml);
				document.close();
			}
			
		}else if(document.all){//*** IE
			myBgLayer=eval(this.mtab[i].bgLayer);
			myBgLayer.style.backgroundColor=myBgColor;
			myBgLayer.all[0].style.color="#000000";
			
		}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
			myBgLayer=this.mtab[i].bgLayer;
			myBgLayer.style.backgroundColor=myBgColor;
			myBgLayer.firstChild.style.color="#000000";
		}
	}
}

//*** lorsque l'utilisateur passe la souris sur un item
function event_item_over(myChildStoreIndex,myMenuStoreIndex,myNiveau,myCalkName,myBgColor,myIndex)
{
	if (myNiveau==0) myNiveau=-1;
		else if (myNiveau==1) myNiveau=-1;
		else if (myNiveau==2) myNiveau=2;
	hideMenus(myNiveau,myMenuStoreIndex);
	
	menuObj_store[myMenuStoreIndex].unHighLight();
	menuObj_store[myMenuStoreIndex].highLightItem(myIndex);
	if(myChildStoreIndex!=-1) menuObj_store[myChildStoreIndex].showMenu();
	
	if(document.layers){//*** nav4
		document.menufond.visibility="visible";
	}else  if(document.all){//*** IE
		document.all.menufond.style.visibility="visible";
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		document.getElementById('menufond').style.visibility="visible";
	}
	
}

//*** Masquer tous les menus sauf le root
function hideMenus(niveau,saufIndex)
{
	if (typeof niveau=="undefined") niveau=-1;
	if (typeof saufIndex=="undefined") niveau=-1;
	for(i=1;i<menuObj_store.length;i++){
		if((menuObj_store[i].niveau==niveau || niveau==-1)&& saufIndex!=i) menuObj_store[i].hideMenu();
	}
}

//*** lorsque l'utilisateur passe la souris sur le fond
function event_menufond_over()
{
	hideMenus();
	myRootMenu.unHighLight();
	
	if(document.layers){//*** nav4
		document.menufond.visibility="hidden";
	}else  if(document.all){//*** IE
		document.all.menufond.style.visibility="hidden";
	}else if (document.getElementById&&navigator.appName=='Netscape'){//*** netscape6
		document.getElementById('menufond').style.visibility="hidden";
	}
}