/**
 * @author Gorfdo
 */
var imageFader = new Class({
		Implements: Options,
		options : {
			pause:7000,
			element:'.toppp',
			myimages:new Array
		},
		initialize: function(options){
			this.setOptions(options);
			this.fxbox = new Array;
			this.boxarray = new Array;
			this.photoarray = new Array;
			this.pactive = 0;
			this.newbox = '';
			var imageList = new Asset.images(this.options.myimages,{
				onProgress: function(counter,index){
					if(counter > 1)
					{
						$('pimage-'+counter).setProperty('src',this.options.myimages[counter]);
					
					}
				}.bind(this)
			});



			this.addPhotos();
			this.start();				
		},
		addPhotos: function(){
			$$(this.options.element).each(function(item){
				var boxid = item.id.split("-");
				this.boxarray.push(boxid[1]);
				this.fxbox[item.id] = new Fx.Morph(item.id,{duration:2000,link:'chain'});
			}.bind(this))
		},
		start: function(box){
			this.periodical = this.show.bind(this).periodical(this.options.pause);			
		},
		stop: function(){
			$clear(this.periodical);				
		},
		clickshow: function(clickbox){
			var box = clickbox.split("-")	
			this.stop();
			this.show(box[1]);
			this.start();
		},
		show: function(box){
			if(typeof box == 'undefined'){			
				this.newbox = this.pactive*1 + 1;
				if(this.newbox == this.boxarray.length) this.newbox = 0;	
			}
			if(typeof this.fxbox["p-"+this.boxarray[this.pactive]] != 'undefined')	this.fxbox['p-'+this.boxarray[this.pactive]].cancel();
			this.fxbox["p-"+this.boxarray[this.pactive]].start({
				opacity:[1,0]
				}).start({
					'display':'none'
					})
			this.fxbox['p-'+this.boxarray[this.newbox]].set({
						"opacity":0,"display":"block"
						}).start({
							opacity:[0,1]
						})
			this.pactive = this.newbox
			$$('.ppick.active').removeClass('active');
			//$('s-'+box).addClass('active');	

		
		}
	})
		