var speed = 0;
var content;
var scrollTimer;

$(document).ready(function() {
  
  content = $(".slider")
  $("#arrowLeft").mousedown(function() {
    startScroll( -25 )
  });
  $("#arrowRight").mousedown(function() {
    startScroll( 25 )
  });
  
  $(".numbers li a").click(function() {
    stopScroll(true);
    var img = $(".slider img:eq("+this.rel+")")
    var pos = img.position().left;
    content.animate({ scrollLeft: pos }, 600);
    return false;
  });
  
  $(document).mouseup(function() {
    stopScroll(false);
  });
  
  
 // content.css("overflow", "auto");
});

function startScroll( amount)
{
  speed = 0
  if(scrollTimer) {
    clearInterval(scrollTimer)
  }
  scrollTimer = setInterval("scroll("+amount+")",20);
}

function stopScroll(now)
{
  if(scrollTimer) {
    clearInterval(scrollTimer)
  }
  if(now) {
    speed = 0;
  } else {
    scrollTimer = setInterval("scroll(0)",20);
  }
}

function scroll( amount ) 
{
  speed += ( amount - speed ) / 25
  
  if( Math.round(speed) == 0) {
    speed = 0;
    clearInterval(scrollTimer)
  }
  
  
      
  content.scrollLeft( content.scrollLeft() + speed )
}


