$(document).ready(function() {

    //Delay so flash content is faded in (IE bug).
    $('.fade_wrapper').delay(500).customFadeIn(1000, function() {
        $(".latest_img").css("opacity", "0.1");
    });

    $('a').click(function() {
        customFadeOutAndGo($(this)); return false;
    });

    //Remove clicky fade nonsense from some types of links.
    $('a.no_fade').unbind('click');

});

var navigating = false;

function customFadeOutAndGo(link) {
    var current_pathname = window.location.pathname;
    var next_pathname = link.attr('href');

    //alert(current_pathname);
    //alert(current_pathname.indexOf('a-bold-personality'));
    //alert(next_pathname);
    //alert(next_pathname.indexOf('a-bold-personality'));
    
    if ((current_pathname.indexOf('a-bold-personality') == 1) && (next_pathname.indexOf('a-bold-personality') == -1)) {
        //$('div#column2').customFadeOut(1000);
        //$('div#column1').customFadeOut(1000);
        //$('li#shop').delay(1000).customFadeIn(1000);

        $('div#column2').customFadeOut(1000, function() {
            $('li#shop').customFadeIn(1000, function() {
                $('div#column1').delay(1000).customFadeOut(1000);
            });
        });        
        
        
    }

    if ((current_pathname.indexOf('a-bold-personality') == -1) && (next_pathname.indexOf('a-bold-personality') == 1)) {
        $('li#shop').delay(1500).customFadeOut(1000);
        $('li#shop').delay(1000);
    }

    if ((current_pathname.indexOf('online-shop') == 1)) {
        $('li#shop').delay(1000).customFadeIn(2000);
        $('li#shop-large').delay(1000).customFadeOut(1000);
    }


    
    //if ((current_pathname.indexOf('a-bold-personality') >= 0) && (next_pathname.indexOf('a-bold-personality') < 0)) {
    //    $('li#shop').customFadeIn(500).delay('2000'); 
    //    $('#column2').customFadeOut('1500');
    //}

    //Delay so flash fades have completed (IE bug).
    $('#factoid').delay(500).customFadeOut(100);

    $('.fade_wrapper').delay(2000).customFadeOut(1000, function() {
        if (!navigating) {
            navigating = true;
            goAfterFade(link);
        }
        return false;
    });
}

function goAfterFade(link) {
    if (navigating) {
        window.location.href = link.attr('href');
        navigating = false;
    }
}
