jQuery(document).ready(function($) {
								
	$('.tweet').text('Loading latest tweet...');
								
    jQuery.getJSON("http://twitter.com/status/user_timeline/talkstandards.json?count=1&callback=?", function(data){		
			
		var now      = new Date();
			now      = now.getTime();
		var twitDate = data[0].created_at;
		var t        = twitDate.split(' ');
		var theDate  = t[3].split(':');
		var theHour  = theDate[0];
		var theMins  = theDate[1];
		var theSecs  = theDate[2];
		var strMonth;
		switch (t[1]){
			case 'Jan': strMonth = 0; break;
			case 'Feb': strMonth = 1; break;
			case 'Mar': strMonth = 2; break;
			case 'Apr': strMonth = 3; break;
			case 'May': strMonth = 4; break;
			case 'Jun': strMonth = 5; break;
			case 'Jul': strMonth = 6; break;
			case 'Aug': strMonth = 7; break;
			case 'Sep': strMonth = 8; break;
			case 'Oct': strMonth = 9; break;
			case 'Nov': strMonth = 10; break;
			case 'Dec': strMonth = 11; break;
		}
		var theUTC = Date.UTC(t[5], strMonth, t[2], theHour, theMins, theSecs);
		var elapsed = Math.floor(((now - theUTC) /1000 ) /60);
		var totalTime;

			if(elapsed < 1){
				totalTime = 'One minute ago';
			}else if( elapsed < 60 && elapsed > 1){
				totalTime = elapsed+' minutes ago';
			}else if(elapsed < 119 && elapsed > 60){
				totalTime = 'One hour ago';
			}else if(elapsed < 60*24 && elapsed > 120){
				totalTime = Math.ceil(elapsed/60)+' hours ago';
			}else if(elapsed < 43200 && elapsed > 60*24){
				totalTime = Math.ceil(elapsed/(60*24))+' days ago';				
			}else if(elapsed < 86400 && elapsed > 43200){
				totalTime = 'One month ago';
			}else if(elapsed > 86400){
				totalTime = Math.ceil((elapsed/60)/30) +' months ago';
			}
	
		
	
		//Add Info to the screen
		if(data[0].source == 'web'){
			$('.twitterbox').prepend(data[0].source).prepend(' from the ').prepend(totalTime);
		}else{
			$('.twitterbox').prepend(data[0].source).prepend(' from ').prepend(totalTime);
		}
		
		var cleanTweet = ify.clean(data[0].text);
		
		$('.tweet').empty().append(cleanTweet).slideDown();
		

     


	});
	
 });


  /*
 * Twita@talinkahashifyer
 * http://www.dustindiaz.com
 * http://www.dustindiaz.com/basement/ify.html
 *
 * Copyright (c) 2009 Dustin Diaz
 * licensed under public BSD
 */
var ify = function() {
  return {
    "link": function(t) {
      return t.replace(/(^|\s+)(https*\:\/\/\S+[^\.\s+])/g, function(m, m1, link) {
        return ((m1 != '') ? ' ' : '') + '<a href=' + link + '>' + ((link.length > 25) ? link.substr(0, 24) + '...' : link) + '</a>';
      });
    },
    "at": function(t) {
      return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, function(m, m1, m2) {
        return ((m1 != '') ? ' ' : '') + '@<a href="http://twitter.com/' + m2 + '">' + m2 + '</a>';
      });
    },
    "hash": function(t) {
      return t.replace(/(^|\s+)\#([a-zA-Z0-9_]+)/g, function(m, m1, m2) {
        return ((m1 != '') ? ' ' : '') + '#<a href="http://search.twitter.com/search?q=%23' + m2 + '">' + m2 + '</a>';
      });
    },
    "clean": function(tweet) {
      return this.hash(this.at(this.link(tweet)));
    }
  };
}();




