$(function()
{
	$.ajax
	({
		url: "http://api.twitter.com/1/statuses/user_timeline.json?user_id=247264228&count=6&trim_user=1",
		dataType: 'jsonp',
		success: onLoadTwitterFeedSuccess,
		error: onLoadTwitterFeedError
	});
});

function onLoadTwitterFeedSuccess(data,status)
{
	var html = "";
	
	$.each
	(
		data,
		function(i,item)
		{
			html += "<p style=\"display: none;\">"+linkify(item['text'])+"</p>";
		}
	);
	
	if(html != "")
	{
		$("#twitter-feed").html(html);
		$("#twitter-feed p:first").fadeIn("slow", function() { $("#twitter-feed").cycle({fx:'fade',timeout:5000,height:26}); });
	}
}

function linkify(text)
{
	if(text)
	{
		text = text.replace
		(
			/((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
			function(url)
			{
				var full_url = url;
				
				if(false == full_url.match('^https?:\/\/'))
					full_url = 'http://' + full_url;
				
				return '<a href="'+full_url+'">'+url+'</a>';
			}
		);
	}
	
	return text;
}

function onLoadTwitterFeedError(XMLHttpRequest, textStatus, errorThrown)
{
	
}
