_$ = jQuery;
SLIDE_SPEED = 250;

_$('#sidebar_index .panel .header').click(function() {
    if (_$(this).parent().is(':not(.active)')) {
        _$("#sidebar_index .active .content").slideUp(SLIDE_SPEED);
        _$('#sidebar_index .active div:not(.header)').hide();

        _$('#sidebar_index .active').removeClass('active');
        _$(this).parent().addClass('active');

        _$('#sidebar_index .active .content').slideDown(SLIDE_SPEED, function() {
            // Executed after animation is finished to prevent jagged animation
            _$('#sidebar_index .active .footer').find('div').andSelf().show();
        });
    }
});

_$('#sidebar_index #archive_link').click(function() {
    if (_$('#sidebar_index #newsletter_archive').is(':visible')) {
        _$('#sidebar_index #newsletter_archive').hide();
         _$('#sidebar_index .active .content').slideDown(SLIDE_SPEED);
    } else {
        _$('#sidebar_index .active .content').slideUp(SLIDE_SPEED, function() {
            _$('#sidebar_index #newsletter_archive').show();
        });
    }
});

_$(function() {
    _$('#sidebar_index .panel:not(.active) div').hide();
});

function showNews(container) {
    if (_$(container).is(':hidden')) {
        _$('#start').hide();
        _$(container).show();
    }
}
