String.prototype.linkify_tweet = function() {
	var tweet = this.replace(/(http:\/\/\S+[^\W])/g, "<a target='_blank' href='$1'>$1</a>");
	tweet = tweet.replace(/(^|\s)@(\w+)/g, "$1@<a target='_blank' href='http://www.twitter.com/$2'>$2</a>");
	return tweet.replace(/(^|\s)#(\w+)/g, "$1<a target='_blank' href='http://search.twitter.com/search?q=%23$2'>#$2</a>");
};

$(function(){
	$("#flickr_badge_wrapper a").attr("target","_blank");
	if ($('#tweets').length == 1) {
		var url = "http://api.twitter.com/statuses/user_timeline/industrieit.json?count=3&callback=?";
		$.getJSON(url, function(data) {
			var items = [];
			$.each(data, function(i, tweet) {
				var tweet_date_items = tweet.created_at.split(" ");
				var tweet_date = $.datepicker.parseDate("ddMyy", tweet_date_items[2]+tweet_date_items[1]+tweet_date_items[5]);
				items.push(
					'<h5>' + $.datepicker.formatDate("dd MM yy", tweet_date) + '</h5>' +
					'<p>' + tweet.text.linkify_tweet() + '</p>'
				);
			});
			$('#tweets').append(items.join(''));
		});
	}
});
