// Fader by xrado (Radovan Lozej) 2008, http://xrado.hopto.org

var mooFader = new Class({

	options:{
		duration: 4000,
		fade: 1000
	},

	initialize: function(el,path,im,url,options) {
		this.setOptions(options);
		this.holder = $(el);
		if(!this.holder) return;
		this.starter = this.holder.getElement('img');
		this.starter.setStyle('position','absolute');
		this.path = path;
		this.im = im;
		this.url = url;
		this.faders = [];
		this.images = im.length;
		this.counter = 0;
		this.change.periodical(this.options.duration,this);
		new Asset.image(this.im[this.counter]);
	},

	change: function(){
		if(this.counter > this.images-1) this.counter = 0;
		var self = this;
		var imgsrc = this.im[this.counter];
		var imgurl = this.url[this.counter];
		var img = new Element('img',{
			'src'	: imgsrc,
			'styles': { 'position':'absolute' },
			'class': 'hand',
			'events': {
				'click' : function(){ location.href= imgurl }
			}
		}).injectTop(this.holder);
		var fader = img.getNext();
		new Fx.Style(fader,'opacity',{ duration:this.options.fade, onComplete: function(el){ fader.remove(); } }).start('1', '0');
		this.counter++;
		new Asset.image(this.im[this.counter]);
	}
});

mooFader.implement(new Options, new Events);

