document.tweets = [];

function add_tweets(tw) {
  $(tw).each(function() {
    document.tweets.push(this);
  });
}

function padded_month(month) {
  return month.length == 1 ? "0" + month : month;
}

function do_sort(a, b) {
  return b.id > a.id; 
}

function sort_tweets() {
  document.tweets = document.tweets.sort(do_sort);
}

function setup_tweets() {
  sort_tweets();
  var container = $('#tweets');
  for(var i = 0; i < 5; i++) {
    if(i < document.tweets.length) {
      var tweet = document.tweets[i];
      container.append("<li><img src=\"" + tweet.user.profile_image_url + "\"/><h4><a href=\"" + 'http://twitter.com/' + tweet.user.name +"\">" + tweet.user.name + "</a></h4><p>" + tweet.text + "</p></li>");
    }
  }
}