/*
	jQuery function to populate and rotate to testimonial slider on the home page.
*/

// Send Ajax request to the server for 20 random quotes as an unordered list
// Hold results in XML response
// Set timer to step through the XML doc
// On each increment fade out existing text load next into div and fade in.

var timer;
var currentProduct = 0;
var oldProduct = 0;
var featuredPrdCount = 0;
var productInterval;

$(function(){
	$("div#testimonials ul").children("li").hide();

	featuredPrdCount = $("div#testimonials ul li").size();
	productInterval = setInterval(nextFeaturedProduct,10000);
	nextFeaturedProduct();

	//Pause on mouse over
	jQuery('div#testimonials').hover(function() {
		clearInterval(productInterval);
	}, function() {
		productInterval = setInterval(nextFeaturedProduct,10000);
	});
});

function nextFeaturedProduct() {
	currentProduct = (oldProduct + 1) % featuredPrdCount;
	jQuery("div#testimonials").animate({height:'toggle', opacity:0},'slow','linear', function(){
		jQuery("div#testimonials ul li:eq(" + oldProduct + ")").hide();
		jQuery("div#testimonials ul li:eq(" + currentProduct + ")").show();
		oldProduct = currentProduct;
		//jQuery("div#testimonials").animate({height:'toggle', opacity:1},'slow');
	}).animate({opacity:0},1000).animate({height:'toggle', opacity:1},'slow','linear');
	//jQuery("div#testimonials").stop(true, true).slideToggle('slow');
	//jQuery("div#testimonials").css('background','rgba(0,0,0,0.65)');
}

function slideclicktest(){
	jQuery("div#testimonials").slideToggle('slow');
}
