function mycarousel_initCallback(carousel, state)
{
    // Lock until all items are loaded. That prevents jCarousel from
    // setup correctly and we have to do that in the ajax callback
    // function with carousel.setup().
    // We're doing that because we don't know the exact height of each
    // items until they are added to the list.
    carousel.lock();

    jQuery.get(
        'http://www.heavy-r.com/plugs.xml',
        '',
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, xml)
{
    var $items = jQuery('item', xml);

    $items.each(function(i) {
        carousel.add(i + 1, mycarousel_getItemHTML(this));
    });

    carousel.size($items.size());

    // Unlock and setup.
    carousel.unlock();
    carousel.setup();

};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    date = getDateFromFormat($('date', item).text(), "yyyy-MM-dd HH:mm:ss") / 1000;
    currentDate = new Date();
    dateNow = currentDate.getTime() / 1000;
    if (dateNow - date < 60*60*24)
        added = Math.floor((dateNow - date) / (60 * 60)) + " hours ago";
    else if (dateNow - date > 60 * 60 * 24 && dateNow - date < 60*60*24*30)
        added =  Math.ceil((dateNow - date) / (60 * 60 * 24)) + " days ago";
    else
        added =  Math.floor((dateNow - date) / (60 * 60 * 24 * 31)) + " months ago";

    return '<p class="plugadded">Added ' + added + '</p><a class="carousel_link" href="'+$('link', item).text()+'" target="_blank"><img src="/scr/plugs/'+$('thumb', item).text()+'" width="140" height="105" title="'+$('title', item).text()+'" /><br /><p class="plugtitle">'+$('title', item).text()+'</p></a>';
};

