var Portfolio = {
    
    show_hide_portfolio: function(show_hide) 
    {
        if (show_hide == 'show') {
            $('#portfolio_loading').hide();
            $('#portfolio_details_container').fadeIn(800);
            
        } else {
            $('#portfolio_details_container').hide();
            $('#portfolio_loading').fadeIn(800);
        }
    },
        
    /**
     * assign screen cap link event handlers
     */
    assign_screen_cap_link_handlers: function()
    {
        $('#portfolio_screen_cap_links a').click(function(event){
            var link_id = $(this).attr('id');
            var screenshot_id = link_id.replace('screenshot_link_', '');
            $('#portfolio_screen_cap_links li').removeClass('active');
            // $('#portfolio_screen_cap_links li#screenshot_' + screenshot_id).addClass('active');
            $('#portfolio_screen_cap_links li#screenshot_' + screenshot_id).addClass('loading');
            $('#screen_shot_container').fadeOut('fast');
            var url = 'pages/' + screenshot_id + '/portfolio_screenshot_update.js';
            setTimeout(function(){
                $.get(url, {'authenticity_token':encodeURIComponent(window._token), 'id':escape(screenshot_id)}, null, 'script');
            }, 300);
        })
    }
    
}

$(function(){
    
    // the about section's subnav links functionality
    $('#subnav_about a').click(function(event){
        var link_id = $(this).attr('id');
        var set_id = link_id.replace('link_about_', '');
        $.each(['overview', 'design', 'development'], function() {
            $('#about_' + this + '_mid_col, #about_' + this + '_right_col').stop().hide();
        });
        $.each($.browser, function(i) {
            var show_collection = $('#about_' + set_id + '_mid_col, #about_' + set_id + '_right_col');
            ($.browser.msie) ? show_collection.show() : show_collection.fadeIn(600);
        });
        
        $('#subnav_about li').removeClass('active');
        $('#' + link_id).parents('li').addClass('active');
    })
    
    // the portoflio section's subnav links functionality 
    $('#subnav_portfolio a').click(function(event){
        var link_id = $(this).attr('id');
        var portfolio_item_id = link_id.replace('portfolio_link_', '');
        $('#subnav_portfolio li').removeClass('active');
        $('#subnav_portfolio li#portfolio_item_' + portfolio_item_id).addClass('active');
        Portfolio.show_hide_portfolio('hide');
        
        var url = 'pages/' + portfolio_item_id + '/portfolio_item_update.js';
        $.get(url, {'authenticity_token':encodeURIComponent(window._token), 'id':escape(portfolio_item_id)}, null, 'script');
        // event.preventDefault();
    })
    
    Portfolio.assign_screen_cap_link_handlers();
})

$.ajaxSetup({'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}})