var updateInterval = 0;

$(document).ready(function() {
	changeTab($("#tabs").children("a:last"));
});

function changeTab(tab) {
	$('#tabContentHolder').html("<h4 style='width:100%;text-align:center;margin-top:50px;'>Loading " + $(tab).html() + "...</h4>");

	$(tab).siblings().each(function() {
		$(this).removeClass('on');
	});
	
	$(tab).addClass('on');
	
	clearInterval(updateInterval);
	updateInterval = 0;
	
	$.ajax({
		type: "POST",  
		url: $(tab).attr('href'),
		success: function(msg) {
			$('#tabContentHolder').html(msg);
		}
	});
}

function resetBuzzUpdates() {
	clearInterval(updateInterval);
	updateInterval = 0;
	updateInterval = setInterval("reloadTweets()",15000);
}

function reloadTweets() {
	latestTweet = $("#tweetsHolder").children("div:first").attr("alt");
	$.ajax({
		type: "POST",  
		url: "_buzz.php?refresh=1&id="+latestTweet,
		success: function(msg) {
			if($.trim(msg) != "NO" && $.trim(msg) != "") {
				$('#tweetsHolder').fadeOut('fast');
				loadTweetsHolder(msg);
			}
		}
	});
}

function loadTweetsHolder(msg) {
	$('#tweetsHolder').html(msg);
	$('#tweetsHolder').fadeIn();
}
