jQuery(function(){
    jQuery('#searchsubmit').val('');
    
    var isMediaPage = false;
    var curr_page = window.location.pathname;
    
    if(curr_page.indexOf('/media/') != -1){
        isMediaPage = true;
    }
    
    if(jQuery('.tern_wp_youtube_video_meta_data').length != 0){
        isMediaPage = true;
    }
    
    if(jQuery('#nav-above').length != 0){
        jQuery('.nav-next').remove(); // remove the next video link
        if(jQuery('.tern_wp_youtube_video_meta_data').length != 0){
            jQuery('.nav-previous a').attr('href', '/media').html('<span class="meta-nav">&larr;</span> back to media');
        }else{
            if(curr_page.indexOf('/speeches/') == -1 && !isMediaPage){
                jQuery('.nav-previous a').attr('href', '/speeches').html('<span class="meta-nav">&larr;</span> back to speeches');
            }
        }
    }
    
    // do layout changes on the media page
    if(isMediaPage){
        jQuery('#flickr-sidebar').remove();
        
        jQuery('.page-item-1162').addClass('current_page_item'); // higlight the media nav item
        
        jQuery('#book-wrapper').show(); // show the book
        
        jQuery('#content .page-title').remove(); // get rid of the title
        jQuery('#content .entry-utility').remove(); // get rid of the tags
        
        jQuery('.tern_wp_youtube_video_meta_data').remove(); // remove video metat data
        
        jQuery('#comments').remove(); // remove comments
    }
    
    var isPhotosPage = false;
    
    if(curr_page.indexOf('/photos/') != -1){
        isPhotosPage = true;
    }
    
    // if photos page
    if(isPhotosPage){
        jQuery('#content h2').addClass('entry-title').css('margin', '40px 0 20px 0');
        if(jQuery('#photoalbum-nav').length != 0){
            jQuery('#photoalbum-nav').html('<a href="/photos" style="font-size: 12px; line-height: 18px; text-decoration: none; color: #888888;"><span>&larr;</span> back to photos</a>');
            jQuery('#content h2').css('margin', '20px 0 20px 0');
        }
        
        if(jQuery('#comments').length != 0){
            var comments = jQuery('#comments');
            var comments_p = comments.next();
            var context = comments_p.next();
            
            comments.remove();
            comments_p.remove();
            context.remove();
        }
    }
    
    jQuery('#access li:last').css('border', 'none');
});
