/*
 * Eye candy
 */

function switchPages(content, newContent, url) {

    newContent
        .empty()
        .load(url + ' .postWrapper > *',
              function() { /* Callback to AJAX load */
                  create_vcard();
                  content
                      .animate({ opacity: 0}, 400 )
                      .animate({ height: newContent.height() },
                               'slow', 'swing',
                               function() { /* Callback to resize animation */
                                   content
                                       .html(newContent.html())
                                       .animate({ opacity: 1 }, 400);
                               });
              });

}


$(document).ready(function() {

    create_vcard();
        content = $('.postWrapper')
            .css('opacity', '0')
            .animate( {opacity: 1}, 1000 );

        newContent = $('<div id="incoming"></div>')
            .insertBefore('#canvas')
            .css({ 'position' : 'absolute',
                        'opacity' : '0',
                        'left' : '0',
                        'top' : '0'})
            .width($('.postWrapper').width());

        $('.page_item a')
            .removeAttr('title')
            .click(function (event) {
                    switchPages(content, newContent, $(event.target).attr('href'));
                    $('.page_item').removeClass('current_page_item');
                    $(event.target).blur().parent().addClass('current_page_item');
                    return false;
                });

        $('#header a')
            .click(function (event) {
                    switchPages(content, newContent, $(event.target).parent().attr('href'));
                    $('.page_item').removeClass('current_page_item');
                    $(event.target).parent().blur();
                    return false;
                });

    });
