//visor de imagenes
var destacados= new Class({
	numero_fotos:2,
	imagen_activa:0,
	imagenes:new Array(),
	textos:new Array(),
	enlaces:new Array(),
	array_img:new Array(),
	config:{
		duracion:'normal',
		transicion:'sine:in:out',
		alfa:0.3,
		espera:8
	},

	initialize: function(objeto,opciones){
	  var padre=this;
	
	  padre.config=$merge(padre.config,opciones);
	
		objeto.each(function(dato,indice){
			padre.imagenes[indice]=dato.imagen;
			padre.textos[indice]=dato.texto;
			padre.enlaces[indice]=dato.enlace;
		});
		this.array_img = new Asset.images(this.imagenes, {
   		 	onComplete: function(){
   		 			padre.inicio();
   		 			if(padre.imagenes.length>padre.numero_fotos)
   		 			{
						padre.inicio.periodical(padre.config.espera*1000,padre);	
   		 			}			 	
			}
		});
	},
	inicio: function(){
		
		var padre=this;
			
		$$('.marcos').set('morph',{
		  duration: padre.config.duracion,
		  transition: padre.config.transicion
		 });
	 
		myChain=new Chain;

		myChain.chain(
			function(){
				$$('.marcos').morph({'opacity':0});
				myChain.callChain.delay(1000,myChain);	
			},
			function(){
				padre.aparicion();
				myChain.callChain();
			}
			,
			function(){
				$$('.marcos').morph({'opacity':1});
			}
		);
	 	myChain.callChain();
	},
	aparicion:function(){
		var padre=this;
	 	(padre.numero_fotos).times(function(indice){
	 		var indice_fotos=(padre.imagen_activa+indice)%padre.array_img.length;
	 		var dato=padre.array_img[indice_fotos];
	 		$('marco'+indice).setStyle('background-image','url('+dato.src+')')	;
			$$('#marco'+indice+' .textos').set('html',padre.textos[indice_fotos]);
			$('marco'+indice).set('href',padre.enlaces[indice_fotos]);
			//ahora toca ponerle el texto
			});
			//incrementamos el numero de fotos
			padre.imagen_activa=(padre.imagen_activa+padre.numero_fotos)%padre.array_img.length;
	}	
});
