// SET TO DIFFER THE LENGTH OF THE CUT-OFF STRING THAT IS VISIBLE AT START
var lengthToCut = 150;

$(window).ready(function() {
	testimonialWrapper();
	initTestimonials();
});

function initTestimonials() {
	$('#right_testimonials h3').click(function() {
		
		var clicked = this;
		var target_id = '#' + clicked.id.substr(5,20);
		var target_class = $(target_id).attr('class');
		
		if (target_class != 'active_testimonial') {
			$('.active_testimonial').animate({opacity: 'hide'}, 'normal', function() {
				$('.active_testimonial').removeClass('active_testimonial');
				$('.active_testimonial_h3').removeClass('active_testimonial_h3');
				
				$(target_id).animate({opacity: 'show'},'normal');
				$(target_id).addClass('active_testimonial');
				$(clicked).addClass('active_testimonial_h3');
				
			});
		}
		
	});
}



function testimonialWrapper() {
	var allTestimonials = [];
	allTestimonials = $('.testimonials_container .originalTestimonial').toArray();
	
	for (var i = 0; i < allTestimonials.length; i++) {
		var htmlContent = $(allTestimonials[i]).html();
		
		
		if(htmlContent.length > lengthToCut) {
			var shortText = htmlContent.substr(0, lengthToCut);
			var shortHtml = shortText + ' <span class="show_more">more...</span>';
			
			$(allTestimonials[i]).parent().children('.shortTestimonial').html(shortHtml);
			$(allTestimonials[i]).css('display', 'none');
			$(allTestimonials[i]).append('<br /><span class="show_less">close...</span>');
		}
	}
	
	$('.testimonials_container .show_more').click(function() {		
		$(this).parent().parent().children('.shortTestimonial').css('display', 'none');
		$(this).parent().parent().children('.originalTestimonial').animate({opacity: 'show', height: 'show'}, 'normal');
	});
	
	$('.testimonials_container .show_less').click(function() {		
		$(this).parent().parent().children('.originalTestimonial').animate({opacity: 'hide', height: 'hide'}, 'normal');
		$(this).parent().parent().children('.shortTestimonial').animate({opacity: 'show'}, 'fast');
	});
	
}

