/// Classe pour faire apparaitre une info bulle
/// paramètres :
/// element => element HTML sur lequel va être l'évenement faisant apparaitre l'infobulle
/// texte => texte à afficher dans l'infobulle
/// type => façon dont l'infobulle va se comporter : followMouse > suis souris, sinon s'affiche a coté de l'élément HTML

if(typeof(SuperClass)=='function'){Info_bulle.prototype = new SuperClass; /* héritage des méthodes */}
function Info_bulle(element, texte, type){	
	if(typeof(SuperClass)!='function'){alert("fichier SuperClass.js manquant!");}
	else{		
		/* héritage */
		this.classMere = SuperClass;  // classe parente
		this.classMere(); // appel du super constructeur
		delete this.classMere; // inutile de garder la classe parente
		if(type==undefined) type='followMouse';
		this.type=type;
		this.topMouse=15;
		this.leftMouse=5;
		this.element=element;
		this.texte=texte;
		this.className="new__div__info__bulle__"; /// classe CSS des infobulles (à designer dans feuille de style)
		this.divInfoBulle; /// élément HTML de l'infobulle
		this.init();
	}
}

/* renvoie position x en pixel de l'élément déclenchant l'infobulle */
Info_bulle.prototype.getX = function (){return this.calculeOffsetLeft(this.element);}

/* renvoie position y en pixel de l'élément déclenchant l'infobulle */
Info_bulle.prototype.getY = function (){return this.calculeOffsetTop(this.element);}

Info_bulle.prototype.creaDivInfoBulle= function (){
	this.divInfoBulle = document.createElement("div");
	this.divInfoBulle.style.position='absolute';
	this.cacheDivInfoBulle();
	//var texte=document.createTextNode(this.texte);
	
	this.divInfoBulle.className=this.className;
	document.getElementsByTagName("body")[0].appendChild(this.divInfoBulle);
	//this.divInfoBulle.appendChild(texte);
	this.divInfoBulle.innerHTML=this.texte;
}

Info_bulle.prototype.afficheDivInfoBulle= function (){this.divInfoBulle.style.display='block';}

Info_bulle.prototype.cacheDivInfoBulle= function (){this.divInfoBulle.style.display='none';}

Info_bulle.prototype.setPosition= function (event){
var top, left;

var tabXYscroll = new Array();
tabXYscroll=this.getScrollXY();

if(this.type=='followMouse'){
	var tempArray=new Array();
	tempArray=this.getMouseCoords(event);
	top=tempArray[1]+tabXYscroll[1]+this.topMouse;
	left=tempArray[0]+tabXYscroll[0]+this.leftMouse;
}
else{
	top=this.getY();
	left=(this.getX()+this.element.offsetWidth);
}

var tabXY = new Array();
tabXY=this.getViewSize();

var maxX=tabXYscroll[0]+tabXY[0];
var maxY=tabXYscroll[1]+tabXY[1];

if((left+this.divInfoBulle.offsetWidth)>=maxX){left=left-this.divInfoBulle.offsetWidth;}
if((top+this.divInfoBulle.offsetHeight)>=maxY){top=maxY-this.divInfoBulle.offsetHeight;}

if(left<tabXYscroll[0]){left=tabXYscroll[0];}
if(top<tabXYscroll[1]){top=tabXYscroll[1];}

this.divInfoBulle.style.left=left+'px';
this.divInfoBulle.style.top=top+'px';
}


Info_bulle.prototype.init= function (){
	this.creaDivInfoBulle();
	var localThis=this;
	var evt;
	if(this.type=='followMouse'){evt='mousemove';}
	else{evt='mouseover';}
	
	this.addEvent(this.element, evt, 
				function(event){
					localThis.afficheDivInfoBulle();
					localThis.setPosition(event);
				}
	);
	
	this.addEvent(this.element, 'mouseout', function(){localThis.cacheDivInfoBulle();});
}



/************* classe qui transforme l'attribut title d'un élément HTML, en infobulle ***********************/
if(typeof(SuperClass)=='function'){Title_2_info_bulle.prototype = new SuperClass; /* héritage des méthodes */}
function Title_2_info_bulle(classN){
	if(typeof(SuperClass)!='function'){alert("fichier SuperClass.js manquant!");}
	else{		
		/* héritage */
		this.classMere = SuperClass;  // classe parente
		this.classMere(); // appel du super constructeur
		delete this.classMere; // inutile de garder la classe parente

		this.classN=classN; ////// nom de class CSS des elements
		this.tabElem = new Array();
		this.init();
	}
}


Title_2_info_bulle.prototype.getTitle = function(element){
	if(element){if(element.title){return element.title;}}
}

Title_2_info_bulle.prototype.resetTitle = function(element){
	if(element){
		if(element.title){
			element.removeAttribute("title");
			if(document.all){ /// si IE
				var tabImg=new Array();
				tabImg=element.getElementsByTagName("img");
				var nbImg=tabImg.length;
				for(var i=0;i<nbImg;i++){
					tabImg[i].removeAttribute("alt"); /// suppr alt des images enfants, pour pas que IE l'affiche
				}
			}
		}
	}
}

Title_2_info_bulle.prototype.init = function (){
var localThis=this;
	this.addEvent(window,"load",
		function(){
			localThis.tabElem = localThis.getElementsByClassName(localThis.classN);
			var nb=localThis.tabElem.length;
		
			for(var i=0;i<nb;i++){
				var element=localThis.tabElem[i];
				var title=localThis.getTitle(element);
				localThis.resetTitle(element);
				new Info_bulle(element, title);
			}
		}
	);
}


