
	// ----------------- NAVIGATIONTOOLS ------------------------------------->
	
	// --------------------------
		var menuprefix="menu";
		var submenuprefix="submenu";
	// --------------------------


	var currentMenuVisible=null;
	var currentSubMenuVisible=null;

	function toggleMenu(id){

		var menu=document.getElementById(menuprefix+id);
		var submenu=document.getElementById(submenuprefix+id);

//		alert( "menu=\""+menu+"\" submenu=\""+submenu +"\"");
		if(menu==null || menu==undefined)	
			return;
		if(submenu==null || submenu==undefined)	
			return;	
	

		if( isMenuDisplayed(submenu) ) {
			doHideSubMenu(menu,submenu);
		}
		else {
			if(currentSubMenuVisible){
				doHideSubMenu(currentMenuVisible,currentSubMenuVisible);
			}
						
			doShowSubMenu(menu,submenu);
			setInterval("attachWatcher()",1000)
			//attachWatcher(submenu)
		}
	}

	function checkMenusAfterResize(){
		if( currentSubMenuVisible ) {
			doShowSubMenu(currentMenuVisible,currentSubMenuVisible);
		//	attachWatcher(submenu)			
		}
	}

	function attachWatcher(submenu){
		if( !currentSubMenuVisible ) {
			return;
		}		
		document.onmousemove = checkMousePosition;
	}

	function detachWatcher(submenu){
		document.onmousemove=null
	}

	/**
	 * Verifie la position de la souris, apres un show normal ( après un toggle )
	 */
	function checkMousePosition(evt){

		if(!evt) evt = window.event;	

		mousex = evt.clientX;
		mousey = evt.clientY;	

		if( currentSubMenuVisible ) {
			 var cond1=mousex >= getRealLeft(currentSubMenuVisible);
			 var cond2=mousex <= getRealLeft(currentSubMenuVisible)+getRealWidth(currentSubMenuVisible);
			 var cond3=mousey >= getRealTop(currentSubMenuVisible);
			 var cond4=mousey <= getRealTop(currentSubMenuVisible)+getRealHeight(currentSubMenuVisible)

			if(!(cond1 && cond2 && cond3 && cond4)) {
				//window.status="click dehors "+ cond1+" " + cond2+" " + cond3+" "+cond4
				doHideSubMenu(currentMenuVisible,currentSubMenuVisible);				
			}
			else {
				//window.status="click dedans "+ cond1+" " + cond2+" " + cond3+" "+cond4
			}
		}
	}

	/**
	 * Verifie la position de la souris, apres un click dans la page
	 */
	function checkMousePositionAfterClick(evt){
		var sourceElement=document.all?evt.srcElement:evt.target
		var clickX;
		var clickY;

		if(document.all) {
			clickX=evt.x;
			clickY=evt.y;
		}
		else {
			clickX=evt.pageX;
			clickY=evt.pageY;
		}
		
		if( currentSubMenuVisible ) {
			 var cond1=clickX >= getRealLeft(currentSubMenuVisible);
			 var cond2=clickX <= getRealLeft(currentSubMenuVisible)+getRealWidth(currentSubMenuVisible);
			 var cond3=clickY >= getRealTop(currentSubMenuVisible);
			 var cond4=clickY <= getRealTop(currentSubMenuVisible)+getRealHeight(currentSubMenuVisible)

			if(!(cond1 && cond2 && cond3 && cond4)) {
				//window.status="click dehors "+ cond1+" " + cond2+" " + cond3+" "+cond4
				doHideSubMenu(currentMenuVisible,currentSubMenuVisible);
			}
			else {
				window.status="click dedans "+ cond1+" " + cond2+" " + cond3+" "+cond4
			}
		}
	}
	
	/**
	 * Affiche un sous menu sans effectuer de tests logiques
	 * Affeccte les variables currentMenuVisible et  currentSubMenuVisible
	 */
	function doShowSubMenu(menu,submenu){	
		var correctifTop=document.all?0:0;

		submenu.style.left=getRealLeft(menu)+"px";
		//submenu.style.top=(getRealTop(menu)+correctifTop)+"px";
		submenu.style.visibility="visible";
		menu.style.visibility="hidden";
		currentMenuVisible=menu;
		currentSubMenuVisible=submenu;			
	}

	/**
	 * Masque un sous menu sans effectuer de tests logiques
	 * Affeccte les variables currentMenuVisible et  currentSubMenuVisible a null
	 */ 
	function doHideSubMenu(menu,submenu){
		submenu.style.visibility="hidden";
		menu.style.visibility="visible";		
		currentMenuVisible=null;
		currentSubMenuVisible=null;	
	}

	/**
	 * Retourne true/false selon que l'element el, est visible ou non
	 */
	function isMenuDisplayed(el){
		return el.style.visibility=="visible";
	}
	/**
	 * Retourne true/false selon que l'element el, est inviible ou non
	 */	
	function isMenuHidden(el){
		return el.style.visibility=="hidden";
	}

	// ----------------- NAVIGATIONTOOLS ------------------------------------->



	// ----------------- MEASURING TOOLS ------------------------------------->
	function getRealWidth( element ){
		if( element.style.width=="" || parseInt(element.style.width)==null || parseInt(element.style.width)==undefined) {
			return parseInt(element.offsetWidth);
		}
		return parseInt(element.style.width);
	}
	function getRealHeight( element ){
		if( element.style.height=="" || parseInt(element.style.height)==null || parseInt(element.style.height)==undefined) {
			return parseInt(element.offsetHeight);
		}
		return parseInt(element.style.height);
	}
	function getRealTop( element ){
		var top=0;
		var s='';
		var root=element;
		while( root.offsetParent != undefined ) {
			if ( root.id)
				s+=root.id+"\n"
			s+=root.tagName+' '+root.id+' '+root.offsetTop+'\n'
			if(root.tagName!='TR' && root.tagName!='TBODY') {
				top+=parseInt(root.offsetTop)	
			}
			root=root.offsetParent 
		}
		//	alert(s);
		return top;		
	}
	function getRealLeft( element ){
		var left=0;
		var root=element;
		while( root.offsetParent != undefined ) {
			//s+=root.tagName+' '+root.id+' '+root.offsetTop+'<br>'
			if(root.tagName!='TR' && root.tagName!='TBODY') {
				left+=parseInt(root.offsetLeft)
			}
			root=root.offsetParent 
		}
		return left;		
	}
	function largeur_fenetre(){
		if (window.innerWidth) return window.innerWidth;
	 	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	 	else return 0;
	}

	function hauteur_fenetre(){
		if (window.innerHeight) return window.innerHeight  ;
	 	else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
	 	else return 0;
	}
	// ----------------- MEASURING TOOLS ------------------------------------->
	
	
	
	// ----------------- CENTERING TOOLS ------------------------------------->
 	function centerNav(){
		
		var mainleft=parseInt(largeur_fenetre())-parseInt(document.getElementById("navigation").style.width);
		mainleft=parseInt(mainleft/2);
		if(mainleft<0){
			mainleft=0;
		}
		if(document.all){
			mainleft+=1
		}
		document.getElementById("navigation").style.left=mainleft+"px";
		//window.status="centerNav > "+(document.getElementById("navigation").style.left);

	}
	// ----------------- CENTERING TOOLS ------------------------------------->
	
	







 
