$(function() {
  

  var counter = 8;
  $.ajax({
    url: "/friendfeed/_slice/" + counter,
    success: function( response ) {
      var $content = $("#content")
      $content.css({"padding": "0", "width": $content.width() + 20 + "px", "height": $content.height() + 20 + "px" });
      $(document.createElement("ul")).append( response ).appendTo("#content");
      var timer = setInterval( function() {
          $.ajax({
            url: "/friendfeed/_item/" + (++counter),
            success: function( response ) {
              $(response).hide().appendTo("#content ul").slideDown('slow');
              if ( counter > 15 ) {
                $("#content ul li:first").remove();
              }
            },
            error: function() {
              clearTimeout( timer );
            }
          });
      }, 5000 );
    },
    error: function() {
      $("#wrapper").addClass("small");
      $("#content").hide();
    }
  });
});
