$(window).load(function() {
	if ($('#featured_articles').is('div')) {
		height = 0;
		$('.tab_content').each(function(i) {
			height = ($('.tab_content').eq(i).height() > height) ? $('.tab_content').eq(i).height() : height;
		});
		$('.tab_content').height( height );
		
		$('.tabs a').click(function() {
			$('.tab_content').removeClass('tab_show');
			$($(this).attr('href')).addClass('tab_show');
			$('.tabs li').removeClass('active');
			$(this).parent('li').addClass('active');
			
			return false;
		});
		
		rotate = true;
		if (rotate) {
			tid = setTimeout('activateNextTab()', 4000);
		}
		
		$('.tabs a, .tab_content').mouseover(function() {
			clearInterval(tid);
		});
		$('.tabs a, .tab_content').mouseout(function() {
			if (rotate) {
				tid = setTimeout('activateNextTab()', 500);
			}
		});
		$('.tabs a').mousedown(function() {
			rotate = false;
		});
	}
});

$(function() {
	$('.play').click(function() {
		if ($(this).attr('rel').toLowerCase().indexOf('tra') == 0) {
			RhapsodyPlayer.playTrack($(this).attr('rel').split('+'));
		} else if ($(this).attr('rel').toLowerCase().indexOf('mp') == 0) {
			RhapsodyPlayer.playRhapsody({ id:$(this).attr('rel'), type:'playlist' });
		}
		
		return false;
	});
	
	$('#recent_comments li').click(function() {
		window.location = $(this).children('a').eq(0).attr('href');
	});
	
	if ($('#comment').is('textarea')) {
		expandCommentArea();
		$('#comment').keyup(function() {
			expandCommentArea();
		});
	}
});

function activateNextTab() {
	nextTab = $('.active').next('li');
	$('.active').removeClass('active');
	$('.tab_content').removeClass('tab_show');
	
	if ($(nextTab).html()) {
		$(nextTab).addClass('active');
	} else {
		nextTab = $('.tabs li').eq(0);
		$('.tabs li').eq(0).addClass('active');
	}
	$( $(nextTab).children('a').eq(0).attr('href') ).addClass('tab_show');
	
	if (rotate) {
		tid = setTimeout('activateNextTab()', 4000);
	}
}

function expandCommentArea() {
	//console.log($('#comment').get(0).scrollHeight);
	if ($('#comment').get(0).scrollHeight > $('#comment').height()) {
		$('#comment').height( $('#comment').get(0).scrollHeight );
	}
}