var veno = {
	twitter: null,
	
	linkCatch: /((((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&//=]+)/gm,
	usernameCatch: /@(\w+)/gm,

    original_email_address_text: null,
    original_email_message_text: null,

	replaceUrl: function(t) { return '<a href="'+t+'" title="'+t+'">' + t + '</a>'; },

    convertUrls: function(text) {
		text = text.replace(veno.linkCatch, function(t) { return veno.replaceUrl(t); });
		return text.replace(veno.usernameCatch, '<a href="http://twitter.com/$1" title="External Link">@$1</a>');
    }
};

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9252411-3']);
_gaq.push(['_trackPageview']);


$(document).ready(function() {
	veno.twitter = $("#twitter");

	$.ajax({	
		type: "GET",
		dataType: "jsonp",
		url: "http://twitter.com/statuses/user_timeline/ryanmcgrath.json",
		data: "count=8&page=1",
		success: function(tweets) {
			var tweetString = "";
			
			for(var i = 0; i < tweets.length; i++) tweetString += '<dd class="' + (i === tweets.length - 1 ? 'final' : '') + '">' + veno.convertUrls(tweets[i].text) + '</dd>';
			veno.twitter.append(tweetString).slideDown("slow");
		},
		error: function() {
			veno.twitter.append("<dd>Huh, looks like Twitter is down at the moment. This'll return when Twitter gets back up.</dd>");
		}
	});

    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
});

