//
// bulle.js - "Glossaire jaillissant"
// Creation 7/dec/99 Olivier Guerin
// olivier.guerin@logiscom.fr
// (c) Logiscom http://www.logiscom.fr 
//

var tpsBulle=2000;
var idTimeBul=-1;
var bulvis="";
var largeurBulle=250;
var padding=2;

function bulle(nom, titre, txt)
{
	this.nom=nom;
	this.titre=titre;
	this.txt=txt;
	this.nomlay="";
	return this;
}
function showBulle(e)
{
	if (""!=bulvis) doHideBulle();
	var nom="";
	var lay=null;
	if (document.all)
	{
		nom=event.srcElement.name;
		lay=getBulleByName(nom);

		var wdoc=document.body.scrollWidth;
		var hdoc=document.body.scrollHeight;
		var l=document.all(lay.nomlay).style.pixelWidth+2;
		var h=document.all(lay.nomlay).offsetHeight+2;
		var x=event.clientX;
		var y=event.clientY+document.body.scrollTop;
		if ((x+l)>wdoc) x=wdoc-l;
		if ((y+h)>hdoc) y=hdoc-h;
		document.all(lay.nomlay).style.pixelTop=y;
		document.all(lay.nomlay).style.pixelLeft=x;

		highlight(document.all(lay.nomlay), true);
		showdiv(lay.nomlay);
	}
	else
	{
		nom="bulle"+e.target.href[e.target.href.length-1];
		lay=getBulleByName(nom);

		var wdoc=window.innerWidth-(window.scrollbars.visible?20:0);
		var hdoc=document.height;
		var l=eval("document.layers[\""+lay.nomlay+"\"].document.width");
		var h=eval("document.layers[\""+lay.nomlay+"\"].document.height");
		var x=e.pageX;
		var y=e.pageY;
		if ((x+l)>wdoc) x=wdoc-l;
		if ((y+h)>(hdoc)) y=hdoc-h;

		eval("document.layers[\""+lay.nomlay+"\"].left="+x);
		eval("document.layers[\""+lay.nomlay+"\"].top="+y);
		eval("document.layers[\""+lay.nomlay+"\"].visibility='visible'");
	}
	bulvis=lay.nomlay;
}
function doHideBulle()
{
	if (""!=bulvis) hidediv(bulvis);
	cancelHideBulle(); bulvis="";
}

function hideBulle(e)
{
	idTimeBul=setTimeout("doHideBulle()", tpsBulle);
	if (document.all && ""!=bulvis) highlight(document.all(bulvis), false);
}

function getBulleByName(nom)
{
	for (var i=0; i<tabbulles.length; i++)
	{
		if (nom==tabbulles[i].nom) return tabbulles[i];
	}
	return null;
}

function cancelHideBulle()
{
	if (-1!=idTimeBul) clearTimeout(idTimeBul);
	idTimeBul=-1;
}
function startHideBulle(nomlay)
{
	if (-1!=idTimeBul) return;
	bulvis=nomlay;
	idTimeBul=setTimeout("doHideBulle()", tpsBulle);
}

function mouseOnBulle(e)
{
	cancelHideBulle();
	if (document.all) highlight(event.srcElement, true);
}
function mouseOutBulle(e)
{
	if (document.all)
	{
		startHideBulle(event.srcElement.id);
		highlight(event.srcElement, false);
	}
	else startHideBulle(e.target.name);
}
function highlight(bulle, onoff)
{
	if (document.all) {if (onoff) bulle.style.border="1px solid #808080";
	else bulle.style.border="1px solid #000000";}
}
function clicOnLink(e)
{
	return false;
}

function addBulle()
{
	var b=0;
	var tabnombul=new Array(document.anchors.length);
	var nbbulles=0;
	jsok=true;
	for (var i=0; i<document.anchors.length; i++)
	{
		if (-1!=document.anchors[i].name.indexOf("bul")) tabnombul[b++]=document.anchors[i].name;
	}
	nbbulles=b;
	b=0;
	for (i=0; (i<document.links.length)&&(b<nbbulles); i++)
	{
		if (-1!=document.links[i].href.indexOf("bulle"))
		{
			document.links[i].onmouseover=showBulle;
			document.links[i].onmouseout=hideBulle;
			document.links[i].onclick=clicOnLink;
		}
	}

	var tmpname="";
	var nomlay="";
	var squot="\"";
	for (var j=0; j<tabbulles.length; j++)
	{
		tmpname="b"+tabbulles[j].nom;
		if (document.all)
		{
			var htmlstr="<div id=\"b"+tabnombul[j]+"\" style=\"position:absolute; top:0; left:0; width:"+largeurBulle+";"+
				"visibility:hidden; border:1px solid #000000\" class=\"defbul\"><span class=\"titbul\" style=\"position:absolute; width:"+(largeurBulle-2)+";left:0;top:0\" onmouseover=\"window.event.cancelBubble=true\" onmouseout=\"window.event.cancelBubble=true\">"+tabbulles[j].titre+"</span><br>"+tabbulles[j].txt+"</div>";
			document.body.insertAdjacentHTML("BeforeEnd", htmlstr);
			tabbulles[j].nomlay="b"+tabnombul[j];
			document.all(tabbulles[j].nomlay).onmouseover=mouseOnBulle;
			document.all(tabbulles[j].nomlay).onmouseout=mouseOutBulle;
		}
		else
		{
			eval(tmpname+"=new Layer("+largeurBulle+", window)");
			eval(tmpname+".onmouseover=mouseOnBulle");
			eval(tmpname+".onmouseout=mouseOutBulle");
			eval(tmpname+".name=\""+tabnombul[j]+"\"");
			nomlay=eval(tmpname+".name");
			tabbulles[j].nomlay=nomlay;
			eval(tmpname+".document.open()");
			eval(tmpname+".document.write(\"<style>.titbul{background-color:#222222;color:#dddddd;font-family:arial,helvetica;font-size:9pt;padding:0px;margin:0px;text-align:center}</style>\")");
			eval(tmpname+".document.write(\"<style>.defbul{background-color:#000000;color:#ffffff;font-family:arial,helvetica;font-size:9pt;padding:2px;margin:0px;text-align:justify}</style>\")");
			eval(tmpname+".document.write(\"<table border=0 cellspacing=0 cellpadding=1 style=\\"+squot+"text-decoration:none\\"+squot+"><tr><td class=\\"+squot+"titbul\\"+squot+">"+tabbulles[j].titre+"</td></tr>\")");
			eval(tmpname+".document.write(\"<tr><td class=\\"+squot+"defbul\\"+squot+">"+tabbulles[j].txt+"</td></tr></table>\")");
			eval(tmpname+".document.close()");
		}
	}
}
window.onload=addBulle;

