(function($) {
	if(!$('body').hasClass('dynamic')) {
		return;
	}

	$('body').removeClass('dynamic');

	var height = 0,
		tabBodies = $('.tab-body')
			.each(function(i, tabBody) {
				tabBody = $(tabBody);
				var isBlurbs = tabBody.parents('#blurbs').length > 0;
				if(isBlurbs) {
					tabBody.before($('#go-forward-guide'));
				}
				var tbHeight = tabBody.height() + parseInt(tabBody.css('marginTop'), 10) +
					parseInt(tabBody.css('marginBottom'), 10)
				if(tbHeight > height) {
					height = tbHeight;
				}
				if(isBlurbs) {
					$('#blurbs').before($('#go-forward-guide'));
				}
			});

	height += 24;
	$('#lc-body .content, #lc-sidebar .content, .tab-body').height(height);

	$('body').addClass('dynamic');

	$('.tab-tabs li').live('click', function(e) {
		e.preventDefault();
		var tab = $(this);
		tab.blur();
		$(e.target).blur();
		tab.parents('.tab-tabs:first').find('li.active:first').removeClass('active');
		tab.addClass('active')
		var selector = tab.find('a').attr('href').replace(/^.*?\#/, '#'),
			tabContainer = tab.parents('.tab-container'),
			currentlyActive = tabContainer.find('.tab-body.active'),
			activate = $(selector);

		if(currentlyActive[0] == activate[0]) {
			return;
		}

		var duration = 150 * (e.shiftKey ? 10 : 1);

		currentlyActive.fadeOut(duration, function() {
			$(this).removeClass('active');
			activate.fadeIn(duration, function() {
				$(this).addClass('active');
				if(this.style.filter !== undefined && this.style.removeAttribute) {
					this.style.removeAttribute('filter');
				}
			});
		});

	});


	if($('#cb').hasClass('ie6') || $('#cb').hasClass('ie7')) {
		$('#testimonials .tab-tabs').width($('#lc-sidebar').width());
		$('#testimonials .tab-tabs ul').css({
			position: 'absolute',
			left: '50%',
			marginLeft: (0 - Math.floor($('#testimonials .tab-tabs ul').width() / 2)) + 'px'
		});
	}

})(jQuery);