	/************************************************************************************************************
	(C) www.dhtml.com, October 2005
	
	Update log:
	Version 1.1 	December, 1st 2005: Critical update for the new Firefox 1.5 browser
	Version 1.2: 	December, 21th 2005 : Mouseover effect when mouse moves outside of a submenu items text
	
	
	This is a script from www.dhtml.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtml.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	

//	var name_menu = 'secondary';
//	var name_menu = 'sections';


function menu_deroulant(name_menu_in, i_obj_in){
	
	this.i_obj=i_obj_in;
	
	this.name_menu=name_menu_in;
	
	this.currentDepth_name='none';
	this.currentBlock_name='none';	
	this.timeBeforeAutoHide = 1200; // milliseconds from mouse leaves menu to auto hide.
	this.hideTimer = 0; // milliseconds from mouse leaves menu to auto hide.
	this.top_menuObj=null;	// Reference to the menu div

	this.currentZIndex = 1000;

	
	switch (this.name_menu){
		case 'secondary' : 	this.liIndex=0;
					break;
		case 'sections' : 	this.liIndex=100;
					break;
	}

	



	this.visibleMenus = new Array();
	this.activeMenuItem = false;
	this.top_menu_arrow = '/themes/theme_lot2/arrow.gif';
	
	this.MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
	this.navigatorVersion = navigator.appVersion.replace(/.*?MSIE ([0-9]\.[0-9]).*/g,'$1')/1;
	this.menuBlockArray = new Array();
	this.menuParentOffsetLeft = false;	
	
	this.menuActive = true;


	
	
	
	
	this.getTopPos = function(inputObj){
			
		  var returnValue = inputObj.offsetTop;
		  var menuBlock1name = this.currentBlock_name+'1';		  	
	  	  if(inputObj.tagName=='LI' && inputObj.parentNode.className==menuBlock1name){
		  	
			
			if(this.name_menu == 'sections'){
			  	if(aTag)returnValue;
			}else{
			  	var aTag = inputObj.getElementsByTagName('A')[0];
			  	if(aTag)returnValue += aTag.parentNode.offsetHeight;
			}
			
	
		  }	  
		  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	
		  return returnValue;
	}
		
	this.getLeftPos =	function (inputObj)
	{
		  var returnValue = inputObj.offsetLeft;
		  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
		  return returnValue;
	}
		
	
	this.hideMenuItems = 	function (exceptionArray)
	{
			/*
			Hiding visible menu items
			*/
			var newVisibleMenuArray = new Array();
		  	var menuBlock1name = this.currentBlock_name+'1';
	
			for(var no=0;no<this.visibleMenus.length;no++){
				if(this.visibleMenus[no].className!=menuBlock1name && this.visibleMenus[no].id){
					if(!exceptionArray[this.visibleMenus[no].id]){
						var el = this.visibleMenus[no].getElementsByTagName('A')[0];
						this.visibleMenus[no].style.display = 'none';
						var li = document.getElementById('dhtml_listItem' + this.visibleMenus[no].id.replace(/[^0-9]/g,''));
						if(li.className.indexOf('over')>0)li.className = li.className.replace(/over/,'');
					}else{				
						newVisibleMenuArray.push(this.visibleMenus[no]);
					}
				}
			}		
			this.visibleMenus = newVisibleMenuArray;		
	}
		
		
	
	
		

		
	this.initSubMenus=	function (inputObj,initOffsetLeft,currentDepth)
		{	
			var subUl = inputObj.getElementsByTagName('UL');
			if(subUl.length>0){
				var ul = subUl[0];
				
				ul.id = 'subOf' + inputObj.id.replace(/[^0-9]/g,'');
				ul.setAttribute(this.currentDepth_name ,currentDepth);
				ul.currentDepth = currentDepth;
				ul.className=this.currentBlock_name + currentDepth;

				switch(this.i_obj){
					case 0 : 	ul.onmouseover = function(){ menu_deroulant.prototype.mouseOverMenu(0); }; 
							ul.onmouseout = function(){ menu_deroulant.prototype.mouseOutMenu(0); }; 
							break;
					case 1 : 	ul.onmouseover = function(){ menu_deroulant.prototype.mouseOverMenu(1); }; 
							ul.onmouseout = function(){ menu_deroulant.prototype.mouseOutMenu(1); }; 
							break;
				}

				this.currentZIndex+=1;
				ul.style.zIndex = this.currentZIndex;
				this.menuBlockArray.push(ul);
				var topPos = this.getTopPos(inputObj);
				var leftPos ;	
		
				if(this.name_menu == 'sections'){
					leftPos = 290;	
				}else{
					switch(currentDepth){
						case 3 : 	leftPos=this.getLeftPos(inputObj)+62;
								break;
						default : 	leftPos = this.getLeftPos(inputObj)/1 + initOffsetLeft/1;	
								break;
						
					}
				}
			
				ul = this.top_menuObj.appendChild(ul);
				ul.style.position = 'absolute';
				ul.style.left = leftPos + 'px';
				ul.style.top = topPos + 'px';
				var li = ul.getElementsByTagName('LI')[0];
	
				while(li){
					if(li.tagName=='LI'){	
						li.className=this.currentDepth_name + currentDepth;					
						li.id = 'dhtml_listItem' + this.liIndex;
						this.liIndex++;				
						var uls = li.getElementsByTagName('UL');


						switch(this.i_obj){
							case 0 : 	li.onmouseover = function(){ menu_deroulant.prototype.showHideSub(0, this); }; 
									break;
							case 1 : 	li.onmouseover = function(){ menu_deroulant.prototype.showHideSub(1, this); }; 
									break;
						}
	
						if(uls.length>0){
							var offsetToFunction = li.getElementsByTagName('A')[0].offsetWidth+2;
							if(this.navigatorVersion<6 && this.MSIE)offsetToFunction+=15;	// this.MSIE 5.x fix
							this.initSubMenus(li,offsetToFunction,(currentDepth+1));
						}	
						if(this.MSIE){
							var a = li.getElementsByTagName('A')[0];
							a.style.width=li.offsetWidth+'px';
							a.style.display='block';
						}					
					}
					li = li.nextSibling;
				}
				ul.style.display = 'none';	
				if(!document.all){
					//this.top_menuObj.appendChild(ul);
				}
			}	
		}
	
	
	
	
	
	
		
		/* 
		Initializing menu 
		*/
	
			
	
	
	this.initDhtmlMenu =	function ()
		{
	
	
			this.currentDepth_name = this.name_menu+'-'+'currentDepth';
			this.currentBlock_name = this.name_menu+'-'+'menuBlock';
			this.top_menuObj = document.getElementById(this.name_menu);
			
			var aTags = this.top_menuObj.getElementsByTagName('A');
			for(var no=0;no<aTags.length;no++){			
	
				var subUl = aTags[no].parentNode.getElementsByTagName('UL');
				if(subUl.length>0 && aTags[no].parentNode.parentNode.parentNode.id != this.name_menu){
					var img = document.createElement('IMG');
					img.src = this.top_menu_arrow;
					aTags[no].appendChild(img);				
	
				}
	
			}
					
			var mainMenu = this.top_menuObj.getElementsByTagName('UL')[0];
		  	var menuBlock1name = this.currentBlock_name+'1';
			mainMenu.className=menuBlock1name;
			mainMenu.style.zIndex = this.currentZIndex;
			mainMenu.setAttribute(this.currentDepth_name ,1);
			mainMenu.currentDepth = '1';

				switch(this.i_obj){
					case 0 : 	mainMenu.onmouseover = function(){ menu_deroulant.prototype.mouseOverMenu(0); }; 
							mainMenu.onmouseout = function(){ menu_deroulant.prototype.mouseOutMenu(0); }; 
							break;
					case 1 : 	mainMenu.onmouseover = function(){ menu_deroulant.prototype.mouseOverMenu(1); }; 
							mainMenu.onmouseout = function(){ menu_deroulant.prototype.mouseOutMenu(1); }; 
							break;
				}




	
			var mainMenuItemsArray = new Array();
			var mainMenuItem = mainMenu.getElementsByTagName('LI')[0];
			//mainMenu.style.height = mainMenuItem.offsetHeight + 2 + 'px';
			while(mainMenuItem){			
				if(mainMenuItem.className==undefined)	mainMenuItem.className="";
				if (mainMenuItem.className!="")	mainMenuItem.className+=' xxx '+this.currentDepth_name+'1';
				else	mainMenuItem.className+=this.currentDepth_name+'1';  // xxxxx permet de séparation le style original, que l'on garde , avec le style généré par ce script
				mainMenuItem.id = 'dhtml_listItem' + this.liIndex;

						switch(this.i_obj){
							case 0 : 	mainMenuItem.onmouseover = function(){ menu_deroulant.prototype.showHideSub(0, this); }; 
									break;
							case 1 : 	mainMenuItem.onmouseover = function(){ menu_deroulant.prototype.showHideSub(1, this); }; 
									break;
						}


				this.liIndex++;				
				if(mainMenuItem.tagName=='LI'){
					mainMenuItem.style.cssText = 'float:left;';	
					mainMenuItem.style.styleFloat = 'left';
					mainMenuItemsArray[mainMenuItemsArray.length] = mainMenuItem;
					this.initSubMenus(mainMenuItem,0,2);
				}			
				
				mainMenuItem = mainMenuItem.nextSibling;
				
			}
	
			for(var no=0;no<mainMenuItemsArray.length;no++){
				this.initSubMenus(mainMenuItemsArray[no],0,2);			
			}
			
			this.menuParentOffsetLeft = this.getLeftPos(this.top_menuObj);	
			switch(this.i_obj){
				case 0 : 	window.onresize = function(){ menu_deroulant.prototype.resizeMenu(0); }; 
				break;
				case 1 : 	window.onresize = function(){ menu_deroulant.prototype.resizeMenu(1); }; 
				break;
			}
			
			this.top_menuObj.style.visibility = 'visible';	
		}
		
	
	
		// fin de declaration des fonctions de la classe
		
		this.initDhtmlMenu();

} // fin de la 'classe' menu_deroulant

















var obj_menu_deroulant=new Array;
var nb_obj_menu_deroulant=0;

// variables prototypes : publiques




// fonctions prototypes : publiques

	menu_deroulant.prototype.resizeMenu=	function (i_obj)
		{
/*
		var menu_obj = obj_menu_deroulant[i_obj];

		var offsetParent = menu_obj.getLeftPos(menu_obj.top_menuObj);
			
			for(var no=0;no<menu_obj.menuBlockArray.length;no++){
				var leftPos = menu_obj.menuBlockArray[no].style.left.replace('px','')/1;
				menu_obj.menuBlockArray[no].style.left = leftPos + offsetParent - this.menuParentOffsetLeft + 'px';
			}
			menu_obj.menuParentOffsetLeft = offsetParent;
*/		
		}


	menu_deroulant.prototype.mouseOverMenu = function(i_obj)
		{
		var menu_obj = obj_menu_deroulant[i_obj];

			if (!menu_obj.top_menuObj) return;
			menu_obj.menuActive = true;		
		}
		
	menu_deroulant.prototype.mouseOutMenu =	function (i_obj)
		{
		var menu_obj = obj_menu_deroulant[i_obj];

			if (!menu_obj.top_menuObj) return;
			menu_obj.menuActive = false;
			menu_deroulant.prototype.timerAutoHide(i_obj); 		
		}




	menu_deroulant.prototype.showHideSub=	function (i_obj, objetsurvol)
	{
		
		var menu_obj = obj_menu_deroulant[i_obj];
//debugger;
				
			var attr = objetsurvol.parentNode.getAttribute(menu_obj.currentDepth_name);
			if(navigator.userAgent.indexOf('Opera')>=0){
				attr = objetsurvol.parentNode.currentDepth;
			}
			// on recherche ' xxx ' , on enleve le reste et on ajoute ...
			// si cette chaine n'existe pas, alors on ajoute...
			
			var posxxx = objetsurvol.className.indexOf(" xxx ");
			if (posxxx ==-1){
				objetsurvol.className = menu_obj.currentDepth_name + attr + 'over';		
			}else{
				var debut_style = objetsurvol.className.substr(0,posxxx+5);
				objetsurvol.className = debut_style +menu_obj.currentDepth_name + attr + 'over';		
			}
			 
			if(menu_obj.activeMenuItem && menu_obj.activeMenuItem!=objetsurvol){
				menu_obj.activeMenuItem.className=menu_obj.activeMenuItem.className.replace(/over/,'');
			}
			menu_obj.activeMenuItem = objetsurvol;
		
			var numericIdThis = objetsurvol.id.replace(/[^0-9]/g,'');
			var exceptionArray = new Array();
			// Showing sub item of this LI
			var sub = document.getElementById('subOf' + numericIdThis);
			if(sub){
				menu_obj.visibleMenus.push(sub);
				sub.style.display='';	
					
				sub.parentNode.className = sub.parentNode.className.replace(/over/,'');
				sub.parentNode.className = sub.parentNode.className + 'over';
				exceptionArray[sub.id] = true;
			}	
			
			// Showing parent items of this one
			
			var parent = objetsurvol.parentNode;
			while(parent && parent.id && parent.tagName=='UL'){
				menu_obj.visibleMenus.push(parent);
				exceptionArray[parent.id] = true;
				parent.style.display='';			
				var li = document.getElementById('dhtml_listItem' + parent.id.replace(/[^0-9]/g,''));
				if(li.className.indexOf('over')<0)li.className = li.className + 'over';
				parent = li.parentNode;			
			}
	
				
			menu_obj.hideMenuItems(exceptionArray);
	
	
	
	}


	menu_deroulant.prototype.timerAutoHide =	function (i_obj)
		{
		var menu_obj = obj_menu_deroulant[i_obj];

			if(menu_obj.menuActive){
				menu_obj.hideTimer = 0;
				return;
			}
			
			if(menu_obj.hideTimer<menu_obj.timeBeforeAutoHide){
				menu_obj.hideTimer+=100;
				window.setTimeout('menu_deroulant.prototype.timerAutoHide('+i_obj+')',99);
			}else{
				menu_obj.hideTimer = 0;
				// autohideMenuItems
				if(!menu_obj.menuActive){
					menu_obj.hideMenuItems(new Array());	
					if(menu_obj.activeMenuItem)menu_obj.activeMenuItem.className=menu_obj.activeMenuItem.className.replace(/over/,'');		
				}
			}
		}


	// Execution des scripts au chargement de la page
window.onload = function() {
}
active_menu_top = function() {
if(1){
		if (document.getElementById("secondary")){
			obj_menu_deroulant[nb_obj_menu_deroulant]= new menu_deroulant('secondary', nb_obj_menu_deroulant);
			nb_obj_menu_deroulant++;
		} else {
			// alert('secondary id doesn\'t exist');
		}
	
}		
if(1){
		if (document.getElementById("sections")){
			obj_menu_deroulant[nb_obj_menu_deroulant]= new menu_deroulant('sections', nb_obj_menu_deroulant);
			nb_obj_menu_deroulant++;
		} else {
			// alert('sections id doesn\'t exist');
		}
}

}
