var Swapper = Class.create({
	initialize: function(elements, images, options) {
		this.elements = elements;
		this.images = images
		this.options = options;
		this.stop = false;
		
		if(this.options.delay == undefined) this.options.delay = 5;
		if(this.options.duration == undefined) this.options.duration = 1.0;
		
		$(this.elements[0]).setStyle("background: url('"+this.getNextImage()+"')");
		this.swap();
	},
	
	getNextImage: function() {
		var nextimg = this.images.shift();
		this.images.push(nextimg);
		return nextimg;
	},
	
	swap: function() {
		$(this.elements[0]).setStyle("z-index: 10");
		$(this.elements[1]).setStyle("z-index: 9");
		$(this.elements[1]).setStyle("background: url('"+this.getNextImage()+"')");
		$(this.elements[1]).show();
		if(!this.stop) {
			var loc = this;
			Effect.Fade(this.elements[0], {afterFinish: function(e)	{
												loc.swap()
															},
									delay: this.options.delay,
									duration: this.options.duration
									});
		}
		this.elements.reverse();
		return this;
	},
	
	pause: function() {
		this.stop = true;
	},
	start: function() {
		this.stop = false;
		this.swap();
	}
	
});