jQuery.extend(jQuery.easing, { easeInOutQuad: function (x, t, b, c, d) { return ((t/=d/2)<1) ? c/2*t*t+b : -c/2*((--t)*(t-2)-1)+b; } });

$(document).ready(function()
{
  for (var a=0; a<Math.floor(Math.random()*5); a++)
    $('#HeroSlides li:last').after($('#HeroSlides li:first'));
  $('#HeroSlides ul').css({'left' : 0});

  var delay = 7000;
  var run = setInterval('rotate()', delay);

  $('#HeroSlides').hover(
    function() { clearInterval(run); },
    function() { run = setInterval('rotate()', delay); }
  );
});

$(document).unload(function()
{
  clearInterval(run);
});

function rotate()
{
  var width = $('#HeroSlides li').outerWidth();
  var left = parseInt($('#HeroSlides ul').css('left'))-width;

  $('#HeroSlides ul:not(:animated)').animate({'left' : left}, 250, 'easeInOutQuad', function () {
    $('#HeroSlides li:last').after($('#HeroSlides li:first'));
    $('#HeroSlides ul').css({'left' : 0});
  });
}
