function gettweet(id, element, mainsize){
	$.getJSON("gettweet.php?" + escape(id), function(tweet){
		if(tweet == null){
			$.getJSON("getcachedtweet.php?" + escape(id), function(tweet){
				writetweet(tweet, element, mainsize);
			});
		}
		writetweet(tweet, element, mainsize);
	});
}

function writetweet(tweet, element, mainsize){
	tweethtml = new String();
	$(element).hide();
	if(tweet != null) tweethtml = "<font style=\"font-size:" + mainsize + "px;\"><b><a style=\"color:#994747;\" href=\"http://www.twitter.com/" + tweet[0].user.screen_name + "\">" + tweet[0].user.name + "</a> </font><font style=\"font-size:" + mainsize + "px;color:#404040;\">latest tweets:</b></font><font style=\"color:#FFC64B;\">";
	for(tweetnum in tweet) tweethtml = tweethtml + "<br />" + tweet[tweetnum].text + "<br />";
	tweethtml = tweethtml + "</font>";
	$(element).html(tweethtml);
	if($.trim($(element).text()) == '') $(element.text("The latest tweets are temporarily unavailable"));
	$(element).fadeIn(800);
}

$(document).ready(function(){
	gettweet('flamingstocks', '#tweet', '14');
});

/*Example usage:
$(document).ready(function(){
	gettweet('copswapdev', '#error-box', '11');
});
'copswapdev' is the username that you'd like to get the last tweet of
'#error-box' is the id of the div that you'd like to put the tweet in
'11' is the size of the font that the username is displayed in
*/
