function loadItemHandler(carousel, start, last, available)
{
    if (!available) {
        for (var i = start; i <= last; i++) {
           if (i > itemList.length)
		   {
                break;
            }
            carousel.add(i, getItemHTML(itemList[i - 1], itemListLink[i - 1], itemListTitulo[i-1]));
        }
    }

    // Trigger loaded
    carousel.loaded();
};

function getItemHTML(url, linkurl, title)
{
    return '<a href="' + linkurl + '"><img src="' + url + '" width="' + 75 + '" height="' + 75 + '" alt="' + title + '" /><\/a>';
};

// Next-Button handling...
var nextOver = function() {
    jQuery(this).attr("src", "/imagenes/icos/fl_next-over.gif");};

var nextOut = function() {
    jQuery(this).attr("src", "/imagenes/icos/fl_next.gif");};

var nextDown = function() {
    jQuery(this).attr("src", "/imagenes/icos/fl_next-down.gif");};

function nextButtonStateHandler(carousel, button, enabling)
{
    if (enabling) {
        jQuery(button).attr("src", "/imagenes/icos/fl_next.gif")
                      .bind("mouseover", nextOver)
                      .bind("mouseout", nextOut)
                      .bind("mousedown", nextDown);
    } else {
        jQuery(button).attr("src", "/imagenes/icos/fl_next-disabled.gif")
                      .unbind("unmouseover", nextOver)
                      .unbind("unmouseout", nextOut)
                      .unbind("unmousedown", nextDown);
    }
}

// Prev-Button handling
var prevOver = function() {
    jQuery(this).attr("src", "/imagenes/icos/fl_prev-over.gif");};

var prevOut = function() {
    jQuery(this).attr("src", "/imagenes/icos/fl_prev.gif");};

var prevDown = function() {
    jQuery(this).attr("src", "/imagenes/icos/fl_prev-down.gif");};

function prevButtonStateHandler(carousel, button, enabling)
{
    if (enabling) {
        jQuery(button).attr("src", "/imagenes/icos/fl_prev.gif")
                      .bind("mouseover", prevOver)
                      .bind("mouseout", prevOut)
                      .bind("mousedown", prevDown);
    } else {
        jQuery(button).attr("src", "/imagenes/icos/fl_prev-disabled.gif")
                      .unbind("unmouseover", prevOver)
                      .unbind("unmouseout", prevOut)
                      .unbind("unmousedown", prevDown);
    }
}

// Ride the carousel...
jQuery(document).ready(function() {

    jQuery().ajaxStart(function() {
        jQuery(".loading").show();
    });

    jQuery().ajaxStop(function() {
        jQuery(".loading").hide();
    });
	

	
    jQuery("#mycarousel").jcarousel({
        itemVisible: 4, //cuantas /imagenes se ven
        itemScroll: 1, //cuantos avanza en modo automatico cada vez
		wrap: false , //true si quiero que cuando llegue al ultimo vuelva al principio rapidamente
        loadItemHandler: loadItemHandler,
        nextButtonStateHandler: nextButtonStateHandler,
        prevButtonStateHandler: prevButtonStateHandler
    });
});