$(document).ready( function(){
	makeCaptionWidth();

	setTimeout(makeCaptionWidth, 1500);
	setTimeout(makeCaptionWidth, 4000);
});

function makeCaptionWidth(){
	// removes newlines from captions and sets the width
	var img;
	var w;
	$('div.caption').each( function(){
		img = $(this).find('img');
		w = img.width();
		$(this).width(w);
		$(this).find('p').each( function(){
			$(this).html( $(this).text() );
		});

	});
}

function animateTestimonials(parent){
	var p = $(parent).children('p');
	if(p.length == 0){
		return false;
	}
	else if(p.length == 1){
		p.eq(0).show();
	}
	else{
		p.eq(0).show();
		setInterval( function(){setAnimation($(parent));}, 25000);
	}
	return false;
}

function setAnimation(elem){
	var p = $(elem).children('p:visible');

	if(p.next('p').length > 0){
		p.fadeOut(1000, function(){p.next('p').fadeIn(1000);} );
	}
	else{
		p.fadeOut(1000, function(){p.parent().children('p').eq(0).fadeIn(1000);} );
	}
}

