function check_twitter(get_this_many) {
	var siteName = 'drmoore';
	
	$.getJSON(
		'http://twitter.com/statuses/user_timeline/'+siteName+'.json?callback=?&count='+get_this_many,
		function(data) {
			var tweets = data;
			var li_tweets = '';

			for ( num=0; num < tweets.length; num++ ) {
				if ( ( tweets[num] !== undefined ) && ( tweets[num].text !== undefined ) ) {
				
					//parse for links, simple - trust twitter
					var match_http = tweets[num].text.match(/http:\/\/([^ ]+)/);
					var result = tweets[num].text;
					if ( match_http ) {
						for ( var i = 0; i < (match_http.length - 1 ); i++ )
							result = result.replace(match_http[i], '<a href="'+match_http[i]+'">'+match_http[i]+'</a>');
					}
											
					//replace @twitterusers with links
					var matches = tweets[num].text.match(/@([a-zA-Z0-9_]{1,15})/);
					if ( matches ) {
						for ( var i = 0; i < ( matches.length - 1 ); i++ )
							result = result.replace(matches[i], "@<a href='http://twitter.com/" + matches[i].substr(1) + "'>" + matches[i].substr(1) + "</a>");
					}
					
					//check if it's a response
					var reply_to_status;
					if ( reply_to_status = tweets[num].in_reply_to_status_id )
						reply_to_status = ' <a href="http://twitter.com/' + tweets[num].in_reply_to_screen_name + '/statuses/' + reply_to_status + '">in reply to ' + tweets[num].in_reply_to_screen_name + '</a>';
					else
						reply_to_status = '';
					
					//add since/time-ago with link to status update
					var new_tweet = result + reply_to_status + ' <a href="http://twitter.com/' + siteName + '/statuses/' + tweets[num].id + '">';
					var temp_date = new Date();
					
					var mil_ago = temp_date.getTime() - Date.parse(tweets[num].created_at);
					var disp_time;
					var time_ago = 0;
					if ( ( time_ago = parseInt( mil_ago / ( 7 * 24 * 60 * 60 * 1000 ) ) ) > 0 ) {
						if ( time_ago == 1 )
							disp_time = '1 week ago';
						else
							disp_time = time_ago + ' weeks ago';
					}
					if ( ( time_ago = parseInt( mil_ago / ( 24 * 60 * 60 * 1000 ) ) ) > 0 ) {
						if ( time_ago == 1 )
							disp_time = '1 day ago';
						else
							disp_time = time_ago + ' days ago';
					}
					else if ( ( time_ago = parseInt( mil_ago / ( 60 * 60 * 1000 ) ) ) > 0 ) {
						if ( time_ago == 1 )
							disp_time = '1 hr ago';
						else
							disp_time = time_ago + ' hrs ago';
					}
					else if ( ( time_ago = parseInt( mil_ago / ( 60 * 1000 ) ) ) >= 0 ) {
						if ( time_ago == 1 )
							disp_time = '1 min ago';
						else
							disp_time = time_ago + ' mins ago';
					}
					
					//if it's not a tweet from here
					if ( ( 0 !== new_tweet.indexOf( "Moore to the Point:" ) ) ) {
						var li_tweet = '<li>' + new_tweet + disp_time + '</a>' + '</li>';
						//we used to do a lot of things like check to see if the top tweet matched and not update
						// but not any more
						//if ( num == 0 && ( 0 > $('#twitter-tools ul li:first').html().indexOf( tweets[num].id ) ) ) {
							li_tweets += li_tweet;
					}
				}
			}
			//slideUp the tweets there, repopulate, and slideDown
			$('#twitter-tools ul').slideUp('fast',function(){
									$(this).html(li_tweets);
									$(this).slideDown(1000);
								});
		}
	);
}

//jquery to run after everything is loaded
$(function() {
	check_twitter(5);
});
