var buildTweets = {
    init: function(d, e) { 
        $('p.tweet').each(function() {
            $(this).html(buildTweets.getLinks($(this).html()));
        });
        $('p.tweet span.date').each(function() {
            $(this).text(buildTweets.parseTime($(this).text()));
		});
    },
    getLinks: function(text){
        var linkRe = /((http|https|ftp):\/\/\S+)/g;
        var replyRe = /(@)(\S+)/gi;
        var hashtagRe = /#(\S+)/gi;
        var initals = /(#mh|#bb|#fb|#rc|#bs|#hh|#sl|#sc|#sj|#jm|#dp|#aw)/;
        var text = text;
        text = text.replace(initals, "")
            .replace(linkRe, '<a href="$1">$1</a>')
            .replace(replyRe, '<a href="http://twitter.com/$2">$1$2</a>')
            .replace(hashtagRe, '<a href="http://search.twitter.com/search?q=%23$1">#$1</a>');
            return text;
    },
    parseTime: function(date){
		var time = date.substr(7,2)-0;
		if (time > 12) {
			var milTime = time;
			var civTime = time-12;
			date = date.replace(milTime,civTime) + " pm";
		} else {
			date = date + " am";
		}
		return date;
	}
};

$(function() {  
    buildTweets.init();
    $('div#tweetHistory p.tweet:nth-child(odd),div#tweetHistory p.tweeter:nth-child(even)').addClass("alt");
});