var carousels = [];
function initCarousel(ruta,max) {
    carousels[ruta] = [];
    carousels[ruta]['max'] = parseInt(max);
    carousels[ruta]['index'] = 0;
    jQuery(ruta+' ul li').each(function (index) {
        if (index >= max) {
            jQuery(this).hide();
        }
    }); 
};
function nextCarousel(ruta) {
    
    var max = carousels[ruta]['max'];
    
    var height = jQuery(ruta+' ul li:first-child').height();
    
    jQuery(ruta+' ul li:first-child').clone().appendTo(ruta+' ul');
    jQuery(ruta+' ul li:first-child').remove();
    
    jQuery(ruta+' ul li').each(function (index) {
        if (index >= max) {
            jQuery(this).hide();
        } else {
            jQuery(this).show();
        }
    }); 
    
    jQuery(ruta+' ul li').css('top',height+'px');
    jQuery(ruta+' ul li').animate({top:0});
    
    jQuery(".gallery").each(function(index, obj){
		var galleryid = Math.floor(Math.random()*10000);
		jQuery(obj).find("a").colorbox({rel:galleryid, maxWidth:"95%", maxHeight:"95%"});
	});
    
    adjustStyles();
    
};
function prevCarousel(ruta) {
    
    var max = carousels[ruta]['max'];
    
    var height = jQuery(ruta+' ul li:last-child').height();
    
    jQuery(ruta+' ul li:last-child').clone().prependTo(ruta+' ul');
    jQuery(ruta+' ul li:last-child').remove();
    
    jQuery(ruta+' ul li').each(function (index) {
        if (index >= max) {
            jQuery(this).hide();
        } else {
            jQuery(this).show();
        }
    }); 
    
    jQuery(ruta+' ul li').css('top','-'+height+'px');
    jQuery(ruta+' ul li').animate({top:0});
    
    jQuery(".gallery").each(function(index, obj){
		var galleryid = Math.floor(Math.random()*10000);
		jQuery(obj).find("a").colorbox({rel:galleryid, maxWidth:"95%", maxHeight:"95%"});
	});
    
    adjustStyles();
    
}
