/**
 * @author Kevin Thompson
 * @constructor imageSlider
 * @classDescription Takes several images and slides them into an area.
 * @copyright 2007
 * @version 2007-03-27
 */

var imageSlider = Class.create();
imageSlider.prototype = {
	initialize: function(elements,options){
		this.elements = $(elements);
		this.options = {startPos: {x:0,y:0},moveBy: {x:100,y:100},wait: 3000};
		
		Object.extend(this.options, options || {});
			
		this.activeElementIndex = -1;
		this.resetElements();	
		this.start();						
	},
	resetElements: function(){
		//called after the previous effect is complete
		for(var i=0;i<this.elements.length;i++){
			if(i!=this.activeElementIndex){
				this.elements[i].setStyle({top: this.options.startPos.y, left: this.options.startPos.x, zIndex:0});						
			}else{
				this.elements[i].setStyle({zIndex:0});
			}										
			
		}
	},
	start: function(){
		var el = this.getNextElement();
		el.setStyle({zIndex:1});
		new Effect.Move(el,{x: this.options.moveBy.x, y: this.options.moveBy.y, afterFinish:  this.afterMove.bind(this)})				
	},
	getNextElement: function(){
		this.activeElementIndex++;
		if(this.activeElementIndex == this.elements.length){
			this.activeElementIndex = 0;
		}				
		return this.element();
	},
	afterMove: function(effect){
		this.resetElements()
		setTimeout(this.start.bind(this),this.options.wait);								
	},
	element: function(){
		return this.elements[this.activeElementIndex];
	}			
};
