// AdFader v1.2 for MooTools 1.2
// (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({
	Implements: [Events,Options],
	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: 'center top'
			});
			this.adfx = new Fx.Tween($(element).getElement(this.options.innerElement), { 
				property: 'opacity',
				link: 'cancel',
				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(0);
		}
		this.fader.delay(this.options.fadeDelay, this);
	},
	fader: function() {
		this.adfx.start( (this.adfx.subject.get('opacity')>0) ? 0 : 1 );
	}
});