/**
 * DEPRECATED
 * Utilisez plutôt jquery.alert.js
 * 
* Tommy Brière
* Productions Vic Pelletier tous droits réservées
* Afficher des belles boites de dialogues
*
* AVERTISSEMENT: Ce fichier contient un memory probablement un memory leak.
*			Éviter de créer trop d'instances de Tooltips
*
* Nécessite:
* YAHOO.yahoo
* YAHOO.event
**/

var objectRepository;

function ObjectRepository(){
this.objs=[];
this.id=0;}

ObjectRepository.prototype.add= function(obj){
this.id++;
var id= this.id;
this.objs[id-1]= obj;
return id;}

ObjectRepository.prototype.remove= function(id){
this.objs[id-1]= null;}

ObjectRepository.prototype.get= function(id){
return this.objs[id-1];}
objectRepository= new ObjectRepository();
toolTips= new ObjectRepository();

function toolTipCheckDom(){
for(var i=0; i< toolTips.objs.length; i++){
var t= toolTips.objs[i];
if(t){
t.checkDom();}}}

function ToolTip(msg, cibles){
this.msg= msg;
this.cibles= cibles;
this.over= false;
this.etat= 0;
this.dir=0;
this.timer=null;
this.divid=null;
this.fps= 1/30;
this.dureeAnim= 120;
this.inc=(1000 / this.dureeAnim) * this.fps;
this.fpm= Math.round(1000*this.fps);
this.rp= 0;
this.addHandlers();
this.tid= toolTips.add(this);}

ToolTip.prototype.clean= function(){
this.rmTimer();
this.removeHandlers();
this.rmFromDom();
objectRepository.remove(this.id);
toolTips.remove( this.tid );}

ToolTip.prototype.checkDom= function(){
for(var i=0; i< this.cibles.length; i++){
var cible= this.cibles[i];
if(! cible.offsetParent ){
this.clean();
return;}}}

ToolTip.prototype.addHandlers= function(){
YAHOO.util.Event.addListener(this.cibles,"mouseover" , this.onOver, this);
YAHOO.util.Event.addListener(this.cibles,"mouseout" , this.onOut, this);}

ToolTip.prototype.removeHandlers= function(){
YAHOO.util.Event.removeListener(this.cibles,"mouseover" , this.onOver, this);
YAHOO.util.Event.removeListener(this.cibles,"mouseout" , this.onOut, this);}

ToolTip.prototype.onOut= function(e, obj){
this.over= false;
obj.update();}

ToolTip.prototype.onOver= function(e, obj){
this.over= true;
obj.update();}

ToolTip.prototype.isOver= function(){
for(var i=0; i< this.cibles.length; i++){
var cible= this.cibles[i];
if(cible.over){
return true;}}
return false;}

ToolTip.prototype.update= function(){
var over= this.isOver();
if(over){
if(this.etat< 1){
this.dir= this.inc;
if(this.addToDom()){
this.addTimer();}}} else{
if(this.etat> 0){
this.dir=-this.inc;
this.addTimer();}}}

ToolTip.prototype.posittione= function(cible, div, coords){
coords[0]-=180;
coords[1]-= div.offsetHeight;
return coords;}

ToolTip.prototype.positionnneEnHaut= function(cible, div, coords){
coords[0]+= 25;
coords[1]-= div.offsetHeight;
return coords;}

ToolTip.prototype.addToDom= function(){
if(this.divid==null){
var div= document.createElement("div");
var id= YAHOO.util.Event.generateId(div);
div.id= id;
div.style.opacity= 0;
var cible= this.cibles[0];
var coords= YAHOO.util.Dom.getXY(cible);
if(coords[0]> 210){
div.className="toolTip";
var divTop= document.createElement("div");
divTop.className="top-tooltip";
var divWrapper= document.createElement("div");
divWrapper.className="wrapper-tooltip";
var divBottom= document.createElement("div");
divBottom.className="bottom-tooltip";
var divFleche= document.createElement("div");
divFleche.className="fleche";
var msg= remplacer( this.msg,"\n" ,"<br />" );
var msg= remplacer( msg,"\r" ,"" );
divWrapper.innerHTML= msg;
document.body.insertBefore(div, document.body.firstChild);
div.appendChild(divTop);
div.appendChild(divWrapper);
div.appendChild(divBottom);
div.appendChild(divFleche);} else{
div.className="toolTipG";
var divTop= document.createElement("div");
divTop.className="top-tooltip";
var divWrapper= document.createElement("div");
divWrapper.className="wrapper-tooltip";
var divBottom= document.createElement("div");
divBottom.className="bottom-tooltip";
var divFleche= document.createElement("div");
divFleche.className="fleche";
divWrapper.innerHTML= this.msg;
document.body.insertBefore(div, document.body.firstChild);
div.appendChild(divTop);
div.appendChild(divWrapper);
div.appendChild(divBottom);
div.appendChild(divFleche);}
this.divid= id;
divWrapper.style.height= divWrapper.offsetHeight;
if(coords[0]> 210){
coords= this.posittione(cible, div, coords);} else{
coords= this.positionnneEnHaut(cible, div, coords);}
YAHOO.util.Dom.setXY(div, coords);} else{}
return true;}

ToolTip.prototype.rmFromDom= function(){
if(this.divid!=null){
var div= $w(this.divid);
document.body.removeChild(div);
this.divid=null;}}

ToolTip.prototype.addTimer= function(){
if(this.timer==null){
if(this.rp==0){
this.rp= objectRepository.add(this);}
this.timer= setInterval(" objectRepository.get("+this.rp+").animer(); ", this.fpm);
this.animer();}}

ToolTip.prototype.animer= function(){
this.etat+= this.dir;
if(this.etat< 0){
this.etat= 0;
this.rmTimer();
this.dir=0;
this.rmFromDom();} else if(this.etat> 1){
this.etat= 1;
this.dir=0;
this.rmTimer();
this.updateOpacity();} else{
this.updateOpacity();}}

ToolTip.prototype.updateOpacity= function(){
var div= $w(this.divid);
if(div){
div.style.opacity= this.etat;}}

ToolTip.prototype.rmTimer= function(){
if(this.timer!=null){
clearInterval(this.timer);
this.timer= null;}}

function PopUpHtml(html, x, y, width, height){
var me= this;
var divid=null;
me.html= html;
me.x= x;
me.y= y;
me.width= width;
me.height= height;

var init= function(){
me.addToDom();}

this.addToDom= function(){
if(me.divid==null){
var div= document.createElement("div");
var id= YAHOO.util.Event.generateId(div);
div.id= id;
div.className="ajaxpopup";
div.style.width= me.width+"px";
div.innerHTML= me.html;
document.body.appendChild(div);
me.divid= id;
YAHOO.util.Dom.setXY(div,[me.x, me.y]);} else{}
return true;}

this.rmFromDom= function(){
if(me.divid!=null){
var div= $w(me.divid);
document.body.removeChild(div);
me.divid=null;}}

this.close= function(){
me.rmFromDom();
toolTipCheckDom();}
init();}