//<![CDATA[
Crossfader = Class.create({
	initialize: function(ids, int){
		this.image_ids = ids
		this.interval = (int || 7)*1000
		this.index = 0
	},
	
	current_id: function() {
		return this.image_ids[this.index]
	},
	
	next_id: function() {
		return this.image_ids[this.next_index()]
	},
	
	next_index: function() {
		if(this.index + 1 == this.image_ids.size()){ 
			return 0 
		} else {
			return this.index + 1
		}
	},
	
	increment_index: function() {
		this.index = this.next_index()
	},
	
	crossfade: function(fadeout_id, fadein_id, options) {
		new Effect.Fade(fadeout_id, options)
		new Effect.Appear(fadein_id, options)
	},
	
	chain_crossfade: function() {
		this.crossfade(this.current_id(), this.next_id())
		this.increment_index()
		setTimeout(this.chain_crossfade.bind(this), this.interval)
	},
	
	start: function(delay) {
		delay = delay*1000 || this.interval
		setTimeout(this.chain_crossfade.bind(this), delay)
	}
	
})
//]]>