//fade out the testimonials on the home logged out page and switch them in interval
var testimonials = new Array();
var testimonialsRunning = null;
$(document).ready(function(){
	//grab all elements and put them into the array
	$('.testimonial').each(function(key, value) {
		$(value).hide();
		testimonials.push(value);
		$(value).css('cursor', 'pointer');
		$(value).click(function(){
			location = $('#testimoniallink').attr('href');
		});
	});
        testimonials = arrayShuffle(testimonials);
	window.setTimeout("switchTestimonials()", 2000);
        
        function arrayShuffle(theArray){
          var tmp, rand;
          for(var i =0; i < theArray.length; i++){
            rand = Math.floor(Math.random() * theArray.length);
            tmp = theArray[i]; 
            theArray[i] = theArray[rand]; 
            theArray[rand] = tmp;
          }
          return theArray;
        }
});

var switchTestimonials = function(){
	if(testimonialsRunning != null){
		//fade out the first element inarray
		$(document).queue("namedQueue", function() {
		  	var self = this;
		  	$(testimonials[0]).fadeOut();
		  	setTimeout(function() {
			    $(self).dequeue("namedQueue");
			  }, 200);
		});

		//grab the first element and put it to the back, then fade in the first element
		$(document).queue("namedQueue", function() {
			var first = testimonials.shift();
			testimonials.push(first);
			$(testimonials[0]).fadeIn();	
		});
		$(document).dequeue("namedQueue");
	}else{
		//first run, so just fade in the first element in array
		$(testimonials[0]).fadeIn();
		testimonialsRunning = true;
	}
	//run me again
	window.setTimeout("switchTestimonials()", 15000);
}
