// GESTION DES MENUS - SITE EUREGIDE
// 22/09/2001 - Web Project (www.w-project.com)

var lmenux=new Array;	// mémo posit X des menus
var lmenucompx=(top.document.layers) ? 10 : 17;	// compensation X pour Netscape : MS ("top" obligat. pour NS avec frames)
var lmenucompy=(top.document.layers) ? 3 : 0;	// idem en Y
var lmenuact='';		// mémo nom du menu ouvert
var lmenuoff=false;		// vrai -> valid hide menus

function lmenu_create(name,x,y,txt,path,pstyle,bcol,l,h,typ,params) {
	lmenux[name]=x;			// -- mémo posit x absolue
	if (document.all) {		//-- Explorer
		var t='<style type="text/css">\n';
		t+= '#' + name + ' {position:absolute;left:' + x + '; top:' + (y+lmenucompy);
		t+= ';margin:0;display:none}\n';
		t+= '</style>';
		t+= '<table id="' + name + '" onmouseover="lmenuoff=false" onmouseout="lmenu_display(0,2)"><tr><td>';
		if(l) t+= make_table(txt,path,pstyle,bcol,l,h,typ,params);
		else t+= txt;
		t+= '</td></tr></table>';
	}
	else if (top.document.layers) {	//-- Netscape
		var t='<layer name="' + name + '" left=' + x + ' top=' + (y+lmenucompy) + ' visibility=hide';
		t+=' onmouseover="lmenuoff=false" onmouseout="lmenu_display(0,2)">';
		if(l) t+= make_table(txt,path,pstyle,bcol,l,h,typ,params);
		else t+=txt;
		t+= '</layer>';
	}
	document.write(t);
}

function lmenu_display(name,v,c,f) {
	if(v==1 && c) {	// reposit éventuel avant de la rendre visible
		if(!f) f=0.5
		var xwin=lmenu_x();		//largeur interne de la fenêtre
		var x=(xwin>c+lmenucompx) ? Math.floor((xwin-c-lmenucompx)*f) : 0;
		x+= lmenux[name];
		lmenu_move(name,x)		//reposit menu en x
	}

	if(v==2) {		// menu actif -> invisible après délai
		lmenuoff=true;
		timeout=setTimeout('lmenu_rideau()',100);
	}	
	else {
		lmenuoff=false;						// interdit effacement à terme
		if(v) {		// menu -> visible
			if(lmenuact) lmenu_display();	// Effacement préalable old menu actif éventuel
			lmenuact= name;					// mémo du nom du nouveau menu actif
		}
		else {		// menu -> invisible immédiatement
			name=lmenuact;
			lmenuact='';
		}
		if (document.all) {
			var a= (v) ? 'block' : 'none';
			document.all[name].style.display= a;
		}
		else if (top.document.layers) {
			var a= (v) ? 'show' : 'hide';
			document.layers[name].visibility=a;		// pas top.document, NS n'aime pas...
		}
	}
}

// ======= FONCTIONS INTERNES =======
// -- Retourne la largeur interne de la fenêtre
function lmenu_x() {
	var x=0;
	if (document.all) x=document.body.offsetWidth;
	else if (top.document.layers) x=window.innerWidth;
	return x;
}

// -- repositionnement de l'objet 'name' en x
function lmenu_move(name,x) {
	if(document.all) document.all[name].style.pixelLeft=x;
	else if(top.document.layers) top.document.layers[name].left=x;
}

// -- extinction de l'objet courant (fin de tempo)
function lmenu_rideau() {
	if(lmenuact && lmenuoff) lmenu_display();
}

// -- dessin de la bulle
function make_table(txt,path_img,pstyle,bcol,l,h,t,params) {
	var r='';
	if(params) {
		var pa=params.split(':');	// paramètres de la bulle
		for(var i in pa) pa[i]=parseFloat(pa[i]);
		var l0=pa[0],l1=pa[1]	// largeur des colonnes gauche et droite
		var h0=pa[2],h1=pa[3]	// hauteur des coins hg, bg
		var h2=pa[4],h3=pa[5]	// coins hd, bd
		var h4=pa[6],h5=pa[7]	// hauteur des bandes h / b
		if(!t) t="hd";			// par défaut, haut-droite
		var hd=(t=="hd") ? "fle_hd" : "std_hd"	// Nom du coin haut droit
		var bd=(t=="bd") ? "fle_bd" : "std_bd"	// idem bas droit
		var bg=(t=="bg") ? "fle_bg" : "std_bg"	// bas gauche
		var hg=(t=="hg") ? "fle_hg" : "std_hg"	// haut gauche
		l=l-l0-l1;				// largeur du milieu
		var ht=(h0+h1>h2+h3) ? h0+h1 : h2+h3;	// plus grande hauteur des coins (h mini bulle)
		if(h<ht) {								// mise à l'échelle des coins nécessaire
			var e=ht/h;
			h0=Math.floor(h0/e);
			h1=Math.floor(h1/e);
			h2=Math.floor(h2/e);
			h3=Math.floor(h3/e);
			h4=Math.floor(h4/e);
			h5=Math.floor(h5/e);
		}
		var r= '<table border="0" cellspacing="0" cellpadding="0" width="' + l + '" height="' + h + '">';

		// - Colonne de gauche (largeur = l0)
		r+= '<tr><td rowspan="3" width="' + l0 + '">';
		r+= '<img src="' + path_img + hg + '.gif" width="' + l0 + '" height="' + h0 + '"><br>';
		var hm=h-h0-h1;		// hauteur restant pour le milieu / gauche de la bulle
		if(hm>0) r+='<img src="' + path_img + 'std_g.gif" width="' + l0 + '" height="' + hm + '"><br>';
		r+= '<img src="' + path_img + bg + '.gif" width="' + l0 + '" height="' + h1 + '"></td>';

		// - Haut de la colonne du centre (largeur = l)
		r+= '<td valign="top"><img src="' + path_img + 'std_h.gif" width="' + l + '" height="' + h4 + '"></td>';

		// - Colonne de droite (largeur = l1, hauteur = h - 38)
		r+= '<td rowspan="3" width="' + l1 + '">';
		r+= '<img src="' + path_img + hd + '.gif" width="' + l1 + '" height="' + h2 + '"><br>';
		var hm=h-h2-h3;	// hauteur restant pour le milieu / droite de la bulle
		if(hm>0) r+='<img src="' + path_img + 'std_d.gif" width="' + l1 + '" height="' + hm + '"><br>';
		r+= '<img src="' + path_img + bd + '.gif"  width="' + l1 + '" height="' + h3 + '"></td>';

		// - Fin de la colonne centrale
		r+= '</tr><tr><td width="' + l + '" bgcolor="#ADD1F3" valign="middle" height="' + (h-h4-h5) + '">';
		r+= '<p class="' + pstyle + '">' + txt + '</td>';
		r+= '</tr><tr><td valign="bottom">';
		r+= '<img src="' + path_img + 'std_b.gif" width="' + l + '" height="' + h5 + '"></td>';
		r+= '</tr></table>';
	}
	else alert('bulle ' + path + ' non initialisée');
	return r;
}

