
$(document).ready(function () {
    // get the set of testimonials available
	
	$.getJSON("/model/remote/RemoteTestimonialService.cfc?method=getTestimonialPaths&returnformat=json", handleResponse);
});

handleResponse = function(data){
	testimonials = data;
	index = Math.floor(Math.random()*testimonials.length);
	$("#mainBoxHome #testimonial").attr("src", "/images/testimonials/" + testimonials[index]);
	fadinRunning = false;
}

goToTestimonial = function(newIndex){
	if (!fadinRunning) {
		index = newIndex;
		$("#mainBoxHome").append('<img src="/images/testimonials/' + testimonials[index] + '" id="testimonialNew" />');
		$("#mainBoxHome #testimonialNew").attr("src", "/images/testimonials/" + testimonials[index]);
		fadinRunning = true;
		$("#mainBoxHome #testimonialNew").fadeIn("slow", fadeinDone);
	}
}

fadeinDone = function(){
	var newImg = $("#mainBoxHome #testimonialNew");
	var oldImg = $("#mainBoxHome #testimonial");
	
	oldImg.remove();
	newImg.attr("id", "testimonial");
	fadinRunning = false;
}

getIndex = function(increment){
	var newIndex;
	
	if(index+increment < 0){
		newIndex = index+increment+testimonials.length;
	} else {
		newIndex = (index+increment) % testimonials.length;
	}
	
	return newIndex;
}
