$(document).ready(function() {
    
    if (_activeSection != 'portfolio' && _activeSection != 'motion') {
        
        if (_activeSection == 'bio') {
            
            $('#content_of_bio').slideDown('fast', function() {
                $('#content_of_bio').jScrollPane();
                })
                .removeClass('hide_photographer_content').addClass('show_photographer_content');
            $('#content_of_bio').parents().eq(0).addClass('show_jscrollpane_container');
            
        } else {
            $('#content_of_clients').slideDown('fast', function() {
                $('#content_of_clients').jScrollPane();
                })
                .removeClass('hide_photographer_content').addClass('show_photographer_content');
            $('#content_of_clients').parents().eq(0).addClass('show_jscrollpane_container');
        }
    }
    
    $('#main_nav_text a').click(function() {
        if (window.document.location.href.indexOf('dev.arcreps.com') !== - 1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=main';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=main';
            }
        } else if (window.document.location.href.indexOf('dichirico.com') !== -1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=main';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=main';
            }
        } else {
            window.document.location.href = '/photographers/info/?a=main';
        }
    });
    
    $('#contact_nav_text a').click(function() {
        if (window.document.location.href.indexOf('dev.arcreps.com') !== - 1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=contact';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=contact';
            }
        } else if (window.document.location.href.indexOf('dichirico.com') !== -1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=contact';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=contact';
            }
        } else {
            window.document.location.href = '/photographers/info/?a=contact';
        }
    });
    
    $('#about_nav_text a').click(function() {
        if (window.document.location.href.indexOf('dev.arcreps.com') !== - 1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=about';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=about';
            }
        } else if (window.document.location.href.indexOf('dichirico.com') !== -1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=about';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=about';
            }
        } else {
            window.document.location.href = '/photographers/info/?a=about';
        }
    });
    
    $('#news_nav_text a').click(function() {
        if (window.document.location.href.indexOf('dev.arcreps.com') !== - 1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=news';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=news';
            }
        } else if (window.document.location.href.indexOf('dichirico.com') !== -1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=news';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=news';
            }
        } else {
            window.document.location.href = '/photographers/info/?a=news';
        }
    });
        
    
    
    /*
    $('#main_nav_neg a').click(function() {
        if ($('#content_of_main').attr('class').indexOf('show_content') !== -1) {
            return false;
        } 

        // hide the photographer slideshow swf:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            $('#photographerSlideShowWrapper').slideUp().removeClass('show_photographer_slideshow').addClass('hide_photographer_slideshow');
        }

        $('#content_of_main').slideDown().removeClass('hide_content');
        
        // hide any photographer bio/clients contents:
        $('.show_photographer_content').slideUp().removeClass('show_photographer_content').addClass('hide_photographer_content');
        
        // hide the div that currently has active state:
        $('.show_content').slideUp();
        $('.show_content').addClass('hide_content');
        $('.show_content').removeClass('show_content');
        
        $('#content_of_main').addClass('show_content');

        // show the 'main' slide show in place of the photographer portfolio swf:
        if ($('#mainSlideShowWrapper').attr('class') == 'hide_main_slideshow') {
            $('#mainSlideShowWrapper').slideDown().removeClass('hide_main_slideshow').addClass('show_main_slideshow');
        }
       
        // set the 'main' button to 'active state':
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        $('#main_nav_neg a').removeClass('inactive_state').addClass('active_state');

    });
    */
    $('#contact_nav_text a').mouseover(function() {
        if ($('#contact_info_inner_wrapper').hasClass('hide_contact_info_inner_wrapper')) {
            $('#contact_info_inner_wrapper').fadeIn().removeClass('hide_contact_info_inner_wrapper').addClass('show_contact_info_inner_wrapper');
        }
    });

    $('#contact_nav_text a').mouseout(function() {
        if ($('#contact_info_inner_wrapper').hasClass('show_contact_info_inner_wrapper')) {
            $('#contact_info_inner_wrapper').fadeOut().removeClass('show_contact_info_inner_wrapper').addClass('hide_contact_info_inner_wrapper');
        }
    });

    $('#contact_nav_text a').click(function() {
        if (window.document.location.href.indexOf('dev.arcreps.com') !== - 1) {
            if (window.document.location.href.indexOf('/demo/') !== -1) {
                window.document.location.href = '/demo/photographers/info/?a=contact';
            } else {
                window.document.location.href = '/arcreps/photographers/info/?a=contact';
            }
        } else {
            window.document.location.href = '/photographers/info/?a=contact';
        }
    });

    /*
    $('#contact_nav a').click(function() {
        if ($('#content_of_contact').attr('class').indexOf('show_content') !== - 1) {
            return false;
        }

        // hide the photographer slideshow swf:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            $('#photographerSlideShowWrapper').slideUp().removeClass('show_photographer_slideshow').addClass('hide_photographer_slideshow');
        }

        $('#content_of_contact').slideDown().removeClass('hide_content');
        
        // hide any photographer bio/clients contents:
        $('.show_photographer_content').slideUp().removeClass('show_photographer_content').addClass('hide_photographer_content');
        
        // hide the div that currently has active state:
        $('.show_content').slideUp();
        $('.show_content').addClass('hide_content');
        $('.show_content').removeClass('show_content');
        $('#content_of_contact').addClass('show_content');
        
        // show the 'main' slide show in place of the photographer portfolio swf:
        if ($('#mainSlideShowWrapper').attr('class') == 'hide_main_slideshow') {
            $('#mainSlideShowWrapper').slideDown().removeClass('hide_main_slideshow').addClass('show_main_slideshow');
        }
        
        // set the 'contact' button to 'active state':
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        $('#contact_nav a').removeClass('inactive_state').addClass('active_state');
    });
    */
    /*
    $('#about_nav a').click(function() {
        if ($('#content_of_about').attr('class').indexOf('show_content') !== -1) {
            return false;
        }

        // hide the photographer slideshow swf:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            $('#photographerSlideShowWrapper').slideUp().addClass('hide_photographer_slideshow').removeClass('show_photographer_slideshow');
        }

        $('#content_of_about').slideDown().removeClass('hide_content');
        
        // hide any photographer bio/clients contents:
        $('.show_photographer_content').slideUp().removeClass('show_photographer_content').addClass('hide_photographer_content');
        
        // hide the div that currently has active state:
        $('.show_content').slideUp();
        $('.show_content').addClass('hide_content');
        $('.show_content').removeClass('show_content');

        $('#content_of_about').addClass('show_content');
        
        // show the 'main' slide show in place of the photographer portfolio swf:
        if ($('#mainSlideShowWrapper').attr('class') == 'hide_main_slideshow') {
            $('#mainSlideShowWrapper').slideDown().removeClass('hide_main_slideshow').addClass('show_main_slideshow');
        }
        
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        $('#about_nav a').removeClass('inactive_state').addClass('active_state');

    });
    */

    /*
    $('#news_nav a').click(function() {
        if ($('#content_of_news').attr('class').indexOf('show_content') !== -1) {
            return false;
        }

        // hide the photographer slideshow swf:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            $('#photographerSlideShowWrapper').slideUp().addClass('hide_photographer_slideshow').removeClass('show_photographer_slideshow');
        }

        $('#content_of_news').slideDown().removeClass('hide_content');
        
        // hide any photographer bio/clients contents:
        $('.show_photographer_content').slideUp().removeClass('show_photographer_content').addClass('hide_photographer_content');
        
        // hide the div that currently has active state:
        $('.show_content').slideUp();
        $('.show_content').addClass('hide_content');
        $('.show_content').removeClass('show_content');

        $('#content_of_news').addClass('show_content');
        
        // show the 'main' slide show in place of the photographer portfolio swf:
        if ($('#mainSlideShowWrapper').attr('class') == 'hide_main_slideshow') {
            $('#mainSlideShowWrapper').slideDown().removeClass('hide_main_slideshow').addClass('show_main_slideshow');
        }
        
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        $('#news_nav a').removeClass('inactive_state').addClass('active_state');

    });
    */


    $('#portfolio_nav_text_neg a').click(function() {
        
        if (_activeSection != 'portfolio') {
            window.document.location.href = _requestUri + '?a=portfolio';
        }
        // if the photographerSlideShow is already visible, do nothing:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            return false;
        }
    
        // hide the 'main' slide show if it is visible:
        if ($('#mainSlideShowWrapper').attr('class') == 'show_main_slideshow') {
            $('#mainSlideShowWrapper').slideUp().addClass('hide_main_slideshow').removeClass('show_main_slideshow');
        }

        // hide the current "content_box":
        $('.show_photographer_content').slideUp();
        $('.show_photographer_content').addClass('hide_photographer_content');
        $('.show_photographer_content').removeClass('show_photographer_content');

        // hide any boxes for main/contact/about/news:
        $('.show_content').slideUp().addClass('hide_content').removeClass('show_content');

        // if any of the main/contact/about/news buttons have 'active state', disable that now:
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        
        // hide the top buffer if it is showing:
        if ($('#content_box_top_buffer').hasClass('show_top_buffer')) {
            $('#content_box_top_buffer').removeClass('show_top_buffer').addClass('hide_top_buffer');
        }

        // lastly, show the photographer slide show:
        $('#photographerSlideShowWrapper').slideDown().removeClass('hide_photographer_slideshow').addClass('show_photographer_slideshow');
    });
    
    $('#motion_nav_text_neg a').click(function() {
        if (_activeSection != 'motion') {
            window.document.location = _requestUri + '?a=motion';
        }
    });
    
    $('#bio_nav_text_neg a').click(function() {
        if (_activeSection == 'portfolio' || _activeSection == 'motion') {
            window.document.location = _requestUri + '?a=bio';
        }
        
        // if the 'bio' is already visible, do nothing:
        if ($('#content_of_bio').hasClass('show_photographer_content')) {
            return false;
        }
        
        // if the photographerSlideShow is visible, we must hide it:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            $('#photographerSlideShowWrapper').slideUp().removeClass('show_photographer_slideshow').addClass('hide_photographer_slideshow');
        }
        
        // to prevent a 'bounce' annoyance, hide the main slide show for a sec:
        // lastly, show the main slide show ONLY IF IT ISN'T ALREADY VISIBLE:
        /* debug info: consider deleting this block after development.
        if ($('#mainSlideShowWrapper').hasClass('show_main_slideshow')) {
            $('#mainSlideShowWrapper').slideUp().removeClass('show_main_slideshow').addClass('hide_main_slideshow');
        }
        */
        
        // hide any boxes for main/contact/about/news:
        $('.show_content').slideUp().addClass('hide_content').removeClass('show_content');

        // hide the current "content_box". If the current "content_box" is "content_of_clients", 
        // be sure to hide its scrollbars:
        if ($('.show_photographer_content').attr('id') == 'content_of_clients') {
            
            if (!($('#content_of_clients').hasClass('was_destroyed'))) {
                $('#content_of_clients').addClass('was_destroyed');
            }
            // $('.show_photographer_content').parents(".jScrollPaneContainer").eq(0).remove();
            $('.show_photographer_content').parents(".jScrollPaneContainer").eq(0).removeClass('show_jscrollpane_container').addClass('hide_jscrollpane_container');
            
            $('.show_photographer_content').slideUp();
            $('.show_photographer_content').addClass('hide_photographer_content');
            $('.show_photographer_content').removeClass('show_photographer_content');
            document.getElementById('content_of_clients').parentNode.style.display = 'none';
        }
        
        
        
        // show the content_top_buffer div if it isn't already showing:
        // hide the top buffer if it is showing:
        if ($('#content_box_top_buffer').hasClass('hide_top_buffer')) {
            $('#content_box_top_buffer').removeClass('hide_top_buffer').addClass('show_top_buffer');
        }
        
        // check whether #content_of_bio div exists:
        if ($('#content_of_bio').hasClass('was_destroyed')) {
            // if we are in this block, it means the #content_of_bio wrapper (and parent) must be re-created:
            
            $('#content_of_bio').removeClass('hide_photographer_content').addClass('show_photographer_content');
            $('#content_of_bio').parents().eq(0).slideDown().removeClass('hide_jscrollpane_container').addClass('show_jscrollpane_container');
        } else {
            // if we are in this block, it means the jScrollPane had never existed and must be initialized:
            // show the 'bio' content box:
            $('#content_of_bio').slideDown('fast', function() {
                $('#content_of_bio').jScrollPane();
                })
                .removeClass('hide_photographer_content').addClass('show_photographer_content');
            $('#content_of_bio').parents().eq(0).addClass('show_jscrollpane_container');
        }
        
        // hack to fix a bug where display: none turns on for no reason after 4-5 toggles:
        document.getElementById('content_of_bio').style.display = 'block';
        document.getElementById('content_of_bio').parentNode.style.display = 'block';

        
        
        

        // if any of the main/contact/about/news buttons have 'active state', disable that now:
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        // add the active state to the 'bio' link:
        $('#bio_nav_text_neg a').removeClass('inactive_state').addClass('active_state');

        // lastly, show the main slide show ONLY IF IT ISN'T ALREADY VISIBLE:
        if ($('#mainSlideShowWrapper').hasClass('hide_main_slideshow')) {
            $('#mainSlideShowWrapper').slideDown("fast").removeClass('hide_main_slideshow').addClass('show_main_slideshow');
        }
    });
    
    $('#clients_nav_text_neg a').click(function() {
        if (_activeSection == 'portfolio' || _activeSection == 'motion') {
            window.document.location.href = _requestUri + '?a=clients';
        }
        
        // if the 'clients list' is already visible, do nothing:
        if ($('#content_of_clients').hasClass('show_photographer_content')) {
            return false;
        }
        
        // if the photographerSlideShow is visible, we must hide it:
        if ($('#photographerSlideShowWrapper').attr('class') == 'show_photographer_slideshow') {
            $('#photographerSlideShowWrapper').slideUp().removeClass('show_photographer_slideshow').addClass('hide_photographer_slideshow');
        }
        
        // to prevent a 'bounce' annoyance, hide the main slide show for a sec:
        // lastly, show the main slide show ONLY IF IT ISN'T ALREADY VISIBLE:
        /* debug info: consider deleting this block after development.
        if ($('#mainSlideShowWrapper').hasClass('show_main_slideshow')) {
            $('#mainSlideShowWrapper').slideUp().removeClass('show_main_slideshow').addClass('hide_main_slideshow');
        }
        */
        
        // hide any boxes for main/contact/about/news:
        $('.show_content').slideUp().addClass('hide_content').removeClass('show_content');

        // hide the current "content_box". If the current "content_box" is "content_of_bio", 
        // be sure to hide its scrollbars:
        if ($('.show_photographer_content').attr('id') == 'content_of_bio') {
            
            if (!($('#content_of_bio').hasClass('was_destroyed'))) {
                $('#content_of_bio').addClass('was_destroyed');
            }
            
            //$('.show_photographer_content').parents(".jScrollPaneContainer").eq(0).remove();
            $('#content_of_bio').parents(".jScrollPaneContainer").eq(0).removeClass('show_jscrollpane_container').addClass('hide_jscrollpane_container');
        
        
            $('.show_photographer_content').slideUp();
            $('.show_photographer_content').addClass('hide_photographer_content');
            $('.show_photographer_content').removeClass('show_photographer_content');
            
            document.getElementById('content_of_bio').parentNode.style.display = 'none';
        }

        // show the content_top_buffer div if it isn't already showing:
        // hide the top buffer if it is showing:
        if ($('#content_box_top_buffer').hasClass('hide_top_buffer')) {
            $('#content_box_top_buffer').removeClass('hide_top_buffer').addClass('show_top_buffer');
        }
        
        // check whether #content_of_clients div exists:
        if ($('#content_of_clients').hasClass('was_destroyed')) {
            // if we are in this block, it means the #content_of_clients_wrapper (and parent) must be re-created:
            
            $('#content_of_clients').removeClass('hide_photographer_content').addClass('show_photographer_content');
            $('#content_of_clients').parents().eq(0).slideDown().removeClass('hide_jscrollpane_container').addClass('show_jscrollpane_container');
            
        } else {
            // if we are in this block, it means the jScrollPane had never existed and must be initialized:
            // show the 'clients' content box...
            $('#content_of_clients').slideDown('fast', function() {
                $('#content_of_clients').jScrollPane();
                })
                .removeClass('hide_photographer_content').addClass('show_photographer_content');
                
            $('#content_of_clients').parents().eq(0).addClass('show_jscrollpane_container');
            
        }
        
        // hack to fix a bug where display: none turns on for no reason after 4-5 toggles:
        document.getElementById('content_of_clients').style.display = 'block';
        document.getElementById('content_of_clients').parentNode.style.display = 'block';
        
        

        // if any of the main/contact/about/news buttons have 'active state', disable that now:
        $('.active_state').addClass('inactive_state').removeClass('active_state');
        // add the active state to the clients link:
        $('#clients_nav_text_neg a').removeClass('inactive_state').addClass('active_state');

        // lastly, show the main slide show ONLY IF IT ISN'T ALREADY VISIBLE:
        if ($('#mainSlideShowWrapper').hasClass('hide_main_slideshow')) {
            $('#mainSlideShowWrapper').slideDown("fast").removeClass('hide_main_slideshow').addClass('show_main_slideshow');
        }
    });
});
