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 name_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 sname_HTML(image, url, price, merchant, brand, name)
{
    var text = '<a href="' + url + '" target="_blank"><img src="' + image + '" class="jsmallcarousel-img" /></a>';
    text += '<div class="jsmallcarousel-item-extrainfo">' + name + '<br />' + price + '</div>';
    return text;
};


function riotcarousel_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">' + merchant + '<br />' + price + '</div>';
    return text;
};

function brandcarousel_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">' + brand + '<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("#allproductcarousel", "http://shops.popshops.com/shops/4ufz8nzri8sp8yakuwydg3uio.xml", name_HTML);
generate_carousel("#riotcarousel", "http://shops.popshops.com/shops/8oh7awuk7miw5ys4rezdeznzh.xml", riotcarousel_HTML);
generate_carousel("#brandcarousel", "http://shops.popshops.com/shops/1i85cjjuc0616aalh6qc0ltou.xml", brandcarousel_HTML);
generate_carousel("#prevfeatured", "http://shops.popshops.com/shops/8ycbnckje512g1rwhd68thwjt.xml", name_HTML);
generate_carousel("#dress789", "http://shops.popshops.com/shops/c11ecc4d26044331a5f48e2d4f1b832e.xml", name_HTML);
generate_carousel("#tops789", "http://shops.popshops.com/shops/2461b5a812f7469e835cd9c9557dff50.xml", name_HTML);
generate_carousel("#pants789", "http://shops.popshops.com/shops/bd2b8c23c16046d49865e69c27fbcf08.xml", name_HTML);
generate_carousel("#skirts789", "http://shops.popshops.com/shops/8b7a6def750b446eba1d3aa536ac95b2.xml", name_HTML);
generate_carousel("#suits789", "http://shops.popshops.com/shops/dffafabeb4104e3aad429271345002c2.xml", name_HTML);
generate_carousel("#collections789", "http://shops.popshops.com/shops/cmzxdakdb9i1p2z8n65fniaon.xml", name_HTML);
generate_carousel("#coats789", "http://shops.popshops.com/shops/201418457e344ae8b75557061c9879c8.xml", name_HTML);
generate_carousel("#ensembles789", "http://shops.popshops.com/shops/aq9tsgf56asv3rrfit1twtkb4.xml", name_HTML);
generate_carousel("#swim789", "http://shops.popshops.com/shops/676ao4clas0dcv0yyb6wrdc4e.xml", name_HTML);
generate_carousel("#activewear789", "http://shops.popshops.com/shops/4bc9c29ff2b4469aaff0df59edfda750.xml", name_HTML);
generate_carousel("#sleepwear789", "http://shops.popshops.com/shops/de5546650a9f43f7a3a2e6ed032d946c.xml", name_HTML);
generate_carousel("#intimates789", "http://shops.popshops.com/shops/4irivhf6x2l2rzhp5w36mxly9.xml", name_HTML);
generate_carousel("#new789", "http://shops.popshops.com/shops/c4de4663c3fd43d0a1a4fa9a261ca61e.xml", name_HTML);
generate_carousel("#trends789", "http://shops.popshops.com/shops/f4rcbg2zbqyj9t4be7e82q30d.xml", name_HTML);
generate_carousel("#clubjr789", "http://shops.popshops.com/shops/4w4vxnu57o12xg8g9tzymql4g.xml", name_HTML);
generate_carousel("#scrubs789", "http://shops.popshops.com/shops/32sqy2xep5ir3tix4vyjpikov.xml", name_HTML);
generate_carousel("#wicking789", "http://shops.popshops.com/shops/ae8d4b869da2486f9f9e90e88f6c13b9.xml", name_HTML);
generate_carousel("#maternity789", "http://shops.popshops.com/shops/6n095trqxbvb99sq8o5c8x95l.xml", name_HTML);
generate_carousel("#costumes789", "http://shops.popshops.com/shops/dw0k5kug3h0yxlzd2rbgeirmr.xml", name_HTML);
generate_carousel("#vintage789", "http://shops.popshops.com/shops/08aiy7zxxp084q13886t7scqp.xml", name_HTML);
generate_carousel("#footwear789", "http://shops.popshops.com/shops/7b084b42670446f2a5acc8e374fa6ef7.xml", name_HTML);
generate_carousel("#jewelry789", "http://shops.popshops.com/shops/38246ecf7c5448e1bbf525d8dae484f6.xml", riotcarousel_HTML);
generate_carousel("#fragrance", "http://shops.popshops.com/shops/b5rd0gw92833co73fem5oytpz.xml", name_HTML);
generate_carousel("#accessories789", "http://shops.popshops.com/shops/d651c1b1e7fd415793c8dcc4f7b8b38a.xml", name_HTML);

generate_carousel("#sportsfan", "http://shops.popshops.com/shops/doukonmupgsg94ao754wn1a83.xml", name_HTML);
generate_carousel("#springaccessories", "http://shops.popshops.com/shops/6pei99ibio0d8nvcqc2pud5oa.xml", name_HTML);
generate_carousel("#springjewelry", "http://shops.popshops.com/shops/87o6eailulpmyh1yxiugc5xot.xml", name_HTML);

generate_carousel("#summeraccessories", "http://shops.popshops.com/shops/2ad6vdxncbvtkm262727nid6b.xml", name_HTML);
generate_carousel("#summerjewelry", "http://shops.popshops.com/shops/87k8iy3zqmxvb6mf77cybxh55.xml", name_HTML);

generate_carousel("#autumnaccessories", "http://shops.popshops.com/shops/e4266p8k382tk1shdx1kd82qd.xml", name_HTML);
generate_carousel("#autumnjewelry", "http://shops.popshops.com/shops/92kn6a47qjofeya1fcukzp5gr.xml", name_HTML);

generate_carousel("#winteraccessories", "http://shops.popshops.com/shops/bxj9ugfhb47bhb5vl79ni7lg8.xml", name_HTML);
generate_carousel("#winterjewelry", "http://shops.popshops.com/shops/3uo06grs15xqipwt0y81d9n0c.xml", name_HTML);
