// Temporarily error handler
function presentError(text) {
  $('#tweet').append('<p>' + text + '</p>');
}

$(document).ready(function() {
  
  // Retrieve latest tweet from Aaron
  $.ajax({
    dataType: "jsonp",
    url: "http://twitter.com/statuses/user_timeline/AaronHillegass.json?count=1",
    success: function(data) {
    if ($.isArray(data) && data.length > 0) {
      var tweet = data[0];
      var date = new Date(tweet.created_at);
      $('#aarontweet').append('<div class="date">' + date.format("stylishDate") + ' ' + date.format("shortTime") + '</div><p>' + tweet.text + '</p>');
    } else {
      presentError('Could not fetch latest tweet.');
    }
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    presentError('Could not fetch latest tweet.');
  },
  complete: function(XMLHttpRequest, textStatus) {
      //$('#tweet_spinner').hide();
  }
  });

  // Retrieve latest tweet from Big Nerd Ranch
  $.ajax({
    dataType: "jsonp",
    url: "http://twitter.com/statuses/user_timeline/BigNerdRanch.json?count=1",
    success: function(data) {
    if ($.isArray(data) && data.length > 0) {
      var tweet = data[0];
      var date = new Date(tweet.created_at);
      $('#bnrtweet').append('<div class="date">' + date.format("stylishDate") + ' ' + date.format("shortTime") + '</div><p>' + tweet.text + '</p>');
    } else {
      presentError('Could not fetch latest tweet.');
    }
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    presentError('Could not fetch latest tweet.');
  },
  complete: function(XMLHttpRequest, textStatus) {
      //$('#tweet_spinner').hide();
  }
  });
  
});