/* couche de compatibilité avec AffBulle() */
function AffBulle(texte, evt) {
	AffBulle.myib = AffBulle.myib || new InfoBulle();
	AffBulle.myib.show(texte, evt);
}
function HideBulle() {
	AffBulle.myib = AffBulle.myib || new InfoBulle();
	AffBulle.myib.hide();
}
function InitBulle(ColTexte,ColFond,ColContour,NbPixel) {
	AffBulle.myib = new InfoBulle();
}

/* couche de compatibilité avec show_box() */
function show_box(e,msg,alpha_ratio) {
	show_box.myib = show_box.myib || new InfoBulle();
	show_box.myib.show(msg, e);
}
function hide_box() {
	show_box.myib = show_box.myib || new InfoBulle();
	show_box.myib.hide();
}

/* couche de compatibilité avec smart_show_box() */
function smart_show_box (e, msg) {
	smart_show_box.myib = smart_show_box.myib || new InfoBulle();
	smart_show_box.myib.show(msg, e);
}
function smart_hide_box() {
	smart_show_box.myib = smart_show_box.myib || new InfoBulle();
	smart_show_box.myib.hide();
}

/***********************************************/
/* replaceSelect (Bug IE select always on top) */
/***********************************************/
function replaceSelect (r) {
	if (check_nav(true) != "IE6") {return true;}
	replaceSelect.rslct = replaceSelect.rslct || Array ();
	replaceSelect.slctDisplay = replaceSelect.slctDisplay || Array ();
	if (r == true) {
		slct = document.getElementsByTagName("select");
		if (slct.length != replaceSelect.rslct.length) {
			for (i=0; i<replaceSelect.rslct.length; i++) {
				replaceSelect.rslct[i].parentNode.removeChild(replaceSelect.rslct[i]);
			}
			for(i=0; i<slct.length; i++) {
				replaceSelect.rslct[i] = document.createElement("input");
				replaceSelect.rslct[i].setAttribute("type", "text");
				replaceSelect.rslct[i].style.display = "none";
				replaceSelect.rslct[i].disabled = true;
				replaceSelect.rslct[i].width = slct[i].offsetWidth;
				replaceSelect.rslct[i].height = slct[i].offsetHeight - 2;
				slct[i].parentNode.insertBefore(replaceSelect.rslct[i], slct[i]);
			}
		} 
		for(i=0; i<slct.length; i++) {
			replaceSelect.slctDisplay[i] = slct[i].style.display;
			if (slct[i].style.display != "none") {
				slct[i].style.display = "none";
				replaceSelect.rslct[i].style.display = replaceSelect.slctDisplay[i];
				replaceSelect.rslct[i].disabled = false;
				try {value = slct[i].options[slct[i].selectedIndex].childNodes[0].data;} catch (e) {value = "";}
				replaceSelect.rslct[i].setAttribute("value", value);
			}
		}
	} else {
		for(i=0; i<slct.length; i++) {
			slct[i].style.display = replaceSelect.slctDisplay[i];
			replaceSelect.rslct[i].disabled = true;
			replaceSelect.rslct[i].style.display = "none";
		}
	}
	return true;
}

/*******************/
/* Class InfoBulle */
/*******************/

function InfoBulle () {this.init();}
InfoBulle.prototype.init = function () {
	this.ib = document.createElement("div");
	this.ib.className = "sunSetStyleInfoBulle";
	document.body.appendChild(this.ib);
}

InfoBulle.prototype.show = function (content, evt) {
    replaceSelect(true); // BUG IE
	if (content == null || content.lenght == 0) {
		this.hide();
		return;
	}
	this.ib.innerHTML = content;
	var magicNumber = 25;
	if (window.innerWidth) { /* pour les navigateurs standards */
		this.ib.style.left = (window.innerWidth > evt.clientX + 10 + this.ib.offsetWidth + magicNumber)? window.pageXOffset + evt.clientX + 10 : window.pageXOffset + evt.clientX - 10 - this.ib.offsetWidth;
		this.ib.style.top = (window.innerHeight > evt.clientY + 10 + this.ib.offsetHeight + magicNumber)? window.pageYOffset + evt.clientY + 10 : window.pageYOffset + evt.clientY- 10 - this.ib.offsetHeight;
	} else { /* pour IE */
		evt = window.event;
		this.ib.style.left = (document.body.offsetWidth > evt.x + 10 + this.ib.offsetWidth + magicNumber) ? document.body.scrollLeft + evt.x + 10 : document.body.scrollLeft + evt.x - 10 - this.ib.offsetWidth; 
		this.ib.style.top = (document.body.offsetHeight > evt.y + 10 + this.ib.offsetHeight + magicNumber) ? document.body.scrollTop + evt.y + 10 : document.body.scrollTop + evt.y - 10 - this.ib.offsetHeight;
	}
    this.ib.style.visibility = "visible";
}

InfoBulle.prototype.hide = function () {
	this.ib.style.visibility="hidden";
	this.ib.innerHTML = "";
	this.ib.style.left = 0;
	this.ib.style.top = 0;
	replaceSelect(false); // BUG IE
}

