$(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");
        $('#promo_wrapper').customFadeIn(1);    
        $('div#footer').customFadeIn(500);
    });
    $('ul#main-nav-1').delay(500).customFadeIn(1000);

    $('a').click(function() {
        customFadeOutAndGo($(this)); return false;
    });

    //Remove clicky fade nonsense from some types of links.
    $('#promo_wrapper a').unbind('click');
    $('#links a').unbind('click');
    $('a.no_fade').unbind('click');

});

var navigating = false;

function customFadeOutAndGo(link) {
    //Fade any flash objects, have to complete fade before others! I.E!!!
    $('.flashObject').each(function(index) {
        thisMovie($(this).attr('name')).jsFadeOut(0.3);
    });
    
    $('#promo_wrapper').stop().css('display', 'none');

    //Delay so flash fades have completed (IE bug).
    $('#factoid').stop().delay(500).customFadeOut('100');
    $('ul#main-nav-1').stop().delay(500).customFadeOut(1000);
    $('div#footer').stop().delay(500).customFadeOut(1000);
    //$('#promo_wrapper').delay(500).customFadeOut(1);
    $('.fade_wrapper').stop().delay(500).customFadeOut(1000, function() {
        if (!navigating) {
            navigating = true;
            goAfterFade(link);
        }
        return false;
    });
}

function goAfterFade(link) {
    if (navigating) {
        window.location.href = link.attr('href');
        navigating = false;
    }
}
