
/*

	TWEET DISPLAY
	Joseph O Donoghue

*/

var tweet_count = 0;
var tweets = new Array();
var tweet;

function loadTweets(){

	var url = "http://twitter.com/statuses/user_timeline/PanIndexNews.json?callback=?&count=5"
	
	if(site_lang == 'zh'){
		url = "http://twitter.com/statuses/user_timeline/PanIndexNews_zh.json?callback=?&count=5"
	}
		
	$.getJSON(url, function(data) {
		
		tweet_count = 0;
		tweets = new Array();						
		
		for(var i = 0; i < data.length; i++) {
			tweets.push(autoLink(data[i].text));
		}
		
		tweet = setInterval(populateTweets, 6000);
							
	});
	
}

function populateTweets(){
	
	clearInterval(tweet);
	
	$("#ticker p").fadeOut('fast', function(){
		if(tweet_count<tweets.length){
	
			$("#ticker p").html(tweets[tweet_count]);
			
			$("#ticker p").fadeIn('fast', function(){
				tweet_count++;
				tweet = setInterval(populateTweets, 6000);
			});
	
		}else{
			
			loadTweets();

		}
		
	});
	
}
	
function autoLink(text){
	return text.replace(/(http:\/\/[\w\.\/]+)/, "<a href=\"$1\" target=\"blank\">$1</a>");
}
