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

var mycarousel_itemList = [
    {url: "gallery/INSP022.jpg", title: "INSP 022"},
    {url: "gallery/INSP023.jpg", title: "INSP 023"},
    {url: "gallery/INSP029.jpg", title: "INSP 029"},
    {url: "gallery/INSP030.jpg", title: "INSP 030"},
    {url: "gallery/INSP037.jpg", title: "INSP 037"},
    {url: "gallery/INSP049.jpg", title: "INSP 049"},
    {url: "gallery/INSP056.jpg", title: "INSP 056"},
];

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 item = jQuery(mycarousel_getItemHTML(mycarousel_itemList[i-1])).get(0);

        // Apply thickbox
        tb_init(item);

        carousel.add(i, item);
    }
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    var url_m = item.url.replace(/_s.jpg/g, '_m.jpg');
    return '<a href="' + url_m + '" title="' + item.title + '"><img src="' + item.url + '" width="216" height="160" border="0" alt="' + item.title + '" /></a>';
};

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

