var fadeTime = "5s";


$(function() {
    // Take care of moving the footer.
    footerStick()
    $(window).resize(footerStick);
    
    // Do fading banners.
    if ($("div#banner a").length > 1) {
        $("div#banner a.hidden").removeClass("hidden").hide();
        $("div#banner a:first").oneTime(fadeTime, function() {
            ticker($(this));
        });
    }
    
    // Wrap lists to allow colored bullet points.
    $("div.colored-bullets li").wrapInner('<div class="colored-bullet-wrapper"></div>').addClass("colored-bullet");
});


function ticker(me) {
    me.fadeOut("slow", function() {
        var next = me.next();
        if (next.length == 0) {
            next = $("div#banner a:first");
        }
        next.fadeIn("slow").oneTime(fadeTime, function() {
            ticker(next);
        });
    });
}


function footerStick() {
    
    // Put the footer at the bottom of the page.
    var nonContentHeight = $("div#header").height() +
                           $("div#breadcrumbs").height() +
                           $("div#site-tools").height();
    var windowHeight = $(window).height();
    var finalHeight = windowHeight - nonContentHeight - 261;
    if (finalHeight > $("div#content div.inner-padded").height()) {
        $("div#content div.inner-padded").height(finalHeight);
    }
    
    // Remove the sidebar content if empty.
    if ($("div#sidebar-content div.colored-bullets").html().replace(/\s/g, "").length == 0) {
        $("div#sidebar-content div.colored-bullets").remove();
    }
    if ($("div#sidebar-content").html().replace(/\s/g, "").length == 0) {
        $("div#sidebar-content").hide();
    } else {
    
        // Resize the sidebar content.
        var sidebarContentHeight = $("div#sidebar-content").height() + 45;
        var contentHeight = $("div#content").height();
        
        // Adjust for subscribe.
        if ($("div#subscribe").length > 0) {
            sidebarContentHeight = sidebarContentHeight + $("div#subscribe").height() + 15;
        }
        
        var difference = contentHeight - sidebarContentHeight;
        
        if (difference > 0) {
            var newHeight = $("div#sidebar-content").height() + difference;
            $("div#sidebar-content").height(newHeight);
        }
        
    }
    
}