function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }




    jQuery.get(
        'dynamic_carousel.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,link', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url)
{
var imgs = url;
imgs = imgs.split(',')
small_img = imgs[0] ;
widthz = imgs[1] ;
heightz = imgs[2] ;
title = imgs[3] ;
ptype = imgs[4] ;
catid = imgs[5] ;

    return '<div><div class="indimg"><a href="webpage.php?' + title + '&' + ptype + '&' + catid + ' "><img src="' + small_img + '" width="' + widthz + '" height="' + heightz + '" alt="" /></a></div></div>';
	//return  '<div>' + url + '</div>' ;
};

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.

        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
		
		scroll:1,
		buttonNextHTML: null,
        buttonPrevHTML: null,
        itemLoadCallback: mycarousel_itemLoadCallback,
		initCallback: mycarousel_initCallback
    });
});

function mycarousel_initCallback(carousel) {
     
    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

