$(document).ready(function(){
	$("#new_products_carousel ul").empty()
});


function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        '/system/xml/new_products.xml',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery(xml).find('site').each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML($(this).find('image').text(), $(this).find('price').text(), $(this).find('url').text()));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url_image, price, url)
{
    return '<a href="' + url + '"><img src="' + url_image + '" alt="" /></a><div class="newPrice">'+ price +' &euro;</div>';
};

jQuery(document).ready(function() {
    jQuery('#new_products_carousel').jcarousel({
start: 0,
        itemLoadCallback: mycarousel_itemLoadCallback
    });
});




