
function mycarousel_itemLoadCallback( carousel, state ) {

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

    jQuery.get(
        'jcarousel-xml-press.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 ) {
        var src = jQuery( this ).find( 'src' ).text();
        var href = jQuery( this ).find( 'href' ).text();
        carousel.add( first + i, mycarousel_getItemHTML( href, src ) );
    } );

};

/* ***** Item html creation helper. ***** */
function mycarousel_getItemHTML( href, src ) {
    var rv = ( '<img src="' + src + '" width="100" height="130" alt="" />' );
    if ( href.length ) { rv = ( '<a href="' + href + '" target="_blank">' + rv + '</a>' ); }
    return rv;
};

var $jp = jQuery.noConflict();
$jp( document ).ready( function() {
    $jp( '#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); } },
        vertical: true,
        itemLoadCallback: mycarousel_itemLoadCallback
    } );
} );

