// -----------------------------------------------------------------------------------
//
// Galeria de Imagenes Real Valladolid
// Realizacion: digival.es
// joseignacio.marcos@digival.es
//
// -----------------------------------------------------------------------------------
var galeriaEstadio = new Class({

	initialize: function(enlaces) {
		this.enlaces	= enlaces;
		this.fotoId 	= 'fotoEstadio';
		this.cajaFoto 	= 'fotoSup';
		this.actual 	= 0;
	},
	
	start: function(){
		this.enlaces.each(function(enlace, i){
			enlace.addEvent('click', function(e) {
				e = new Event(e).stop();
				if(this.actual!=i) this.cambiaFoto();
				this.actual = i;	
			}.bind(this));
		}.bind(this));
	},
	
	insertaImg: function(){
		var imgNew = new Asset.image(this.enlaces[this.actual], {id: this.fotoId, alt:"Estadio", onload: function(){this.cambiaOpacidad();}.bind(this) });
		$(this.cajaFoto).adopt(imgNew);
	},

	cambiaOpacidad: function(){
		if($(this.fotoId).getStyle('height').toInt()!=$(this.cajaFoto).getStyle('height').toInt()){
			$(this.cajaFoto).effect('height', {duration: 500, onComplete: function(){$(this.cajaFoto).effect('opacity', {duration: 500}).start(0,1);}.bind(this) }).start($(this.fotoId).getStyle('height').toInt());
		}else{
			$(this.cajaFoto).effect('opacity', {duration: 500}).start(0,1);
		}
	},
	
	cambiaFoto: function(){
		$(this.cajaFoto).effect('opacity', {duration: 500, onComplete: function(){ 
				$(this.cajaFoto).setStyle('height', $(this.cajaFoto).getStyle('height'));
				$(this.cajaFoto).setStyle('overflow', 'hidden');
				$(this.fotoId).remove(); 
				this.insertaImg(); 
		}.bind(this) }).start(1,0);
	}
		
});

function InitGaleria(){
	var galeriaFotos = new galeriaEstadio($$('.miniEstadio a')).start();
}

/* -----------------------------------------------------------------------------
LOAD ---------------------------------------------------------------------------
----------------------------------------------------------------------------- */ 
window.addEvent('domready', InitGaleria);