jQuery(function($) {
  
  function generate_tweet_li(profile_image_url, user_name, summary){
    return "<div style='margin-bottom: 5px; min-height: 48px;'><img style='float: left; margin-right: 5px;' src='" + profile_image_url + "' height='48' width='48' alt='" + user_name + "' /><div><b>" + user_name + "</b><br />" + summary + "</div></div><div style='clear: both; height: 1px; border-bottom: 1px solid #ebebeb; margin-bottom: 5px;'>&nbsp;</div>";
  }

  function updateTweets(){
    $.getJSON('/twitter-feed.js', function(data) {
      var items = [];
      
      $.each(data, function(key, val) {
        if(key != '_update_time') {
          items.push(generate_tweet_li(val['profile_image_url'], val['user_name'], val['summary']));
        }
      });
      
      $('#twitter_update_list').html($('<div/>', {
        'class': 'twitter_updated_list',
        html: items.join('')
      }));
    });
  }

  window.setInterval(updateTweets, 30000);
  updateTweets();
});
