/* These functions are to do with the homepage news content and the
   posts that show on /news/ etc. Similiar code is gonna be needed by
   the blogs I think. ~jaymz */

function loadNews(e) {
    e.preventDefault();
    $('#latest-news').html('<div class="loader_icon"></div>');
    $('#latest-news').load($(this).attr('href'), function(response, status, xhr) {
        if(status=="error") {
            $('#latest-news').html('<div class="post"><h2>Sorry!</h2><p>Something has gone wrong in the tubes.</p></div>');
        } else {
            Shadowbox.setup($('a.add-comment')); // rebind SB to comment links
        }
    });
    $('.news_filter_selected').remove();
    $(this).before('<span class="news_filter_selected">&#x25B8;</span>');
}

function showArchiveLinks() {
    var target = this;
    var year_id = $(target).next('.news-yearlinks').attr('id');
    $('.news-yearlinks').not('#'+year_id).slideUp(function() {
        $('.yearlinks-active').html('&#x25B8;');
        $(target).next('.news-yearlinks').slideDown();
        $(target).children('.yearlinks-active').html('&#x25BE;');
    });
}

$(document).ready(function() {
    $('#news-filter ul li a').not('.rss-small').bind('click', loadNews);
    $('#archive-list .titlebar').bind('click', showArchiveLinks);
    $('.news-yearlinks:not(:first)').hide().prev('.titlebar').append('<span class="yearlinks-active">&#x25B8;</span>');
    $('.news-yearlinks:first').prev('.titlebar').append('<span class="yearlinks-active">&#x25BE;</span>');
    $('#search-keywords').click(function () {
        $(this).val('');
    });
	var JSKitConfig = {
               'comments-paginate': '5',
               'comments-editable': 'yes'
        };
    /* The most popular box on the news sidebar */
    $('#popbox-content li').hide(); // hide everything but the first
    $('#popbox-select li').click(function() {
        var target_class = $(this).attr('class');
        $('#popbox-content li.'+target_class).show();
    });

});


