jQuery(document).ready(function(){
   
   window.OFFSET_BUBBLE_X = -41;
   
   $(".suivi_don").each(function(){
      var dons = parseInt($(this).attr('dons'));
      var objectif = parseInt($(this).attr('objectif'));
      var pourcentage = 1.0 - (dons / objectif);
      
      var totalWidth = 236; //$(".don_photo img", this).width();
      var width = Math.round(totalWidth * pourcentage);
      
      // Ajustement de la taille du fading
      $(".don_photo .fade", this).animate({ width: width+'px' }, {
         duration: 5000,
         step: updateBubblePos
      });
   })
   .hover(
      function(event){
         $(".don_photo .don_bulle", this)
            .css('left', getBubblePosX(this))
            .fadeIn();
      }, 
      function(event){
         $(".don_photo .don_bulle", this).fadeOut();
      }
   )
   .click(function(){
      var href = $(".don_bulle a", this).get(0).href;
      window.location.href = href;
      return true;
   })
   
   
   function updateBubblePos(p)
   {
      var obj_don = $(this).parent().parent();
      $(".don_bulle", obj_don).css('left', getBubblePosX(obj_don));
   }
   
   function getBubblePosX(obj_don)
   {
      var posX = $(".don_photo .fade", obj_don).position().left;
      return posX + OFFSET_BUBBLE_X;
   }
   
});