var testimonial_count = 0;
var testimonial_time = 6000;
var testimonial_animation = 1000;
var testimonial_timeout = null;
var testimonial_current = -1;

jQuery(document).ready(function(){
	//if the div exists
	if(jQuery(".testmonial-home").length > 0){
		//set the number of testimonials
		testimonial_count = jQuery(".testimonial_content").length;
		
		//start the transitions
		swapTestimonial();
	}
});

function swapTestimonial(){
	//setup for next testimonial
	var next_testimonial = 0;
	
	//get next testimonial
	if(testimonial_current + 1 < testimonial_count){
		next_testimonial = testimonial_current+1;
	}
	
	//animate the testimonials
	jQuery(".testimonial_content").eq(testimonial_current).fadeOut(testimonial_animation);
	jQuery(".testimonial_content").eq(next_testimonial).fadeIn(testimonial_animation,function(){
		//set the current testimonial
		testimonial_current = next_testimonial;
		
		//setup the elements
		var testimonial = jQuery(this);
		var container = jQuery(".testimonial_cont:eq(0)");
		
		//move the thing up if needed
		moveTestimonialUp(testimonial,container);
	});
}

function moveTestimonialUp(test,cont){
	if(test.outerHeight(true) + test.position().top > cont.height()){
		//get the difference
		var diff  = test.outerHeight(true)-cont.height();
		
		//move it up
		test.animate({ 'top':cont.height() - test.outerHeight(true) },diff*100,'linear',function(){
			moveTestimonialUp(test,cont);
		});
	} else {
		//set the timeout
		testimonial_timeout = setTimeout('swapTestimonial()',testimonial_time);
	}
}
