//Setup
var username = 'therhythmhut'; //Set your twitter username
var count = 3; //Set a limit of many posts you'd like to display (0 = no limit)
 
//No need to edit past this point
function gettweet(mytweets) {
  var statusHTML = [];
  for (var i=0; i<mytweets.length; i++){
    var username = mytweets[i].user.screen_name;
    var status = mytweets[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'" target="_blank">'+url+'</a>';
	}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  '<a href="http://twitter.com/'+reply.substring(1)+'" target="_blank">'+reply+'</a>';
    });
    statusHTML.push('<div class="tweet"><span class="tweet-title"><a href="http://twitter.com/' + username + '">@' + username + '</a></span><span class="tweet-date"> - '+converttime(mytweets[i].created_at)+'</span><br /><span class="tweet-text">'+status+'</span></div>');
  }
  //Fade out the loading graphic and append data
  $('.loader').fadeOut(1000, function() {
		$('#tweets').hide();
		 $('#tweets').append($(statusHTML.join('')));
		 if($('#tweets').height() > 190){
			$('.tweet:last').empty();
		 }
		 $('#tweets').fadeIn(750);
  });
}
//Convert to relative time
function converttime(thetime) {
	var values = thetime.split(" ");
	thetime = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
	var convertdate = Date.parse(thetime);
	var timeoffset = (arguments.length > 1) ? arguments[1] : new Date();
	var timeno = parseInt((timeoffset.getTime() - convertdate) / 1000);
	timeno = timeno + (timeoffset.getTimezoneOffset() * 60);
	var twttime = [[false,'less than a minute ago',60,1],[false,'about a minute ago',120,1],[true,' minutes ago',3600,60],[false,'about an hour ago',9600,1],[true,' hours ago',86400,3600],[false,'1 day ago',172800],[true,' days ago',172800,86400]];
	var i = 0;
	while(timeno > twttime[i][2] && i!=6){
		i++;
	}
	if (twttime[i][0] == false){
		return twttime[i][1];
	} else {
		return(parseInt(timeno / twttime[i][3])).toString() + twttime[i][1];
	}
}
//call Twitter script on DOM ready with jQuery

