// JavaScript Document

function randRange(min, max) {
		var randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
		return randomNum;
}

function preloadTestimonials() {
	for (var i = 0; i <= maxTestimonialsIdx; i++) {
		var img = new Image();
		img.src = '/images/testimonials/' + i + '.jpg';
	}
	isTestimonialsPreloaded = true;
}

function changeTestimonials() {
	if (!isTestimonialsPreloaded) return;
	$('#testimonials').hide();
	currentTestimonialsIdx++;
	//currentTestimonialsIdx = currentTestimonialsIdx > maxTestimonialsIdx?0:currentTestimonialsIdx;
	currentTestimonialsIdx = randRange(1, 12);
	$('#testimonials').css('background-image', 'url(/images/testimonials/' + (currentTestimonialsIdx<10?'0':'') + currentTestimonialsIdx + '.jpg)');
	$('#testimonials').fadeIn(500);
}

var isTestimonialsPreloaded = false;
var currentTestimonialsIdx = -1;
var maxTestimonialsIdx = 8;

$(document).ready(function () {
	preloadTestimonials();
	changeTestimonials()
	setInterval(changeTestimonials, 8000);
})
