$(function () {
	var $testimonialPod = $('#testimonialPod');
	var $testimonials = $('div.content', $testimonialPod).hide();
	var tagStripper = /<[/]?a[^>]*>/g;
	if ($testimonials.length) {
		var delayModifier = 45; // milliseconds per character
		var initialDelay = $testimonials.filter('.featured').show().html().replace(tagStripper,"").length;
		var locked = false;
		var rotateTestimonial = function (timer) {
			if (!locked) {
				var $featuredTestimonial = $testimonials.filter('.featured');
				var $randomTestimonials = $testimonials.not('.featured');
				var $randomTestimonial = $randomTestimonials.eq(Math.floor(Math.random() * $randomTestimonials.length));
				$featuredTestimonial.fadeOut(
					 500
					,function () {
						$(this).removeClass('featured');
						$randomTestimonial.fadeIn(
							 500
							,function () {
								$(this).addClass('featured');
								var delay = $(this).html().replace(tagStripper,"").length * delayModifier;
								timer.reset(delay);
							}
						);
					}
				);
			}
		};
		$.timer((initialDelay * delayModifier), function (timer) {rotateTestimonial(timer);});
		$testimonialPod.bind('mouseover', function () {locked = true;});
		$testimonialPod.bind('mouseout',  function () {locked = false;});
	}
});
