
var simpleRotator = new Class({

	Implements: [Events, Options],
	
	options: {
		container  : null,  // The container to rotate
		timer      : 5,     // How long between slides in seconds
		display    : 1,     // The number of elements to display
		serachFor  : 'p', // The element to search for (div, p)
		transition : 'slide_up' // Transition type (fade, slide_up, slide_left, slide_right, slide_down)
	},
	
	current  : 0,    // The current start element
	elements : [],   // All of the elements
	tweens   : [],   // Tweens for all the elements
	count    : null, // How many elements there are to rotate through
	
	initialize: function(options) {
		this.setOptions(options);
		
		// Get the elements to rotate
		this.getElements();
		
		// Get all the elements ready
		this.setElements();
		
		// Now start the rotator
		this.rotateElements();
	},
	
	getElements: function() {
		this.elements = this.options.container.getChildren(this.options.serachFor);
	},
	
	setElements: function() {
		for (var i=0; i<this.elements.length; i++) {
			// Setup a tween for each elements
			this.tweens[i] = new Fx.Tween(this.elements[i], { duration: this.options.timer*1000});
			this.elements[i].setStyle('height', this.elements[i].getStyle('height'));
		}
	},
	
	rotateElements: function() {
		var height = (this.elements[this.current].getStyle('height').toInt()+this.elements[this.current].getStyle('margin-bottom').toInt())*-1;
		var margin_top = this.elements[this.current].getStyle('margin-top').toInt();
		this.tweens[this.current].start('margin-top', margin_top, height).chain(function() {
			this.elements[this.current].dispose();
			this.elements[this.current].inject(this.options.container);
			this.elements[this.current].setStyle('margin-top');
			this.current++;
			if (this.current == this.elements.length) {
				this.current = 0;
			}
			this.rotateElements();
		}.bind(this));
	}
});

