$(document).ready(function() {

    $('#recent-tweets').tweet({
        username: 'gulielmus',
        count: 5,
        template: "{text} {time}",
        loading_text: "loading tweets..."
    }).bind("loaded", function(){
        $('#recent-tweets .loading').remove();
        $('#recent-tweets ul.tweetList').slideDown('slow');
    });

    var key = '1fbbc05c3831c7819b2f3d96e0a68681';

    // Adjust the photo div's height
    // $('#photo').css('height', $(window).height() - 48);

    $('#recent-photos').flickr({
        api_key: key,
        user_id: '28085303@N00',
        type: 'search',
        sort: 'date-taken-desc',
        per_page: 15,
        callback: function() { 
            $('#recent-photos .loading').remove();

            $('#recent-photos img').css('opacity', 0.75).hover(
              function () { $(this).not('.selected').fadeTo('fast', 1.0); }, 
              function () { $(this).not('.selected').fadeTo('fast', 0.75); }
            );
            $('#recent-photos ul').slideDown('slow');
        }});

        $('#recent-blog').append('<ul></ul>');
        $.getJSON("http://blog.willbarton.com/api/read/json?callback=?", 
          function(data) { 
            console.log(data);
            $.each(data.posts.slice(0,5), function(i,posts){ 
              var type = this.type;

              var title;
              if (type == 'regular')
                title = this["regular-title"];
              else if (type == 'link')
                title = this["link-text"];
              else if (type == 'photo')
                title = $(this["photo-caption"]).text();

                $('#recent-blog ul').append('<li><a href="' + this.url + '">' + title + '</a> ' + this.date+ '</li>');
            });
            $('#recent-blog .loading').remove();
            $('#recent-blog ul').slideDown('slow');
        });

        $('#recent-writings').append('<ul></ul>');
        $.getJSON("http://writings.willbarton.com/api/read/json?callback=?", 
          function(data) { 
            console.log(data);
            $.each(data.posts.slice(0,5), function(i,posts){ 
              var type = this.type;

              var title;
              if (type == 'regular')
                title = this["regular-title"];
              else if (type == 'link')
                title = this["link-text"];
              else if (type == 'photo')
                title = $(this["photo-caption"]).text();

                $('#recent-writings ul').append('<li><a href="' + this.url + '">' + title + '</a> ' + this.date+ '</li>');
            });
            $('#recent-writings .loading').remove();
            $('#recent-writings ul').slideDown('slow');
        });

});

