// Set thickbox loading image
tb_pathToImage = "images/loading-thickbox.gif";

function mycarousel_itemLoadCallback(carousel, state) {
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) { continue; }
        if (i > mycarousel_itemList.length) { break; }
        // Create an object from HTML
        var o = mycarousel_itemList[i-1];
        var item = jQuery(mycarousel_getItemHTML(o)).get(0);
        // Apply thickbox
        tb_init(item, o.desc);
        carousel.add(i, item);
    }
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item) {
    var url_m = item.url.replace(/_s.jpg/g, '_m.jpg');
    var o = '<a href="' + url_m + '" title="' + item.title + '" longdesc="' + item.desc + '"><img src="' + item.url + '" class="thumbnail" alt="' + item.title + '" /></a>';
    return o;
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        size: mycarousel_itemList.length,
	scroll: 4,
        itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
    });
});

