$(document).ready(function() {
    $('#news-carousel').jcarousel({
        // Configuration goes here
        vertical: true,
        wrap: 'circular',
        auto: 6,
        visible:4,
        scroll:1,
        animation: 2000,
        itemVisibleInCallback: {onBeforeAnimation: newsCarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: newsCarousel_itemVisibleOutCallback},
        buttonNextHTML:null,
        buttonPrevHTML:null
    });

});

function newsCarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, newsCarousel_itemList.length);
    carousel.add(i, newsCarousel_getItemHTML(newsCarousel_itemList[idx - 1]));
};

function newsCarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function newsCarousel_getItemHTML(item)
{
    return '<div class="date">' + item.date + '</div>' + 
    '<h2><a href="' + item.url + '">' + item.title + '</a></h2>' +
    '<p>' + item.content + '</p>';
};
