loader.addOnLoad(function () {
   var areas = document.getElementsByTagName('area');
   for (var i = 0; i < areas.length; i++) {
      if (areas[i].parentNode.id == 'mapCommunes' && areas[i].title.length != 0) {
         new InfosBulles(areas[i]);
      }
   }
});
function InfosBulles(area) {
   this.area = area;
   this.texte = area.title;
   this.ville = this.habs = this.superficie = this.densite = false;
   this.area.removeAttribute('title');
   this.analyserTitle();
   this.creerInfoBulle();
   
   this.DECALAGE_X = 10;
   this.DECALAGE_Y = -5;
   this.DELAY_OUT  = 0;
   this.timerOut   = null;
   
   var objet = this;
   this.area.onmouseover = function (e) { objet.afficher(e); return false; };
   this.area.onmouseout = function () { objet.mouseout(); };
}
InfosBulles.prototype.analyserTitle = function () {
   if (this.texte.indexOf(', ') == -1) {
      this.ville = this.texte;
      return;
   }
   var textes = this.texte.split(', ');
   this.ville = textes[0];
   this.habs  = textes[1];
   if (textes[2]) {
      this.superficie = textes[2];
   }
   if (textes[3]) {
      this.densite = textes[3];
   }
};
InfosBulles.prototype.creerInfoBulle = function () {
   this.div = document.createElement('div');
   this.div.className = "infoBulleCommunes";
   this.div.innerHTML = '<span>' + this.ville + '</span>';
   if (this.habs !== false) {
      this.div.innerHTML += '<br><b>Population :</b> ' + this.habs;
   }
   if (this.superficie !== false) {
      this.div.innerHTML += '<br><b>Superficie :</b> ' + this.superficie;
   }
   if (this.densite !== false) {
      this.div.innerHTML += '<br><b>Densité :</b> ' + this.densite;
   }
   document.body.appendChild(this.div);
};
InfosBulles.prototype.afficher = function (e) {
   if (!e && window.event) {
      e = window.event;
   }
   if (this.timerOut) {
      clearTimeout(this.timerOut);
   }
   this.div.style.display = "block";
   this.placer(e);
   var objet = this;
   this.area.onmousemove = function (e) { objet.placer(e); };
};
InfosBulles.prototype.mouseout = function () {
   var objet = this;
   this.timerOut = setTimeout(function () { objet.cacher(); }, this.DELAY_OUT);
};
InfosBulles.prototype.cacher = function () {
   this.div.style.display = "none";
   this.area.onmousemove = null;
   clearTimeout(this.timerOut);
};
InfosBulles.prototype.placer = function (e) {
   if (!e && window.event) {
      e = window.event;
   }
   var x = e.clientX + this.DECALAGE_X;
   var y = e.clientY + this.DECALAGE_Y - this.div.offsetHeight;
   this.div.style.top = y + (document.documentElement.scrollTop || document.body.scrollTop) + "px";
   this.div.style.left = x + (document.documentElement.scrollLeft || document.body.scrollLeft) + "px";
};