function processTweets(data) {
  var tweet;
  var limit = 5;
  var monthes = [
    "Null",
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec"
  ];
  var container = document.getElementById("floatUl");
  var length = data.length;
  if (length == 0) {
    return;
  }
  if (length > limit) {
    length = limit;
  }
  tweet = data[0];
  appendTweet(tweet, monthes, container);
  for (var i = length - 1; i >= 0; i--) {
    tweet = data[i];
    appendTweet(tweet, monthes, container);
  }
}

function formatDayWithEnding(day) {
  if (day == 1) {
    return day + "st";
  }
  else if (day == 2) {
    return day + "nd";
  }
  else if (day == 3) {
    return day + "rd";
  }
  else {
    return day + "th";
  }
}

function appendTweet(tweet, monthes, container) {
  var date, listItem, anchor, span
  date  = new Date(tweet.created_at);
  listItem  = document.createElement("li");
  anchor    = document.createElement("a");
  span      = document.createElement("span");
  anchor.setAttribute("href", "http://twitter.com/"
    + tweet.user.screen_name + "/statuses/" + tweet.id_str);
  anchor.innerHTML  = tweet.text;
  span.innerHTML    = date.getHours() + ":" + date.getMinutes()
    + " " + monthes[date.getMonth()]
    + " " + formatDayWithEnding(date.getDate())
    + (tweet.source ? " via " + tweet.source : "")
    + (tweet.in_reply_to_screen_name
      ? ' <a href="http://twitter.com/'
        + tweet.in_reply_to_screen_name + '/status/'
        + tweet.in_reply_to_status_id_str
        + '">in reply to ' + tweet.in_reply_to_screen_name + '</a>'
      : ""
    );
  listItem.appendChild(anchor);
  listItem.appendChild(span);
  container.appendChild(listItem);
}
