/*******************************
Image Rotator
Created By: Greg D'Angelo
Created On: December 22nd 2008
Description:
	- Rotates the Source of a specified <IMG> tag
Parameters
	path     - Path of images
	ext      - Extension of images
	images   - Image names
	duration - duration of each "slide"
*******************************/
var ImageRotator = Class.create();

ImageRotator.prototype = {
	initialize: function(element, options){
			this.element = $(element);
			this.options = {
				 path: '/web_images/'
				,ext: 'png'
				,images:Array()
				,duration:1
			}
			Object.extend( this.options, options || {} );
			this.path = 	this.options.path;
			this.ext = this.options.ext;
			this.duration = this.options.duration;
			this.images = this.options.images;
			this.currentIndex = 0;
		}
	,start: function(){ this.periodicallyUpdate(); }
	,stop: function(){ clearTimeout(this.timer); }
	,periodicallyUpdate: function(){ 
		if (this.timer != null) {
			clearTimeout(this.timer);
			this.updateImage();
		}
		this.timer = setTimeout(this.periodicallyUpdate.bind(this), this.duration*1000);
	}
	,updateImage: function(){
		if(this.currentIndex == this.images.length){
			this.currentIndex = 0;
		}
		this.element.src = this.path + this.images[this.currentIndex] +"."+ this.ext;
		this.currentIndex++;
	}
}