
/*
----------------
- EFFETTI FOTO -
----------------
*/

var fotoSlide=new Class({
	initialize:function(array_foto,dove,durata,debug){
		this.array_foto=array_foto;
		this.dove=dove;
		this.durata = durata*1000;
		this.fotos=new Array();
		for(i=0;i<array_foto.length;i++){
			this.fotos.push(false);
		}
		this.over=$('over_'+dove);
		this.under=$('under_'+dove);
		this.visible=0;
		this.over.fade=new Fx.Morph(this.over,{duration: 1000,transition: Fx.Transitions.Cubic.easeOut,onComplete:(
			function(){
				this.rollImages();
			}).bind(this)});
		this.under.fade=new Fx.Morph(this.under,{duration: 800,transition: Fx.Transitions.Cubic.easeOut});
		this.next_image;
		this.debug = debug;


		// inizializzazione
		this.fotos[this.visible]=this.array_foto[0]; //HR_PATH+'img/'+this.nome_foto+this.visible+'.jpg';
		this.defineNextImage();
		this.loadNextImage();

		//(function(){(function(){this.start()}).periodical(durata,this)}).delay(delay,this);
		(function(){this.start()}).periodical(this.durata,this);
	},
	defineNextImage:function(){
		if(this.debug) alert(this.visible);
		this.visible = (this.visible < (this.fotos.length-1)) ? (this.visible+1) : 0 ;
		if(this.debug) alert(this.visible);
		return this.visible;
	},
	loadNSetImg:function(num){
		return this.next_image=new Asset.image(this.array_foto[num],{
			onload:(
				function(){
					this.fotos[this.visible]=this.array_foto[num];
					this.putNextImage();
				}
			).bind(this)
		});
	},
	fadeOver:function(){
		this.over.fade.start({'opacity': '0'});
	},
	appearUnder:function(){
		this.under.fade.start({'opacity': '1'});
	},
	rollImages:function(){
		this.over.style.zIndex='0';
		this.under.style.zIndex='1';
		this.under.injectBefore(this.over);

		this.over.setProperty('id','under_'+this.dove);
		this.under.setProperty('id','over_'+this.dove);

		this.over=$('over_'+this.dove);
		this.under=$('under_'+this.dove);

		this.defineNextImage();
		this.loadNextImage();
	},
	putNextImage:function(){
		this.under.setProperty('src', this.next_image.getProperty('src'));
	},
	start:function(){
		this.appearUnder();
		this.fadeOver();
	},
	loadNextImage:function(){
		//this.defineNextImage();
		if(!this.fotos[this.visible]){
			this.loadNSetImg(this.visible);
		} else {
			this.next_image.setProperty('src',this.fotos[this.visible]);
			this.putNextImage();
		}
	},
	toString:function(){
		return '[object fotoSlide]';
	}

});


