$(document).ready(function () {
  
  $('.continuousScroll').continuousScroll();
  
});

(function () {
    // The idea of this function is to continuously scroll elements to the
    // left, pausing on mouse over.
    // The effect is achieved by giving the first element a negative left margin, until it goes out of view, and then removing it and adding it to the far end of the list.
    $.fn.continuousScroll = function () {

        return this.each(function () {

          var $wrapper = $('> div', this).css('overflow', 'hidden'),
              $slider = $wrapper.find('> ul').width(9999),
              $items = $slider.find('> li'),
              $single = $items.filter(':first');

          var singleWidth = $single.outerWidth(),
              viewportWidth = $wrapper.innerWidth(),
              fullyVisible = Math.floor( viewportWidth / singleWidth);
              
              // the additional single with is added as the first element will
              // slide off the screen
              initialClones = Math.ceil((viewportWidth+singleWidth)/($items.length*singleWidth));
              if (initialClones>0) {
                for (var i=0; i < initialClones; i++) {
                  $items.filter(':last').after($items.clone());
                };
              };

          slide = function(){

          $slider.mouseover(function () {
              sliding = false;
              items.filter(':first').stop(true);
              return;
          });

          slidetime = 10000;//the shorter the time the more cpu usage (to a point)
          sliding = true;
            items = $slider.find('> li')
            first = items.filter(':first');
             
            first.animate({marginLeft:-(singleWidth)},
              slidetime-Math.abs((first.css('marginLeft').slice(0,-2)/197))*slidetime
            ,'linear',function(){
              items.filter(':last').after(first.css({marginLeft:0}));
              slide();
            }  
            );
          };
          
          mouseover = sliding = false; 
          $('a',$slider).mouseover(function () {
              mouseover = true;
          }).mouseout(function () {
            mouseover = false;
          });
          
          slide();
          setInterval(function () {
              if (false === sliding && false === mouseover) {
                  slide();
              }
          }, 200);
          
        });
    };
})(jQuery);