$(window).load(function() {
	if ($('#main-featured').is('div')) {
		height = 0;
		$('.tab_content').each(function(i) {
			height = ($('.tab_content').eq(i).height() > height) ? $('.tab_content').eq(i).height() : height;
		});
		
		//Hack for IE.
		$('#ctab2').fadeTo(0,0);
		$('#ctab3').fadeTo(0,0);
		$('#ctab4').fadeTo(0,0);
		
		$('.tab_content').height( height );
		
		$('.tabs a').click(function() {
		  	$('.tab_show').fadeTo(0, 0);
			$('.tab_content').removeClass('tab_show');
			
			var k = $($(this).attr('href'));
	  			k.addClass('tab_show');
	    		k.fadeTo("slow", 1);
	     
			$('.tabs li').removeClass('carousel-active');
			$(this).parent('li').addClass('carousel-active');
			
			return false;
		});
		
		rotate = true;
		if (rotate) {
			tid = setTimeout('activateNextTab()', 7000);
		}
		
		$('.tabs a, .tab_content').mouseover(function() {
			clearInterval(tid);
		});
		$('.tabs a, .tab_content').mouseout(function() {
			if (rotate) {
				tid = setTimeout('activateNextTab()', 7000);
			}
		});
		$('.tabs a').mousedown(function() {
			rotate = false;
		});
	}
});

function activateNextTab() {
	nextTab = $('.carousel-active').next('li');
	$('.carousel-active').removeClass('carousel-active');
	$('.tab_show').fadeTo("slow", 0);
	$('.tab_content').removeClass('tab_show');
	
	if ($(nextTab).html()) {
		$(nextTab).addClass('carousel-active');
	} else {
		nextTab = $('.tabs li').eq(0);
		$('.tabs li').eq(0).addClass('carousel-active');
	}
	
	var k = $( $(nextTab).children('a').eq(0).attr('href') );
  	k.addClass('tab_show');
	k.fadeTo("slow", 1);
	
	if (rotate) {
		tid = setTimeout('activateNextTab()', 7000);
	}
}
