$(document).ready(function() {
	
	maxpages = $("a#testimonial_slideshow > span").size();
	
	itemwidth = $("a#testimonial_slideshow span").outerWidth();
	totalwidth = itemwidth*maxpages;
	
	$("a#testimonial_slideshow").css({width:totalwidth});
	
	$("a#testimonial_slideshow > span").each(function (i) {
		i = i+1;
		
		$(this).addClass(num(i));
	});
	
	if(maxpages > 1) {
		timeChange();
	}
	
});

var t;
var page;
var timer_is_on=1;


if (typeof page === 'undefined') {
    page = '1';
}

function timeChange()
{
	if(timer_is_on == 1) {
		t=setTimeout("Change()",5000);
	}
}
	
function Change()
{
	//$("a#testimonial_slideshow span."+num(page)).stop(true,true).fadeOut(1500);
	
	$("a#testimonial_slideshow").css({left:'0'});
	$("a#testimonial_slideshow span.removeme").remove();
	
	var content = $("a#testimonial_slideshow span."+num(page)).html();
	content = '<span class="'+num(page)+'">'+content+'</span>';
	
	$("a#testimonial_slideshow").animate({left:'-305px'});
	$("a#testimonial_slideshow span."+num(page)).addClass("removeme");
	
	$("a#testimonial_slideshow").append(content);

	page = Number(page)+1;
	timeChange();
	
	if(page > maxpages) {
		page = 1;
	}
	
	//$("a#testimonial_slideshow span."+num(page)).stop(true,true).fadeIn(1500).css('display', 'block');

}

//convert number to word function
var units = new Array ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen");
var tens = new Array ("Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety");

function num(it){var theword="";var started;if(it>999)return"Lots";if(it==0)return units[0];for(var i=9;i>=1;i--){if(it>=i*100){theword+=units[i];started=1;theword+=" hundred";if(it!=i*100)theword+=" and ";it-=i*100;i=0}};for(var i=9;i>=2;i--){if(it>=i*10){theword+=(started?tens[i-2].toLowerCase():tens[i-2]);started=1;if(it!=i*10)theword+="-";it-=i*10;i=0}};for(var i=1;i<20;i++){if(it==i){theword+=(started?units[i].toLowerCase():units[i])}};return theword}
