function mycarousel_itemLoadCallback(carousel, state) {
    var carouselId = carousel.list.attr('id');
    var itemListId = '#' + carouselId + '_itemList';
    var itemList = eval(carouselId + "_itemList");

    if (document.getElementById(carouselId) == "undefined" || document.getElementById(carouselId) == null)
        return;

    carousel.size(itemList.length);
    if (itemList.length > 1) {
        $('.jcarousel-control').show();
    }

    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > itemList.length) {
            carousel.size(itemList.length);
            break;
        }

        // Create an object from HTML
        var index = i - 1;
        var item = jQuery(mycarousel_getItemHTML(itemList[index])).get(0);

        carousel.add(i, item);
    }
};

function highlight(carousel, objectli, liindex, listate) {
    var carouselId = carousel.list.attr('id');
    var itemListId = '#' + carouselId + '_itemList';
    var itemList = eval(carouselId + "_itemList");
    var teasersize = itemList.length;

    actindex = (liindex % teasersize); // calculate which item this corresponds to after first scroll
    if (actindex == 0)
        actindex = teasersize;
    jQuery('#external a').removeAttr("class", "active");
    jQuery('#external a#link' + actindex).attr("class", "active");
};
function removehighlight(carousel, objectli, liindex, listate) {
    var carouselId = carousel.list.attr('id');
    var itemListId = '#' + carouselId + '_itemList';
    var itemList = eval(carouselId + "_itemList");
    var teasersize = itemList.length;

    actindex = teasersize - (liindex % teasersize);
    if (actindex == 0)
        actindex = teasersize;
    jQuery('.jcarousel-control a#link' + actindex).removeAttr("class", "active");
};

function mycarousel_fadeOut(carousel, state) {
    var JCcontainerID = carousel.clip.context.id;
    //    $('#' + JCcontainerID).fadeOut();

    mycarousel_itemLoadCallback(carousel, state);
}

function mycarousel_fadeIn(carousel) {
    var JCcontainerID = carousel.clip.context.id;
    //    $('#' + JCcontainerID).fadeIn();
}

function mycarousel_getItemHTML(item) {
    if (typeof (item) == "undefined" || item == null)
        return;

    var url_m = item.link;
    return '<a href="' + url_m + '" title="' + item.title + '"><img src="' + item.url + '" width="100%" height="100%" border="0" alt="' + item.title + '" /></a>';
};

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function () {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    // 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();
    });
};

