/* iubito's menu - http://iubito.free.fr/prog/menu.php - configuration du javascript */

/* true = the menu will be vertical, on the left.
   false = the menu will be horizontal, in top. */

var vertical = false;

/* IMPORTANT !
   It is necessary to put here the number of menus, script is not able to count all 
   alone!  Donc if your code goes to < p id="menu5 "... >  5 should be put. */

var nbmenu = 3;

/* Centrer le menu ? (true/false).
   Center horizontally or vertically according to the selected mode. 
*/

var centrer_menu = true;

/* define the width for the menus.  

   To put menus of different widths:  
   VAr largeur_menu = new Array(largeur menu1, width menu2, width menu3...) 
   Attention should be paid to put as many values as of a number of menu!  
   Attention, if you are in vertical menu, put a fixed width (not Array)!
*/

var largeur_menu = 125;

/* In vertical mode, one needs to know the height of each menu. 
   Even if the "boxes" are not dimensioned in height. 
   Adjust this variable if the menus are too much brought closer or spaced into vertical. 
   To put menus different heights:  
   VAr hauteur_menu = new Array(hauteur menu1, height menu2, height menu3...) 
   Attention should be paid to put as many values as of a number of menu!  
   Attention, if you are in horizontal menu, put a fixed width (not Array) !
*/

var hauteur_menu = 25;

/* En mode horizontal.

	Width of the sub-menus, for IE only, the other navigators respect the width car.  
	Put "car" only if you are sure to have put  
	in the place of space in the items!  
	To put sub-menus of different widths:  
	VAr largeur_sous_menu = new Array(largeur1, largeur2...). 
	Attention should be paid to put as many values as menus. 
	If a menu does not have sub-menus, something should be put nevertheless! 
	It is possible to put "car" in certain columns, with the proviso of respecting the instruction above.
*/

var largeur_sous_menu = 230;


/* For the navigators knowing the automatic width (adapts to the contents),
   this option (active by defect) makes it possible to have an automatic width. 
   In contrary case (false), under menus will have the width largeur_sous_menu. 
*/

var largeur_auto_ssmenu = true;

/* ... to put a little space enters the menus ! */

var espace_entre_menus = 5;


/* position of the menu compared to the top of the screen or the page.
  0 = the menu is all in top.  in px 
*/

var top_menu = 2;

/* In horizontal version.  
   position of the sub-menus compared to the top of the screen or the page. 
   It is necessary to envisage the height of the menus, 
   therefore not to put 0 and make "with tâton".  in px 
*/

var top_ssmenu = top_menu + 28;

/* Position gauche du menu, en px. */

var left_menu = 0;

/* En version verticale.
   Position des sous-menus par rapport au bord gauche de l'écran. 
*/

var left_ssmenu = largeur_menu+2;

/* When the mouse leaves a sub-menu, if the sub-menu disparait immediately,
  that obstructs the user.  Then one can put a time before disappearance of 
  the sub-menu.  500 ms is good :-) 
*/

var delai = 650; // en milliseconde

/* En version horizontale.
   As the menu can be superimposed with the text of the page,
   it is possible to reduce a little the page (the margin top is increased)
   to air a little the page, forty pixel it is not badly in px
*/

var height_page = top_menu + 40;

/* En version verticale.
  On décale le document à droite pour pas que le menu le superpose. 
*/
 

var marge_a_gauche_de_la_page = largeur_menu + 10;

/* Put at true if you wish that the menu be always visible.  
   Put false if you do not wish it, in this case the menu "will disappear" 
   when you go down in the page. 
*/

var suivre_le_scroll=true;

/* For IE only, the beacons < select > always pass above the menu,
   therefore by defect one hides the drop-down lists when the menu is opened,
  then one makes them reappear with closing menu.  To prevent that, put at false.
*/

var cacher_les_select=true;

var timeout; //not to touch, it is to declare the variable

var agt = navigator.userAgent.toLowerCase();

var isMac = (agt.indexOf('mac') != -1);

var isOpera = (agt.indexOf("opera") != -1);

var IEver = parseInt(agt.substring(agt.indexOf('msie ') + 5));

var isIE = ((agt.indexOf('msie')!=-1 && !isOpera && (agt.indexOf('webtv')==-1)) && !isMac);

var isIE5win = (isIE && IEver == 5);

var isIE5mac = ((agt.indexOf("msie") != -1) && isMac);

var blnOk=true;

//to remove the "px" to make calculations...

var reg = new RegExp("px", "g");


// onScroll for Internet To explore, the position:fixed makes this job for the other navigators

// who respect standards CSS...

window.onscroll = function()

{

	if (blnOk && suivre_le_scroll && (isIE || isIE5mac))

	{

		if (isIE5mac) document.getElementById("small_container").style.visibility="hidden";

		var cumul=0;

		for(i=1;i<=nbmenu;i++)

		{

			if (!vertical) {

				document.getElementById("menu"+i).style.top = document.body.scrollTop + top_menu + "px";

				if (document.getElementById("ssmenu"+i))//undefined

					document.getElementById("ssmenu"+i).style.top = document.body.scrollTop + top_ssmenu + "px";

			} else {

				document.getElementById("menu"+i).style.top = document.body.scrollTop

							+(((i-1)*espace_entre_menus)+cumul+1+top_menu)+"px";

				if (document.getElementById("ssmenu"+i))//undefined

					document.getElementById("ssmenu"+i).style.top = document.body.scrollTop

							+(((i-1)*espace_entre_menus)+cumul+1+top_menu)+"px";

				cumul += isFinite(hauteur_menu)?hauteur_menu:hauteur_menu[i-1];

			}

		}

		if (isIE5mac) document.getElementById("small_container").style.visibility="visible";

	}

}

function flicker()

{

	if (document.getElementById("small_container"))

	{

		document.getElementById("small_container").style.visibility="hidden";

		//IE5 mac has a bug:  when a text is in an element of style float, it does not appear.

		/*if (isIE5mac)

		{

			document.getElementById("small_container").style="";

		}*/

	}

}

function Loading() {

	if (!blnOk) {

		if(document.body.style.backgroundColor!="") { blnOk=false; }

		if(document.body.style.color!="") { blnOk=false; }

		if(document.body.style.marginTop!="") { blnOk=false; }

		if(document.getElementById) {

			with(document.getElementById("small_container").style) {

				if(position!="" || top!="" || left!=""

						|| width!="" || height!="" || zIndex!=""

						|| margin!="" || visibility!="") {

					blnOk=false;

				}

			}

		}
		else{

			blnOk=false;
		}
	}
	if(blnOk)
	{

		document.getElementById("small_container").style.visibility="hidden";

		

		trimespaces();

		

		with(document.body.style) {

			if (!vertical) marginTop=height_page+"px";

			else		   marginLeft=marge_a_gauche_de_la_page+"px";

		}

		

		positionne();

		CacherMenus();

	}
	// like one avoided the flickering, now one reveals the menu ;-)

	document.getElementById("small_container").style.visibility='';

}

window.onresize = Loading;
/*

 * Place the elements of the menu correctly, with the loading, the scroll, redimensioning

 * window

 */

function positionne() {

	var largeur_fenetre = (isIE?document.body.clientWidth:window.innerWidth);

	var hauteur_fenetre = (isIE?document.body.clientHeight:window.innerHeight);

	if (centrer_menu) {

		if (!vertical) {

			var largeur_totale = espace_entre_menus * (nbmenu-1);

			if (isFinite(largeur_menu))

				largeur_totale += largeur_menu * nbmenu;

			else {

				for (i = 1; i <= nbmenu; i++)

					largeur_totale += largeur_menu[i-1];

			}

			left_menu = (largeur_fenetre - largeur_totale)/2;

		} else {

			var hauteur_totale = espace_entre_menus * (nbmenu-1);

			if (isFinite(hauteur_menu))

				hauteur_totale += hauteur_menu * nbmenu;

			else {

				for (i = 1; i <= nbmenu; i++)

					hauteur_totale += hauteur_menu[i-1];

			}

			top_menu = (hauteur_fenetre - hauteur_totale)/2;

		}

	}

	

	//Menus

	var cumul = 0;

	for(i=1;i<=nbmenu;i++) {

		with(document.getElementById("menu"+i).style) {

			if (!vertical) {

				top=top_menu+"px";

				//left=(((i-1)*(largeur_menu+espace_entre_menus))+1+left_menu)+"px";

				left=(((i-1)*espace_entre_menus)+cumul+1+left_menu)+"px";

			} else {

				//top=(((i-1)*(hauteur_menu+espace_entre_menus))+1+top_menu)+"px";

				top=(((i-1)*espace_entre_menus)+cumul+1+top_menu)+"px";

				left=left_menu+"px";

			}

			if (!suivre_le_scroll || isIE || isIE5mac)

				position="absolute";

			else position="fixed";

			//if (vertical) height=hauteur_menu+"px";

			margin="0";

			zIndex="2";

			if (vertical || isFinite(largeur_menu))

				width=largeur_menu+"px";

			else

				width=largeur_menu[i-1]+"px";

			if ((!vertical && isFinite(largeur_menu)) || (vertical && isFinite(hauteur_menu))) {

				cumul += (!vertical?largeur_menu:hauteur_menu);

			}

			else {

				cumul += (!vertical?largeur_menu[i-1]:hauteur_menu[i-1]);

				if (vertical) height=hauteur_menu[i-1]+"px";

			}

		}

	}

	

	//Sub-menus

	cumul = 0;

	for(i=1;i<=nbmenu;i++) {

		if (document.getElementById("ssmenu"+i))//undefined

		{

			with(document.getElementById("ssmenu"+i).style) {

				if (!suivre_le_scroll || isIE || isIE5mac)

					position="absolute";

				else position="fixed";

				if (!vertical) {

					top=top_ssmenu+"px";

					//left=(((i-1)*(largeur_menu+espace_entre_menus))+1+left_menu)+"px";

					left=(((i-1)*espace_entre_menus)+cumul+1+left_menu)+"px";

				} else {

					left=left_ssmenu+"px";

					//top=(((i-1)*(hauteur_menu+espace_entre_menus))+1+top_menu)+"px";

					top=(((i-1)*espace_entre_menus)+cumul+1+top_menu)+"px";

				}

				if (isIE || isOpera || isIE5mac || !largeur_auto_ssmenu) {

					if (isFinite(largeur_sous_menu))

						width = largeur_sous_menu+(largeur_sous_menu!="auto"?"px":"");

					else

						width = largeur_sous_menu[i-1]+(largeur_sous_menu[i-1]!="auto"?"px":"");

				}

				else width = "auto";

				if (!vertical && !isIE5mac) {

					//repositioning if overflows on the right

					if ((width != "auto")

						&& ((left.replace(reg,'').valueOf()*1 + width.replace(reg,'').valueOf()*1) > largeur_fenetre))

						left = (largeur_fenetre-width.replace(reg,'').valueOf())+"px";

				}

				margin="0";

				zIndex="3";

			}

		}

		if ((!vertical && isFinite(largeur_menu)) || (vertical && isFinite(hauteur_menu))) {

			cumul += (!vertical?largeur_menu:hauteur_menu);

		}

		else {

			cumul += (!vertical?largeur_menu[i-1]:hauteur_menu[i-1]);

		}

	}

}





function ShowMenu(strMenu) {

	if(blnOk) {

		CancelHide();

		CacherMenus();

		if (document.getElementById(strMenu))//undefined

			with (document.getElementById(strMenu).style)

				visibility="visible";

	}

	SelectVisible("hidden",document.getElementsByTagName('select'));

}



function HideTime() {

	if (blnOk) {

		timeout = setTimeout('CacherMenus()',delai);

	}

}

function CancelHide() {

	if (blnOk && timeout) {

		clearTimeout(timeout);

	}

}

function CacherMenus() {

	if(blnOk) {

		for(i=1;i<=nbmenu;i++) {

			if (document.getElementById("ssmenu"+i))//undefined

				with(document.getElementById("ssmenu"+i).style)

					visibility="hidden";

		}

	}

	SelectVisible("visible",document.getElementsByTagName('select'));

}



function trimespaces() {

	//Circumvent a bug of IE5/win... it does not collect well the css for < Li >, therefore they are transfered!

	if(blnOk&&isIE5win) {

		for(i=1;i<=nbmenu;i++) {

			if (document.getElementById("ssmenu"+i))//undefined

				with(document.getElementById("ssmenu"+i))

					innerHTML = innerHTML.replace(/<LI>|<\/LI>/g,"");

		}

	}

}



function SelectVisible(v,elem) {

	if (blnOk && cacher_les_select && (isIE||isIE5win))

		for (var i=0;i<elem.length;i++) elem[i].style.visibility=v;

}

