
function appendItemCallback(carousel, start, last, data)
{
    var items = data.split("|");
    for (i = start; i <= last; i++) {
        if (items[i-1] == undefined) {
            break;
        }
        var item = carousel.add(i, getItemHTML(items[i-1]));
        item.each(function() {
            // Urgh...ThickBox should provide a function for that
            jQuery("a.thickbox", this).bind("click", function() {
                var t = this.title || this.name || null;
                var g = this.rel || false;
                TB_show(t,this.href,g);
                this.blur();
                return false;
            });
        });
    }
    // Trigger loaded
    carousel.loaded();
};


// Next-Button handling...
var nextOver = function() {
    jQuery(this).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/next-over.gif");
};

var nextOut = function() {
    jQuery(this).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/next.gif");
};

var nextDown = function() {
    jQuery(this).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/next-down.gif");
};

function nextButtonStateHandler(carousel, button, enabling)
{
    if (enabling) {
        jQuery(button).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/next.gif")
                      .bind("mouseover", nextOver)
                      .bind("mouseout", nextOut)
                      .bind("mousedown", nextDown);
    } else {
        jQuery(button).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/next-disabled.gif")
                      .unbind("unmouseover", nextOver)
                      .unbind("unmouseout", nextOut)
                      .unbind("unmousedown", nextDown);
    }
}

// Prev-Button handling
var prevOver = function() {
    jQuery(this).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/prev-over.gif");
};

var prevOut = function() {
    jQuery(this).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/prev.gif");
};

var prevDown = function() {
    jQuery(this).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/prev-down.gif");
};

function prevButtonStateHandler(carousel, button, enabling)
{
    if (enabling) {
        jQuery(button).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/prev.gif")
                      .bind("mouseover", prevOver)
                      .bind("mouseout", prevOut)
                      .bind("mousedown", prevDown);
    } else {
        jQuery(button).attr("src", "http://images.jacketflap.com/img/horizontal-ie7/prev-disabled.gif")
                      .unbind("unmouseover", prevOver)
                      .unbind("unmouseout", prevOut)
                      .unbind("unmousedown", prevDown);
    }
}

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function itemFirstInHandler(carousel, li, idx, state) {
    display("Item #" + idx + " is now the first item");

    if (state != 'init')
        return;
    var cr = carousel;
    jQuery(".jcarousel-control").bind("click", function() {
        cr.scroll(parseInt(jQuery(this).html()));
        return false;
    });
}

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered before animation.
 */
function itemVisibleInHandlerBeforeAnimation(carousel, li, idx, state) {
    // No animation on first load of the carousel
    if (state == "init")
        return;
    jQuery("img", li).hide();
    jQuery("img", li).show("slow");
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

/**
 * Helper function for printing out debug messages.
 * Not needed for jCaoursel.
 */
function display(s)
{
    jQuery('#display').get(0).innerHTML += s + "<br />";
    jQuery('#display').get(0).scrollTop += 10000;
}
