// AdFader
// (c) 2008 Andrew Buckman / http://stormyfrog.com/mootools/
// -----------------------------------------------------------------
// For simple two-level fades between images of the same size
// Requirements:
//   Parent element with display:block and appropriate height/width set
//   Second image is the URL of the image to fade to, the first image should be specified in HTML/CSS
//   If inner element to fade in/out is not an IMG, specify innerElement in your options

var sfAdFader = new Class({
	adfx: Class.empty,
	counter: 0,
	options: {
		fadeDelay: 3000,
		fadeTime: 900,
		innerElement: 'img',
		limit: -1 // unlimited
	},
	initialize: function(element, secondImage, options) {
		this.setOptions(options);
		if ($chk($(element))) {
			$(element).setStyles({
				backgroundImage: "url('" + secondImage + "')",
				backgroundRepeat: 'no-repeat',
				backgroundPosition: 'left top'
			});
			this.adfx = $E(this.options.innerElement, element).effect('opacity', { 
				duration: this.options.fadeTime, 
				onComplete: function() {
					this.counter++;
					if (this.options.limit==-1 || this.counter < this.options.limit) this.fader.delay(this.options.fadeDelay, this);
				}.bind(this)
			}).set(1);
		}
		this.fader.delay(this.options.fadeDelay, this);
	},
	fader: function() {
		this.adfx.stop();
		if (this.adfx.now>0) this.adfx.start(0);
		else this.adfx.start(1);
	}
});
sfAdFader.implement(new Events, new Options);