var fader = Class.create({
	
	initialize: function(a) {
		this.imgclass = a.className;
		this.imgs = new Array();
		this.totalImgs = 0;
		this.getAllImgs();
		this.prevCounter;
		this.imgCounter = 1;
		this.imgTimer = a.delay;
		this.setTimer();
		
		if(a.loopNum != '' ) {
			this.loopNum = a.loopNum;
		}
		
	},
	
	getAllImgs: function() {
		var allDivs = $$('#fader div.'+this.imgclass)
		var numDivs = allDivs.length;

		var counter = 0;
		for(i=0; i<numDivs; i++) {
			if($(allDivs[i]).hasClassName(this.imgclass))
				{
					counter++;
					this.totalImgs++;
					this.imgs[counter] = $(allDivs[i]);
					$(this.imgs[counter]).setStyle({
						display: 'none'
					});
				}
		}
		
	},
	
	setTimer: function() {
		this.showImage();
		new PeriodicalExecuter(this.runApp.bind(this), this.imgTimer);
	},
	
	runApp: function(e) {
		this.prevCounter = this.imgCounter;
		if(this.imgCounter == this.totalImgs) {
			this.imgCounter = 1;
		} else {
			this.imgCounter++;
		}
		
		this.showImage();
		this.fadeImage();
		
	},
	
	showImage: function() {
	
		new Effect.Appear($(this.imgs[this.imgCounter]), {
			duration: 1.0
		});
	},
	
	fadeImage: function() {
		
		new Effect.Fade($(this.imgs[this.prevCounter]), {
			duration: 1.0
		});
	}
	
	
});

if($('fader')) {

		var myFader = new fader({
			className: 'myImgBox',
			delay: 5
		});
	}