$(function()
{
	var user = 'toffeenutdesign';
	
	$.getJSON('http://twitter.com/statuses/user_timeline/toffeenutdesign.json?count=1&callback=?', $(this), function(data)
	{
		var tweet_text = $('<span class="tweet_text"></span>');
		tweet_text.html(data[0].text.length > 100 ? (data[0].text.substring(0, 100) + '...') : data[0].text);
		$('#tweet_wrap').append(tweet_text);
		
		$('#tweet_wrap').append($('<br />'));
		
		// Twitter has the year after the timezone - IE doesn't like that
		var corrected_date = data[0].created_at;
		if ($.browser.msie)
		{
			var parts = corrected_date.split(' ');
			if (parts.length > 2)
			{
				var timezone = parts[parts.length - 2];
				parts[parts.length - 2] = parts[parts.length - 1];
				parts[parts.length - 1] = timezone;
				corrected_date = parts.join(' ');
			}
		}
		
		var tweet_date = $('<span class="tweet_date"></span>');
		var seconds_ago = Math.round((new Date() - Date.parse(corrected_date)) / 1000);
		if (seconds_ago < 60)
			tweet_date.html('@' + user + ', about ' + seconds_ago + ' second' + (seconds_ago != 1 ? 's' : '') + ' ago');
		else if (seconds_ago < 3600)
		{
			var mins_ago = Math.round(seconds_ago / 60);
			tweet_date.html('@' + user + ', about ' + mins_ago + ' minute' + (mins_ago != 1 ? 's' : '') + ' ago');
		}
		else
		{
			var hours_ago = Math.round(seconds_ago / 3600);
			tweet_date.html('@' + user + ', about ' + hours_ago + ' hour' + (hours_ago != 1 ? 's' : '') + ' ago');
		}
		
		$('#tweet_wrap').append(tweet_date);
	});
});


