/**************************************************************

	Script		: Image Rotator
	Version		: 1.0
	Authors		: Leonard Martin
	Desc		: Rotates a series of images in turn

**************************************************************/

//start menu class
var Rotator = new Class({

	//implements
	Implements: [Options],
	
	//options
	options:{
		interval: 10000,
		speed: 1000,
		content:[]
	},
	
	current:0,

	//initialization
	initialize: function(parent,options)
	{
		
		//set options
		this.setOptions(options);
		
		this.container = parent;
		
		this.move(true);
		
	},
	
	move: function(snap) {
		
		if(!snap) {
			this.current = (this.current+1)%this.options.content.length;
		}
		
		var show = this.container.getChildren().filter(function(e){return e.match(this.options.content[this.current])}.bind(this)),
			hide = this.container.getChildren().filter(function(e){return !e.match(this.options.content[this.current])}.bind(this));
		
		show.each(function(e){
			$(e).setStyle('zIndex',20);
			var fadeIn = new Fx.Morph($(e),{duration:snap?0:this.options.speed});
			fadeIn.start({
				opacity: 1
			});
		}.bind(this));
			
		hide.each(function(e){
			$(e).setStyle('zIndex',10);
			var fadeOut = new Fx.Morph($(e),{duration:snap?0:this.options.speed});
			fadeOut.start({
				opacity: 0
			});
		}.bind(this));
		
		this.timeout();
		
	},
	
	timeout: function() {
		
		setTimeout(function(){
			this.move();
		}.bind(this),this.options.interval);
		
	}
	
	
});