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

    jQuery.get(
        '../site/lista_produtos.php',
        {
            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('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url)
{
	/// monta div
	var url
	var vals=url.split("###");
	var nome=vals[0];
	var imagem=vals[1];
	var idloja=vals[2];
	var preco=vals[3];
	
//	if (preco!="")
//	{ preco="<br /><span class='precoprod'>"+preco+"</span>"; }
	
	var html_this='<a href="../lojas/loja.php?id='+idloja+'" title="Veja onde comprar"><img src="../imagens/produtos/'+imagem+'" width="60" height="60" alt="'+nome+'" class="produto" />'+'<span class="nomeprod">'+nome+'</span><br /><span class="precoprod">'+preco+'</span></a>';
    return html_this;
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.
	size: 5,
	scroll: 5,
       itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
       itemLoadCallback: mycarousel_itemLoadCallback
    });
});