/* Begin Slideshow */
var slideshow = {
	
	timerInt: 8000,
	fadeTime: 400,
	idx: 1,
	currentSlide: 1,
	controls: $('.slideshow_controls'),
	numslides: 0,
	getNumSlides: function(){
	  var slides = $('.SS_item');
	  this.numslides = slides.length - 1;
	},
	nextSlide: function(){
        // determine the next slide number
            var nextSlide;
            if (this.currentSlide == (this.numslides - 1)) {
                nextSlide = 0;
            } else {
                nextSlide = this.currentSlide + 1;
            }
/*             console.log('next: '+nextSlide); */
	
	    this.idx = nextSlide;
        this.changeactiveslide(nextSlide);
	},
	prevSlide: function(){
	  // determine the next slide number
	      var nextSlide;
	      if(this.currentSlide == 0) {
	          nextSlide = this.numslides - 1;
	      } else {
	          nextSlide = this.currentSlide - 1;
	      }
	      
	      this.idx = nextSlide;
	      this.changeactiveslide(nextSlide);
	},
	init: function(){
		this.getNumSlides();
		this.currentSlide = 1;
	},
	
	changeactiveslide: function(id){
		var newSlideID		= "#SS_item_"+id;
		this.currentSlide   = id;

		var currentSlide = $('.SS_active_item');
		
        currentSlide.fadeOut(slideshow.fadeTime,function(){
		  currentSlide.remove();
		  $(newSlideID).clone().addClass('coming_up').prependTo("#SS_viewport").addClass('SS_active_item').removeAttr('id').hide().fadeIn(slideshow.fadeTime,function(){
		      $('.coming_up').removeClass('coming_up');
		  
		  });		
		});
		
		// set the current id to the selected slide
		this.idx	= id;
	},
	changeslide: function(id) {
	
	  if(id == (this.numslides)) {
        this.changeactiveslide(1);
	  } else {
	    this.changeactiveslide(id+1);
	  }
	},
	showcontrols: function() {
        $('.slideshow_controls').stop().fadeTo(400,1);
	},
	hidecontrols: function() {
        $('.slideshow_controls').stop().fadeTo(400,0);
	}

	
} // end var waterslide


var slidetimer;

function starttimer() {
	slidetimer		= setInterval(function(){slideshow.changeslide(slideshow.idx)},slideshow.timerInt);
}

function cleartimer() {
	clearInterval(slidetimer);
}

starttimer();
slideshow.init();

