$(function() {   

	var theWindow        = $(window),
	    $bg              = $("#bg"),
	    aspectRatio      = $bg.width() / $bg.height();
  			    		
	function resizeBg() {

		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
		    $bg
		    	.removeClass()
		    	.addClass('bgheight');
		} else {
		    $bg
		    	.removeClass()
		    	.addClass('bgwidth');
		}
			
	}
                 			
	theWindow.resize(function() {
		resizeBg();
	}).trigger("resize");

});

function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); 
}
function replaceURLWithTWEETLinks(text) {
  var exp = /(^|[^a-z0-9_])@([a-z0-9_]+)/ig;
  return text.replace(exp," <a href='http://twitter.com/$2' target='_blank'>@$2</a>"); 
}

$.getJSON("https://twitter.com/statuses/user_timeline/handmadetea.json?callback=?", function(data) {
		 var last_tweet = replaceURLWithHTMLLinks(data[0].text);
     $(".twitter_meat").html(replaceURLWithTWEETLinks(last_tweet)+'<div class="twitter_nib"></div>');
});
