function slideshowInstance(){};
slideshowInstance.prototype = {
  config : {
    autoPlay : true,
    stopping: false,
    slideDelay : 2000,
    fadeDelay : 3000
  },
  init : function(options) {
    var o = this;
    o.played = false;
    o.slides = $j('#Slideshow img');
    o.count = 1;
    o.totalSlides = o.slides.length;
    o.config.autoPlay = options.autoPlay;
    o.render();
  },
  render : function() {
    var o = this;
    o.reset();
		//Only run slide show if there is more than one image to cycle through
		if(o.slides.length > 1){
			if(o.config.autoPlay == true) { o.play(); }
		}
  },
  reset : function() {
    var o = this;
    o.lastSlide = null;
    o.stopping = false;
    if(o.played == false) {
      o.played = true;
      o.slides.each(function(i){
        var z = i;
        $j(this).css({
          zIndex: z,
          left: '652px',
          display: 'block'
        });
      });
      o.slides.eq(0).animate({left: '0px'}, o.config.fadeDelay);
    }
    else {
      o.slides.each(function(i){
        var z = i;
        if(i == 0) { $j(this).css({left: '0px'}); }
        else {
          $j(this).css({
            zIndex: z,
            left: '621px',
            display: 'block'
          });
        }
      });
    }
  },
  play: function() {
    var o = this;
    o.count = 1;
    o.reset();
    o.next();
  },
  next : function() {
    var o = this;
    window.setTimeout(nextDelay,o.config.slideDelay);
    function nextDelay() {
      o.slide(o.slides.eq(o.count));
      o.count++;
    }
  },
  slide : function(currentSlide){
    var o = this;
    var temp = o.totalSlides;
    if (o.stopping == true) {
      o.stopShow();
    }else {
      if(o.count < temp) {
        currentSlide.animate({left: '0px'}, o.config.fadeDelay, function(){
        o.currentSlide = currentSlide;
        if(o.lastSlide) { if(o.lastSlide.hasClass('hidden') == true) { o.lastSlide.hide(); } }
        o.lastSlide = currentSlide;
        o.next();
        });
      }
      else {
        o.lastSlide.animate({opacity: 'hide'}, o.config.fadeDelay, function() { o.play(); });
      }
   }
  },
  stop : function() {
    var  o = this;
    o.stopping = true;
  },
  stopShow : function() {
    var  o = this;
    if(o.lastSlide) {
      if(o.lastSlide.hasClass('hidden') == true) {
        o.lastSlide.animate({opacity: 'hide'},o.config.fadeDelay,function() {
          o.reset();
           o.slides.stop();
        });
      }
    }
   
  }
}

