function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'dynamic_ajax_php.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
	size = parseInt(jQuery('total', xml).text());
    carousel.size(size);
	rand_no = Math.ceil(size*Math.random());

    jQuery('company', xml).each(function(i) {
		image = $(this).find('image').text();
		url = $(this).find('url').text();
        carousel.add(first + i, mycarousel_getItemHTML(image, url));
	});
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url, xlink)
{
    return '<a href="' + xlink + '" target="_blank"><img src="' + url + '" alt="" /></a>';
};

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); }},
        itemLoadCallback: mycarousel_itemLoadCallback,
		start: jquery_cycler_start,
		scroll: 4,
		visible: 4
    });
});
