
/*function mycarousel_itemLoadCallback(carousel, state) // dynamic content loading via Ajax
{
    // 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
    carousel.size(parseInt(jQuery('total', xml).text()));
 
    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};*/

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
	//alert(mycarousel_itemList[idx - 1].href);
};
 
function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};
 
/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
	//alert(item.href);
    return '<a href="' + item.href + '"><img src="' + item.url + '" width="135" height="100" alt="' + item.title + '" /></a><div class="pname"><a href="' + item.href + '">' + item.title + '</a></div>';
};

// For auto start
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    }, function() {
		carousel.startAuto(2);
	});
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    }, function() {
		carousel.startAuto(2);
	});
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
 
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
		auto: 2,
		scroll: 1,
		visible: 4,
        wrap: 'circular',
        initCallback: mycarousel_initCallback,
		/*itemLoadCallback: mycarousel_itemLoadCallback, // dynamic content loading via Ajax */
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
});

