(function(){
	var tHeight = $('#testimonials').innerHeight();

	function testimonialsRotate(duration) {
		if (!duration)
			duration = 5000;

		setTimeout(function(){
			testimonialsAnimate();
		}, duration);
	}

	function testimonialsAnimate() {
		var slides = $('#testimonials > ul > li');
		var current = $('#testimonials > ul > li.active');
		var next = current.next();

		if (current.length != 0) {
			current
				.removeClass('active')
				.fadeOut(2000);
		}

		if (next.length == 0) {
			var next = $('#testimonials > ul > li').eq(0);
		}

		next
			.addClass('active')
			.delay(1500)
			.fadeIn(2000, function(){
				testimonialsRotate();
			});
	}

	$('#testimonials > ul > li').each(function(){
		var height = $(this).outerHeight();
		var paddingTop = (tHeight / 2) - (height / 2);

		$(this).css({
			position: 'absolute',
			top: 0,
			right: 0,
			bottom: 0,
			left: 0,
			paddingTop: (paddingTop > 0 ? paddingTop : 0)
		});
	});

	testimonialsRotate(1);
})();

