/*
Funcions globals
*/
var galleryList = new Array();

var Gallery = {

  loadGallery : function(idGallery, prefix, showElements, idAnterior, idSiguiente, offset) {
    galleryList[idGallery] = new Object();
    galleryList[idGallery].currentPosition = 1;
    galleryList[idGallery].elementPrefix = prefix;
    galleryList[idGallery].gbNumElements = showElements;
		galleryList[idGallery].idAnterior = idAnterior;
		galleryList[idGallery].idSiguiente = idSiguiente;

    var first = $$("div#" + idGallery + " ul li")[0];
		var size = first.getSize();
		
		$(galleryList[idGallery].idAnterior).setStyle("display", "none");

		galleryList[idGallery].elementWidth = first.getCoordinates().width + offset; 
    var scroll = new Fx.Scroll($(idGallery), { wait: false, duration: 0, offset: {'x': -3, 'y': -7}, transition: Fx.Transitions.Quad.easeInOut });
    scroll.toElement(first);
  },
  
   // Devuelve el ancho/alto que debe ocupar la galería para quede en línea
	getGalleryWidth: function(contenedor) {
    var rtnValue = 0;
    if ($(contenedor)) {
      var lis = $$("#" + contenedor + " ul li");
			lis.each(function(element) {
				var size = element.getSize();
					size = size['size'].x;
					size += $(element).getStyle("marginRight").toInt() + 2;
					size += $(element).getStyle("marginLeft").toInt() + 2;

				rtnValue += size;
      });
			
    }
    return rtnValue;
  },
  
  galleryLength : function(idGallery) {
		var rtnValue = 0;
		
		var lis = $$("#" + idGallery + " ul li");
		rtnValue = lis.length;
		
		return rtnValue;
	},
  
  anterior : function(idGallery) {
         
        if (galleryList[idGallery].currentPosition > 1) {
            galleryList[idGallery].currentPosition--;
            var myFx = new Fx.Tween(($$("#" + idGallery + " ul")[0]), { duration: 500, transition: 'quad:inOut'});
						myFx.start("margin-left", ($$("#" + idGallery + " ul")[0]).getStyle("margin-left").toInt() + galleryList[idGallery].elementWidth);
						
						if (galleryList[idGallery].currentPosition==1) $(galleryList[idGallery].idAnterior).setStyle("display", "none");
						if (galleryList[idGallery].currentPosition < Gallery.galleryLength(idGallery)) $(galleryList[idGallery].idSiguiente).setStyle("display", "block");
        }

     },

  siguiente : function(idGallery) {

		if (Gallery.galleryLength(idGallery) > (galleryList[idGallery].currentPosition + (galleryList[idGallery].gbNumElements-1))) {
			galleryList[idGallery].currentPosition++;
		
			var myFx = new Fx.Tween(($$("#" + idGallery + " ul")[0]), { duration: 500, transition: 'quad:inOut'});
			myFx.start("margin-left", ($$("#" + idGallery + " ul")[0]).getStyle("margin-left").toInt() - galleryList[idGallery].elementWidth);
			
			if (galleryList[idGallery].currentPosition > 1) $(galleryList[idGallery].idAnterior).setStyle("display", "block");
			if (Gallery.galleryLength(idGallery) == galleryList[idGallery].currentPosition) $(galleryList[idGallery].idSiguiente).setStyle("display", "none");
			
    }
 }
		
};

