$(function() {
    $('#headline, #footer-announcement').each(function() {
        var messages = $(this).find('.announcement'),
            cur = -1,
            interval = 10000,
            speed = 700;
        var next = function() {
            if (messages.length < 2) return;
            messages.eq(cur).animate({opacity: 0}, speed, function() {
                $(this).hide();
            });
            cur = (cur + 1 + messages.length) % messages.length;
            messages.eq(cur).show().animate({opacity: 1}, speed);
        }
        $(window).bind('custom-load', function() {
            var t = setInterval(next, interval);
            $(this).hover(function() {
                clearInterval(t);
            }, function() {
                t = setInterval(next, interval);
            });
            next(0);
        });
    });

    // Preload logo swap
    $(window).load(function() {
        var el = $('#header h1 a').clone(false).addClass('hover').css({
            position: 'absolute', top: -99999
        }).appendTo('#header h1').remove();
    });
    
    // Select content for header search input.
    $('input#id_search').bind('focus click', function() {
        $(this).select();
    });
});

