//var dist;

function scroll_images(element)
{
  // time for each picture to move one space in milliseconds
  var speed = 1500;

  // get the first element
  var first = $("#"+element).children().eq(0);

  // get margin value, used to continue animation after pause
  var marginLeft = first.css("margin-left");

  // remove the px from margin left
  marginLeft = parseFloat(marginLeft.substr(0, marginLeft.length - 2));
  if(isNaN(marginLeft)) marginLeft = 0;
  
  var dist = $(first).width()+10;
  
  //alert(dist);
  
  // speed must be 75 pixels a second
  var dist_left = dist + parseFloat(marginLeft);
  var time = (dist_left / 75) * speed;
  //alert(time);
  
  // work out how much time is left in the animation
  var animationTime = ((dist + (parseFloat(marginLeft))) / dist) * speed;

  first.animate({marginLeft: -dist}, time, "linear", function()
  {
    $(this).css("margin-left", "0px");
    $(this).appendTo($("#"+element));
    scroll_images(element);
  });
}
  
$(document).ready(function()
{
  $("#all_scroll_container").css({width: "1920px", height: "100px"});
  scroll_images("all_scroll_container");
  
  $("#all_scroll_container").hover(
  function()
  {
    $("#all_scroll_container").children().eq(0).stop();
  },
  function()
  {
    scroll_images("all_scroll_container");
  });
});