var mTestimonialIndex = 0;
var mCompanyLogoIndex = 0;

function randOrd(){
	return (Math.round(Math.random())-0.5); 
} 

function showTestimonial(){
	var fadeDelayMs = 500;
	var timeoutDelayMs = 4000;
	var trimAtChar = 254;
	
	if(mTestimonialIndex == testimonialText.length){
		mTestimonialIndex = 0;
	}
	companyLogos.sort();
	if(mCompanyLogoIndex >= companyLogos.length - 3){
		mCompanyLogoIndex = 0;
	}
	var quote = testimonialText[mTestimonialIndex];
	var endIndex = quote.indexOf(" ", trimAtChar);
	if(endIndex == -1){	
		quote = quote.substr(0, trimAtChar);
	}else{
		quote = quote.substr(0, endIndex) + "...";
	}
	quote = quote.replace("&ldquo;", "");
	
	//companyLogos.sort( randOrd );
	//hide all the components first
	$("#testimonialTicker p#text").hide();
	$("#testimonialTicker p#by").hide();
	$("#testimonialLogoContainer").hide();
	$("#testimonialCompanyLogo1").hide();
	$("#testimonialCompanyLogo2").hide();
	$("#testimonialCompanyLogo3").hide();	
	//set each component
	$("#testimonialTicker p#text").text('"' + quote + '"');
	$("#testimonialLogoContainer").html(testimonialLogo[mTestimonialIndex]);
	$("#testimonialCompanyLogo1").html(companyLogos[mCompanyLogoIndex]);
	$("#testimonialCompanyLogo2").html(companyLogos[mCompanyLogoIndex + 1]);
	$("#testimonialCompanyLogo3").html(companyLogos[mCompanyLogoIndex + 2]);
	$('#testimonialTicker p#text').css("background-color", "#fff");
	$('#testimonialTicker p#by').css("background-color", "#fff");
	
	//fade in the component
	$('#testimonialTicker p#text').fadeIn(function(){    		
		if ($.browser.msie){$('#testimonialTicker p#text').css("background-color", "#fff");} 
	});
	$("#testimonialTicker p#by").text(testimonialBy[mTestimonialIndex]);
	$('#testimonialTicker p#by').fadeIn(function(){    		
		if ($.browser.msie){$('#testimonialTicker p#text').css("background-color", "#fff");} 
	});
	
	$("#testimonialLogoContainer").fadeIn(fadeDelayMs);		
	$("#testimonialCompanyLogo1").fadeIn(fadeDelayMs);
	$("#testimonialCompanyLogo2").fadeIn(fadeDelayMs);
	$("#testimonialCompanyLogo3").fadeIn(fadeDelayMs);
	
	mTestimonialIndex++;	
	mCompanyLogoIndex = mCompanyLogoIndex + 3;
	
	setTimeout("showTestimonial()", timeoutDelayMs);
}