$(document).ready(function() {
	// Get most recent Twitter
	$.getJSON('http://twitter.com/status/user_timeline/lukecanvin.json?count=1&callback=?', function(data){
		$.each(data, function(index, item){
			$('#twitter').prepend('<p>' + item.text.linkify() + '</p>');
			$('#speech-bubble').append('<p><a href="http://twitter.com/lukecanvin/">Twittered ' + relative_time(item.created_at) + '</a></p>');
		});
	});

	// Format links for Twitter
	String.prototype.linkify = function() {
		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
			return m.link(m);
		});
	};

	// Create relative time mark, from http://twitter.com/javascripts/blogger.js
	function relative_time(C){var B=C.split(" ");C=B[1]+" "+B[2]+", "+B[5]+" "+B[3];var A=Date.parse(C);var D=(arguments.length>1)?arguments[1]:new Date();var E=parseInt((D.getTime()-A)/1000);E=E+(D.getTimezoneOffset()*60);if(E<60){return"less than a minute ago"}else{if(E<120){return"about a minute ago"}else{if(E<(60*60)){return(parseInt(E/60)).toString()+" minutes ago"}else{if(E<(120*60)){return"about an hour ago"}else{if(E<(24*60*60)){return"about "+(parseInt(E/3600)).toString()+" hours ago"}else{if(E<(48*60*60)){return"1 day ago"}else{return(parseInt(E/86400)).toString()+" days ago"}}}}}}};

});
