/* (c) Copyright Apdsoftware
 * 	All rights reserverd.
 */
var fxSlideShow = new Class({
	initialize: function(SlidePanel,ImageList,Delay){
		this.fxPanel = document.id(SlidePanel);
		this.fxDelay = Delay;
		this.fxImages = ImageList;
		this.fxIndex = 0;
		this.fxMin = 0;
		this.fxMax = this.fxImages.length;
		this.fxTimer = null;
		
		this.fxStatus = new Element('div', {
			'styles': {
				'position': 'absolute',
				'top': this.fxPanel.getSize().y - 8,
				'left': '0px',
				'width': '0px',					
				'height': '8px',
				'background-color': '#aaa'
			}					
		});
		this.fxStatus.inject(this.fxPanel);
		
		var fxLoader = new Asset.images(this.fxImages, {
			onProgress: function(counter, index){
				this.fxStatus.tween('width', (this.fxPanel.getSize().x / this.fxMax) * (counter + 1));
			}.bind(this),
			onComplete: function(){
				(function(){
						this.fxStatus.fade('out');
						this.show();
					}.bind(this)
				).delay(1000);
			}.bind(this)
		});
	},
	show: function(){
		this.fxPanel.get('tween').start('opacity',0).chain(
			function(){
				this.fxPanel.setStyle('background-image', 'url(\''+this.fxImages[this.fxIndex]+'\')');
				this.fxPanel.fade('in');
			}.bind(this),
			function(){
				this.nextImage();
				var interLoader = new Asset.images(this.fxImages[this.fxIndex],{
					onComplete: function(){
						this.fxTimer = (function(){this.show()}.bind(this)).delay(this.fxDelay);
					}.bind(this)
				});
			}.bind(this)
		);
	},
	nextImage: function() {
		this.fxIndex = this.fxIndex + 1;
		if (this.fxIndex >= this.fxMax) {
			this.fxIndex = this.fxMin;
		}
	}				
});

