/* 
 * FactureBook : sliderIt Plugin
 * @author Mohamed BENARROUDJ <mohamed.benarroudj@laposte.net>
 * @copyright   2010 Mohamed BENARROUDJ - All rights reserved
 */
(function($)
{
  $.fn.sliderIt = function(callback)
  {
    $(this).find('a.scroll').draggable(
    {
      grid:[8,0], 
      axis:"x", 
      containment:"parent",
      drag: function(event, ui)
      {
        if( ui.position.left <= 0 )
        {
          $(this).css('left', 0);
          ui.position.left = 0;
        }
        else if( ui.position.left >= 120 )
        {
          $(this).css('left', 120);
          ui.position.left = 120;
        }
         
        $(this).prev().css('width', ui.position.left+'px');
        var value = Math.round((ui.position.left/8)*10);
        $(this).next().html('à <span class="noir">'+value+' Km</span> autour');
      },
      stop: function(event, ui)
      { 
         $(this).parent().parent().find('input:hidden').val(Math.round((ui.position.left/8)*10)); 
         
         if( typeof(callback) == 'function' )
             callback();
      }
    });
  }
})(jQuery);
