$(document).ready(function(){
    var d = document;

    // Preload the navbar hover images
    if (d.images){
        d.images2Preload = new Array();
        var x = 0;

        $('#navbar img').each(function(){
            d.images2Preload[x] = new Image;
            d.images2Preload[x++].src = $(this).attr('src').replace('.gif','-active.gif');

            // While we're in the loop, check for any images with an active class
            if ($(this).attr('class').indexOf('active') != -1){
                var newSrc = $(this).attr('src').replace('.gif','-active.gif');
                $(this).attr('src', newSrc);
            }
        });
    }

    // Navbar hover action
    $('#navbar img').hover(function(){
        // in
        var curSrc = $(this).attr('src');

        if (curSrc.indexOf('-active') == -1){
            var newSrc = $(this).attr('src').replace('.gif','-active.gif');
            $(this).attr('src', newSrc);
        }
    }, function(){
        // out
        var curClass = $(this).attr('class');
        var curSrc   = $(this).attr('src');

        // Don't revert to normal if image is active
        if (curClass.indexOf('active') == -1){
            // Don't revert to normal if image is not active
            if (curSrc.indexOf('-active') != -1){
                var newSrc = $(this).attr('src').replace('-active.gif','.gif');
                $(this).attr('src', newSrc);
            }
        }
    });
});