var diaShow = Class.create( {
	
	pointer : 0,
	images : [],
	con : null,
	delay : 5,
	wait : 5,
	active : [],
	replace : null,
	
	initialize : function (con, options) {
		this.con = con;
		if(options['delay']) this.delay = options['delay'];
		if(options['wait']) this.wait = options['wait'];
		if(options['replace']) this.replace = options['replace'];
		/*Element.setStyle(Element.childElements(this.con).first(), {
			'display' : 'block',
			'position' : 'absolute'
		});*/
		while(Element.childElements(this.con).length > 0) {
			img = Element.childElements(this.con).last();
			Element.setStyle(img, {
				'display' : 'block',
				'position' : 'absolute'
			});;
			img.style.display = 'block';
			this.con.removeChild(img);
			this.images.unshift(img);
		};
		this.con.appendChild(this.images.shift());
		
		/*this.addImage();
		Element.setOpacity(this.active[0], 1);
		this.addImage();
		this.addImage();*/
	},
	
	start : function () {
		/*new Effect.Fade(this.active[1], {
			from: 0.0,
			to: 1.0,
			duration: this.delay,
			fps: 25,
			afterFinish: function() { 
				this.changePic.bind(this);
			}.bind(this)
		});*/
		this.fade();
	},
	
	fade : function() {
		img = this.images.shift();
		Element.setOpacity(img, 0);		
		this.con.appendChild(img);
		Element.clonePosition(img, Element.childElements(Element.childElements(this.con).first()).first());
		new Effect.Appear(img, {
			duration: this.delay,
			fps: 25,
			afterFinish: function() {			
				var old = Element.childElements(this.con).first();
				this.con.removeChild(old);
				this.images.push(old);
				window.setTimeout(this.fade.bind(this), this.wait*1000);
			}.bind(this)
		});
	},
	
	changePic : function () {
		this.active[0].parentNode.removeChild(this.active[0]);
		this.active.shift();
		this.addImage();
		this.process = window.setTimeout(this.start.bind(this), this.wait*1000);
	},
	
	stop : function () {
		clearInterval(this.process);		
	},
	
	addImage : function () {
		img = this.getNextImage();
		Element.setOpacity(img, 0);
		img = this.con.appendChild (img);
		img.style.position = 'absolute';
		Element.clonePosition(this.con, img);
		this.active.push(img);
	},
	
	getNextImage : function () {
		var img = this.images[this.pointer];
		this.pointer++;
		if (this.pointer == this.images.length) this.pointer = 0;
		return img;
	}
	
} );
