// Rotating banners class
// Copyright 2008 Matthew Vickers mvickers@quispiam.com
// Requires Prototype (http://www.prototypejs.org/) and  
// script.aculo.us (http://script.aculo.us/)
function BannerRotator(time_out,elements) {
	//Basic default values
	this.time_out = time_out || 5000;
	this.elements = elements || []; 
				
	//Internal methods
	this.time_out_function;
	this.rotation_counter = 0;
				
				
}

//Public function to cycle the elements
BannerRotator.prototype.cycle = function() {
	if(this.elements.length > 1) {
		Effect.Fade($(this.elements[this.rotation_counter]),{ duration:1, from:1.0, to:0.0 });
		if (++this.rotation_counter >= this.elements.length) this.rotation_counter = 0;
		Effect.Appear($(this.elements[this.rotation_counter]), { duration:1, from:0.0, to:1.0, queue: "end" });
		me = this;
		this.time_out_function = setTimeout(function() { me.cycle() }, this.time_out);
	}
}
			
//Public function to start banner rotation
BannerRotator.prototype.start = function() {
	me = this;
	this.time_out_function = setTimeout(function() { me.cycle() }, this.time_out);
}
			
//Public function to stop banner rotation.
BannerRotator.prototype.stop = function() {
	clearTimeout(this.time_out_function)
}
