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

var mycarousel_itemList = [
    {url: "http://www.webcam-talloires.com/images/archives/webcam-talloires-01.jpg", title: "Cottage Bise Talloires"},
    {url: "http://www.webcam-talloires.com/images/archives/webcam-talloires-6.jpg", title: "Webcam Lac Annecy Talloires"},
    {url: "http://www.webcam-talloires.com/images/archives/webcam-talloires-5.jpg", title: "Hotel Cottage Bise Annecy"},
    {url: "http://www.webcam-talloires.com/images/archives/webcam-talloires-4.jpg", title: "Webcam Talloires Lac Annecy Haute Savoie"},
    {url: "http://www.webcam-talloires.com/images/archives/webcam-talloires-3.jpg", title: "Hotel restaurant Le Cottage Bise"},
    {url: "http://www.webcam-talloires.com/images/archives/webcam-talloires-2.jpg", title: "Webcam Talloires"},
    {url: "images/archives.gif", title: "Lac d'Annecy Talloires"},
    {url: "images/archives.gif", title: "Webcam Lac Annecy"},
    {url: "images/archives.gif", title: "Hotel restaurant Annecy"},
    {url: "images/archives.gif", title: "Le Cottage Bise Talloires Lac Annecy"}
];

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="75" height="75" border="0" alt="' + item.title + '" /></a>';
};

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