$(document).ready(function() {

	// TESTIMONIALS
	// show & hide all testimonials
	$('#all-testimonials').hide();
	$('#all-testimonials-trigger').show();
	$('#all-testimonials-trigger').toggle(function() {
		$('#all-testimonials').slideDown();
		$(this).html($(this).html().replace('all', 'less'));
		return false;
	}, function() {
		$('#all-testimonials').slideUp();
		$(this).html($(this).html().replace('less', 'all'));
		return false;
	});
	// scroll to the top of the page
	$('#go-to-top').click(function() {
		$('html, body').animate({
			scrollTop : 0
		});
		return false;
	});

	// HOMEPAGE
	// show & hide support bubble
	$('#support-bubble-trigger').click(function() {
		if ($('#support-bubble').is(':hidden')) {
			$('#support-bubble').fadeIn('fast');
		} else {
			$('#support-bubble').fadeOut('fast');
		};
		return false;
	});
	$('#support-bubble').mouseleave(function() {
		$(this).fadeOut('fast');
	});

	// ALL PAGES
	// stretch content-right to the height of content-left, if it is shorter and has left border
	if($('#content-right').length && !$('#content-right').hasClass('no-border')) {
		var contentLeftHeight = $('#content-left').height();
		var contentRightHeight = $('#content-right').height();
		if(contentRightHeight < contentLeftHeight) {
			$('#content-right').height(contentLeftHeight + 10);
		};
	};

	// PLAN SUBSCRIPTION
	// change color, font weight & plan details on click
	$.fn.planSubscription = function() {
		$('.plans').removeClass('blue');
		$('.plans label').removeClass('bold');
		$(this).parent('div').addClass('blue');
		$(this).next('label').addClass('bold');
		var totalPrice = $(this).next('label').text().replace(/.*?\(/, '').replace(')', '');
		var selectedPlan = $(this).prevAll('h2').text() + ' / ' + $(this).next('label').text().replace(/\(.*/, '');
		$('.selected-plan').text(selectedPlan);
		$('.total-price').text(totalPrice);
	};
	$('.plans input:checked').planSubscription();
	$('.plans input').click(function() {
		$(this).planSubscription();
	});

});

