/*
*	Rotator Transitions Manager, version 0.1
*	(c) 2008 DELINEAVIT Consulting & Web
*
*	Authors:	Michele D'Errico
*				Angela Iacovella	
*/


/* The Transition1 Class */
var Transition1 = Class.create();
Transition1.prototype = {
		initialize: function( p_eTarget, p_sImage, p_sAltezza, p_sLarghezza ) {
		this.m_eTarget = $( p_eTarget );
		this.m_eTarget.setStyle( { position: 'relative', overflow:'hidden'} );
		this.m_eLoading = null;

		/* Define the refence to this object globally so we can use it within the scope of the anchors */
		g_eTransition1 = this;		
	
				var eImage = document.createElement( 'img' );
				eImage.setAttribute( 'src', p_sImage );	
				var imgSx = '0';
				var imgSu = '0';
				$(eImage).setStyle( { position: 'absolute', left: imgSx, top: imgSu, opacity: '0' } );
				this.m_eTarget.appendChild( eImage );		
				new Effect.Appear( eImage, { duration: 1.5, from: 0.0, to: 1.0  } );
		/*******************************************************************************************/

	},

	loadImage: function( p_eAnchor ) {
		
		// Get Transition1 type and image url.
		var sTransition1 = /^Transition1\[(.+)\]$/.exec( p_eAnchor.getAttribute( 'rel' ) )[ 1 ];
		var sImage = p_eAnchor.getAttribute( 'href' );
		var sLarghezza = p_eAnchor.getAttribute( 'width' );
		var sAltezza = p_eAnchor.getAttribute( 'height' );
		var imgSx = '0px';
		var imgSu = '0px';
		var eImage = document.createElement( 'img' );
		eImage.setAttribute( 'src', sImage );	
		$(eImage).setStyle( { position: 'absolute', left: imgSx, top: imgSu, opacity: '0' } );
		this.m_eTarget.appendChild( eImage );
		if(!eImage.isLoaded()) {
			/* The image is not yet loaded, so fix the loading div */
			this.m_eLoading = document.createElement( 'div' );
			$( this.m_eLoading ).setStyle( { position: 'absolute', left: '0px',  bottom: '0px', color: '#566C80' } );
			this.m_eLoading.appendChild( document.createTextNode( 'LOADING...' ) );
			this.m_eTarget.appendChild( this.m_eLoading );
			Event.observe( eImage, 'load', this._onLoad.bindAsEventListener( null, this, eImage, sTransition1 ) );
		} else {
			/* The image is already loaded*/
			this.m_eLoading = null;
			this._transImage(eImage, sTransition1);
		}
	},
	
	_onLoad: function( p_eEvent, p_oRef, p_eImage, p_sTransition1 ) {
		p_oRef._transImage( p_eImage, p_sTransition1 );
	},

	_transImage : function() {
	},

	_removeImage: function( p_oObj ) {
		p_oObj.element.remove();
	}
}

function dvtbanner1(obiettivo,banner1Img,url,testo,idImg){
	elencoImmagini = new Array();
	elencoImmagini=banner1Img.split(",");
	var numeroImmagini = elencoImmagini.length;
	if(numeroImmagini > 1){
		var immagineScelta = Math.floor(Math.random() * numeroImmagini);
		while(immagineScelta == idImg){immagineScelta = Math.floor(Math.random() * numeroImmagini);}
	} else {
		immagineScelta = 0;
	}
	oTransition1 = new Transition1( obiettivo, elencoImmagini[immagineScelta],'','');
	if(numeroImmagini > 1){
		idImg = immagineScelta;
		var richiama = "dvtbanner1('"+obiettivo+"','"+banner1Img+"','"+url+"','"+testo+"','"+idImg+"')";
		setTimeout(richiama,5000);	
	}
}

