/* SIMPLE SLIDER 1.0.0
    Example Usage:
    $('.slider').slideshow({    
      loops: 20,        // how many times the whole slideshow loops
      speed: 2000,      // the in/out speed of the transition
      timeout: 5000,     // length between transitions
      ease : easeOutQuad
    });
*/
(function($) {
  $.fn.slideshow = function(options) {
    var opts = $.extend({}, $.fn.slideshow.defaults, options);
    // iterate and reformat each matched element
    return this.each(function() {
      var obj = $(this);
      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
      var slidescontainer = obj.find('.slides');
      var slides = slidescontainer.children();
      var navs = obj.find('.slider-navigation').find('a');
      var captions = obj.find('.slider-captions').find('.caption');
      var currentslide = 0;
      var loopcount = 0;
      var slidetimer;
      function doslide(slideid){
        slides.eq(slideid).fadeIn(o.speed);
        if ( currentslide != 0 ){slides.eq(currentslide).fadeOut(o.speed);}
        captions.eq(slideid).fadeIn(o.speed);
        captions.eq(currentslide).fadeOut(o.speed);
        navs.eq(slideid).parent('li').addClass('active');
        navs.eq(currentslide).parent('li').removeClass('active');
        currentslide = slideid;
        loopcount ++;
        timer();
      };
      function timer(){
        slidetimer = setTimeout(function(){
          if (loopcount <= (o.loops*slides.length)-1 ){
            if( currentslide == slides.length -1 ){doslide(0);} else {
              doslide(currentslide + 1);
            }
          } else {clearTimeout(slidetimer);}
        }, o.timeout);
      }
      navs.each(function(i){
        $(this).click(function(){
          loopcount = (o.loops*slides.length);
          doslide(i);
          return false;
        });
      });
      timer();
    });
  };
  
$.fn.slideshow.defaults = {
  loops: 10,             // how many times the whole slideshow loops
  speed: 1000,          // the in/out speed of the transition
  timeout: 5000        // length between transitions
};
})(jQuery);














