OPE = (window.opera)?true:false;
IE  = (document.all && !OPE)?true:false;
MOZ = (document.getELementById && !IE)?true:false;

if(!IE) document.captureEvents(Event.MOUSEMOVE);

function infoBulle(){
  // Creation des conteneurs
  d = document.getElementsByTagName("body");
  body = d[0];
  this.mainIB     = document.createElement('div');
  this.mainIB.id  = "infoBulle";
  this.mainIB.style.position = "absolute";
  this.mainTXT    = document.createElement('div');
  this.mainTXT.id = "insideBulle";
  this.mainIB.appendChild(this.mainTXT);
  body.appendChild(this.mainIB);
  
  //Decallage de l'infobulle
  this.decY = 20;
  this.decX = 0;
  
  //Prise en compte de l'attribut alt
  this.enableAlt = false;
  
  //L'infobulle doit-elle suivre la souris
  this.enableDrag = true;
  
  //Largeur de l'infobulle
  this.width = 210;
  
  //Régles de formatage
  this.format = new Array();
}

infoBulle.prototype.registerPointer = function(src){
  this.pointeur = document.createElement('img');
  this.pointeur.src = src;
  this.pointeur.style.position = "absolute";
  this.pointeur.style.top = 1 - this.pointeur.height + "px";
  this.mainIB.appendChild(this.pointeur);
}

infoBulle.prototype.registerFormat = function(rxp,str){
  if(typeof(rxp) == "function" || typeof(rxp) == "object"){
    this.format.push(new Array(rxp,str));
  }
}

infoBulle.prototype.setTo = function(obj,addtxt){
  if(!window.ibvar) window.ibvar = this;
  if(!obj.ibtxt) obj.ibtxt = (addtxt == undefined)?'':addtxt;
  
  obj.onmouseover = function(){
    txt = (window.ibvar.enableAlt && this.alt != "" && this.alt != undefined)? this.alt : this.title ;
    nbr = window.ibvar.format.length;
    for(i=0; i<nbr; i++){
      txt = txt.replace(window.ibvar.format[i][0],window.ibvar.format[i][1])
    }
    window.ibvar.setText(txt + this.ibtxt);
    this.st = this.title;
    this.title = '';
    if (window.ibvar.enableAlt && this.alt != undefined){
      this.sa = this.alt;
      this.alt = '';
    }
    if(window.ibvar.enableDrag = true) window.ibvar.startDrag();
    window.ibvar.showHide('show');
  }
  
  obj.onmouseout = function(){
    this.title = this.st;
    if (window.ibvar.enableAlt && this.sa != undefined){
      this.alt = this.sa;
    }
    window.ibvar.showHide('hide');
    window.ibvar.stopDrag();
  }
}

/* Méthodes privées */

infoBulle.prototype.setText = function(txt){
  this.mainTXT.innerHTML = txt;
}

infoBulle.prototype.showHide = function(dsp){
  shb = this.mainIB.style;
  if(dsp == undefined){
    shb.display = (shb.display == "block")?"none":"block";
  } else {
    shb.display = (dsp == 'show')?"block":"none";
  }
}

infoBulle.prototype.startDrag = function(){
  if(!window.ibvar) window.ibvar = this;
  document.onmousemove = function(e){
    X = (IE)?event.clientX:e.pageX;
	  Y = (IE)?event.clientY:e.pageY;
	  window.ibvar.mainIB.style.top  = (Y+window.ibvar.decY) + "px";
	  W = body.clientWidth;
	  M = W - window.ibvar.width;
	  window.ibvar.mainIB.style.left = Math.round(M*X/W) + window.ibvar.decX + "px";
	  if(window.ibvar.pointeur){
	    pos = X - Math.round(M*X/W) - Math.floor(window.ibvar.pointeur.width/2)
	    if(pos < 7) pos = 7;
	    if(pos > window.ibvar.width-7-window.ibvar.pointeur.width) pos = window.ibvar.width-7-window.ibvar.pointeur.width;
      window.ibvar.pointeur.style.left = pos + "px";
    } 
  }
}

infoBulle.prototype.stopDrag = function(){
  document.onmousemove = function(e){};
}

