/**************/
/* Info Bulle */
/**************/
// Déclaration du plugin
(function ($)
{
  $.fn.info_bulle = function (options)
  {
    debug ('nb objet(s) : ' + this.size ());
    
    // On écrase les options par défaut si ils sont surchargées en paramètre
    var opts = $.extend ({}, $.fn.info_bulle.defaults, options);
    
    // On parcours tous les objets
    return this.each (function ()
    {
      var $this = $ (this);
      
      // On écrase les options par défaut si ils sont surchargées pour cet objet
      var o = $.extend ({}, opts);
      o = $this.attr ('bgColor') ? $.extend (o, { 'bgColor' : $this.attr ('bgColor')}) : o;
      o = $this.attr ('color') ? $.extend (o, { 'color' : $this.attr ('color')}) : o;
      o = $this.attr ('fontSize') ? $.extend (o, { 'fontSize' : $this.attr ('fontSize')}) : o;
      o = $this.attr ('followMouse') ? $.extend (o, { 'followMouse' : $this.attr ('followMouse')}) : o;
      
      // Création de l'info-bulle
      $this.after ('<span />');
      $this.next ('span').css ({
        display: 'none',
        zIndex: '999',
        position: 'absolute',
        backgroundColor: o.bgColor,
        color: o.color,
        fontSize: o.fontSize,
        padding: "6px 12px"
      });
      $this.next ('span').html ($this.attr (o.attributTexte));
      $this.removeAttr (o.attributTexte);
      if (o.attributTexte != 'title')
        $this.removeAttr ('title');
      
      // Définition des actions
      $this.hover (function (e) 
      {
        $this.next ('span').fadeIn ('fast');
        $this.next ('span').offset ({
          top: e.pageY,
          left: e.pageX + 10
        });
      }, function () 
      {
        $this.next ('span').fadeOut ('fast');
      });
      
      // Positionnement de l'info-bulle
      if (o.followMouse === true)
      {
        $this.mousemove (function (e)
        {
          $this.next ('span').offset ({
            top: e.pageY,
            left: e.pageX + 10
          });
        });
      }
    });
  };
  
  // function privée pour débuggage
  function debug ($message)
  {
    if (window.console && window.console.log)
      window.console.log ('taojquery - info_bulle : ' + $message);
  };
  
  // options par défaut
  $.fn.info_bulle.defaults = {
    bgColor: '#000000',
    color: '#FFFFFF',
    fontSize: '12px',
    attributTexte: 'info_bulle',
    followMouse: true
  };
})(jQuery);

// Appelle du plugin
// Toutes les balises ayant un attribut info_bulle
$ (document).ready (function ()
{
  $ ('[info_bulle]').info_bulle ();
});
