$( document )
 .ready( function() {
    if ( BrowserDetect.browser == "Safari" ) {
        $( "#nav li a" )
         .css( "-webkit-transition-duration",
               "0s" );
    }

    var gallerify = function() {
        $( ".gallery a" )
         .fancybox( { overlayOpacity:
                       0.7,
                      overlayColor:
                       "#555555" } );
        $( ".gallery li:nth-child( n + 7 )" )
         .hide();
    };

    $( "#morePostsLoading" )
     .hide();
    $( "#morePosts" )
     .live( "click",
            function( e ) {
                $.get( $( this )
                        .attr( "href" ),
                       function( data ) {
                           $( "#morePostsLoading" )
                            .hide();
                           $( "#features" )
                            .append( $( data )
                                      .find( "#features > li" ));
                           if ( $( data )
                                 .find( "#morePosts" )
                                 .length ) {
                               $( "#morePosts" )
                                .attr( "href",
                                       $( data )
                                        .find( "#morePosts" )
                                        .attr( "href" ));
                               $( "#morePosts" )
                                .show();
                           }
                           gallerify();
                       } );
                $( "#morePosts" )
                 .hide();
                $( "#morePostsLoading" )
                 .show();
                e.preventDefault();
            } );

    gallerify();
 } );

