$(function() {
	$.getJSON(
		'http://twitter.com/statuses/user_timeline/zichtonline.json?count=5&callback=?',
		function(data) {
			var feedul = $("ul#twitterfeed");
			var feedloader = $("div#twitterloader");
			
			feedloader.hide();
			
			var rowCount = 0;

			$.each(data, function(i, item){
				var status = item.text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
						return '<a href="'+url+'">'+url+'</a>';
					}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
						return reply.charAt(0) + '<a href="http://twitter.com/' + reply.substring(1) + '">' + reply.substring(1) + '</a>';
					}
				);

				if (rowCount < 9) {
					var li = $("<li>" + status + "</li>").appendTo(feedul);
					var r = Math.round(li.height() / 16);

					if (rowCount+r > 9) {
						li.remove();
					} else {
						rowCount += r;
					}
				}
			});

			feedul.find('li:last').css('border','none');
		}
	);
});