// JavaScript Document
//*** INITIALIZE OBJECTS
$(document).ready(function(){ 

	Testimonials.init(); 
	
});

//*** TESTIMONIALS
var Testimonials = {
	
	// you can touch these
	fadeSpeed: 700,
	intervalSpeed: 9000,
	elements: "div.testimonials blockquote",
	
	// you shouldn't touch these
	current: 0,
	total: 0,
	delayFade: 500,
	delayFadeIn: null,
	rotateInterval: null,
	
	// start it
	init: function(){
		
		$(this.elements).hide();
		this.total = $(this.elements).length; // amount of testimonials
		var random = Math.floor(Math.random() * ((this.total-1) - 0 + 1)); // randomize it
		
		this.current = random;
		$(this.elements+":eq("+random+")").show();
		this.rotateInterval = window.setInterval("Testimonials.rotate();",this.intervalSpeed);
	
	},
	
	// rotate through the testimonials
	rotate: function(){
		
		this.checkNext(); // we get the appropriate testimonial if 
		
		/*
		$(this.elements).fadeOut(this.fadeSpeed,function(){
			clearTimeout(Testimonials.delayFadeIn);
			Testimonials.delayFadeIn = setTimeout("Testimonials.delayit();",Testimonials.delayFade);
		});
		*/
		$(this.elements).hide();
		$(this.elements+":eq("+this.current+")").fadeIn(this.fadeSpeed);

	},
	
	// delay the fade in so the other testimonial has time to fade out.. found inside the fadeout callback
	/*delayit: function(){

		$(this.elements+":eq("+this.current+")").fadeIn(this.fadeSpeed);
		
	},*/
	
	// call this function before you use the "this.current" variable.. it will insure you are on the correct testimonial
	checkNext: function(){
	
		if((this.total - 1) > this.current){
			this.current++;
		} else {
			this.current = 0;
		}
		
	},
	
	checkPrevious: function(){
		
		if(this.current > 0){
			this.current--;
		} 
		else {
			this.current = (this.total -1);
		}
		
	},
	
	// if they want to manually scroll through the testimonials
	next: function(){
	
		clearInterval(this.rotateInterval);
		this.checkNext();
		
		$(this.elements).hide();
		$(this.elements+":eq("+this.current+")").show();
		
	},
	
	// if they want to manually scroll through the testimonials
	previous: function(){
		
		clearInterval(this.rotateInterval);
		this.checkPrevious();
		
		$(this.elements).hide();
		$(this.elements+":eq("+this.current+")").show();
		
	}


}


