$(function() {
  var timer;
  
  function scrollContainerTo(container, i) {
    container.scrollTo('li:eq(' + i + ')', 1500);
  }

  function scrollToCurrent() {
    // Wrap around if we hit the end
    if(current >= $("ul.slideShow li").length) {
      current = 0;
    }
    
    if (current < 0) {
      current = $("ul.slideShow li").length - 1;
    }
    
    scrollContainerTo($("ul.slideShow"), current);
  }

  current = 0;
  
  $(".right a").click(function(){
    current++;
    scrollToCurrent();
    clearTimeout(timer);
  });
  
  $(".left a").click(function(){
    current--;
    scrollToCurrent();
    clearTimeout(timer);
  });
  
  // For our timer to use
  function swap() {
    current++;
    scrollToCurrent();
    timer = setTimeout(swap, 5000);
  }
  timer = setTimeout(swap, 7000);
});

