/**
 *
 * Site functions
 *
 **/
$(document).ready(function(){
	
	// Header animation	
	$('#animation .move-txt p.txt-1').fadeIn(1000, function() {
		$('#animation .move-txt p.txt-2').fadeIn(1000, function() {
			$('#animation .move-txt p.txt-3').fadeIn(1000);
		});
	});
	
	// Assign last class for css to show it initially
	$('#testimonials ul li:last').addClass('last');
	
	// start the testimonials which will not actually begin for 10 seconds
	var timer = setInterval('testimonials()',10000);
	
	// in the meanwhile, after 8 seconds, animate the current placeholder testimonial out
	// (This testimonial is already in place on page load */
	$('#testimonials ul li.last .quote').delay(8000).animate({left:'-750px'});
	$('#testimonials ul li.last .client').delay(8000).animate({right:'-150px'}, function() {
		// restore to hidden location
		$('#testimonials ul li.last .quote').css({top:'200px', left:'20px'});
		$('#testimonials ul li.last .client').css({top:'330px', right:'20px'});	
	});
});

function testimonials() {
	
	// each step requires a callback function to execute in order
	$('#testimonials ul li.active .quote').animate({top:'0px'}, function() {
		$('#testimonials ul li.active .client').animate({top:'110px'}, function() {
			$('#testimonials ul li.active .quote').delay(8000).animate({left:'-750px'}); 
			$('#testimonials ul li.active .client').delay(8000).animate({right:'-150px'}, function() {
				// set active class variable
				var $active = $('#testimonials ul li.active');
				// restore to hidden location
				$('#testimonials ul li.active .quote').css({top:'200px', left:'20px'});
				$('#testimonials ul li.active .client').css({top:'330px', right:'20px'});
				// find next li 
				var $next = $active.next();
				// check to see if the next is the last item
				var $nextCheckClass = $('#testimonials ul li.active').hasClass('last');
				// start over if the next li contains 'last' class
				if ( $nextCheckClass ) { $next = $('#testimonials ul li:first'); }
				$next.addClass('active');
				$active.removeClass('active');
			});
		});
	});
	
}
