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

    jQuery.get(
        '/templates/admin/carousels/carousel.php',
        {
            first: carousel.first,
            last: carousel.last,
	    url: carousel.options.url
        },
        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('product', xml).each(function(i) {
        var str = carousel.options.htmlCallback($(this).find("image").text(), $(this).find("url").text(),
                $(this).find("price").text(), $(this).find("merchant").text(), $(this).find("brand").text(),
                 $(this).find("name").text());
	carousel.add(first + i, str);
    });
};

/**
 * Item html creation helper.
 */
function beautylassmain_HTML(image, url, price, merchant, brand, name)
{
    var text = '<a href="' + url + '" target="_blank"><img src="' + image + '" class="jcarousel-img" /></a>';
    text += '<div class="jcarousel-item-extrainfo">' + name + '<br />' + price + '</div>';
    return text;
};

function tearoommall_HTML(image, url, price, merchant, brand, name)
{
    var text = '<a href="' + url + '"><img src="' + image + '" class="jcarousel-img" /></a>';
    text += '<div class="jcarousel-item-extrainfo">' + merchant + '<br />' + price + '</div>';
    return text;
}

function generate_carousel(cssid, xmlurl, callback)
{
  jQuery(document).ready(function() {
    jQuery(cssid).jcarousel({
        itemLoadCallback: mycarousel_itemLoadCallback,
        url: xmlurl,
        htmlCallback: callback
    });
  });
}
generate_carousel("#brands", "http://shops.popshops.com/shops/8pi71sl0wheh0ljl2c9j0l4jc.xml", beautylassmain_HTML);
generate_carousel("#face", "http://shops.popshops.com/shops/0fshzm7jyx1thpdzcsp56f6um.xml", beautylassmain_HTML);
generate_carousel("#mascara", "http://shops.popshops.com/shops/8npm5eoxil1pn9aem0bz096m8.xml", beautylassmain_HTML);
generate_carousel("#eyeliner", "http://shops.popshops.com/shops/0n6ov2bhrf7nua5bgrq2wq8if.xml", beautylassmain_HTML);
generate_carousel("#eyes", "http://shops.popshops.com/shops/5l11hnph1uaz49qv60xjxkkrf.xml", beautylassmain_HTML);
generate_carousel("#eyeshadow", "http://shops.popshops.com/shops/14rhqwwow0gycptz04poyqyqh.xml", beautylassmain_HTML);
generate_carousel("#beautylassmain", "http://shops.popshops.com/shops/029p1xer7pgcokmnsecdd9yjq.xml", beautylassmain_HTML);
generate_carousel("#tearoommall", "http://shops.popshops.com/shops/0eqymft3wvianptl9rdb08x6y.xml", tearoommall_HTML);
generate_carousel("#skin789", "http://shops.popshops.com/shops/48jm9wde1y3iopsdeurtl6ugo.xml", tearoommall_HTML);
generate_carousel("#botanicals789", "http://shops.popshops.com/shops/09efit6flb3za7ocqm9v46a8o.xml", tearoommall_HTML);

