/*******************************
Content Rotator
Created By: Greg D'Angelo
Created On: December 30th 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 ContentRotator = Class.create();

ContentRotator.prototype = {
	initialize: function(element, options){
			this.element = $(element);
			this.options = {
				duration:1
			}
			Object.extend( this.options, options || {} );
			this.duration = this.options.duration;
			this.currentIndex = 0;
			this.sections = this.element.childElements();
		}
	,start: function(){ this.periodicallyUpdate(); }
	,stop: function(){ clearTimeout(this.timer); }
	,periodicallyUpdate: function(){ 
		if (this.timer != null) {
			clearTimeout(this.timer);
			this.updateContent();
		}
		this.timer = setTimeout(this.periodicallyUpdate.bind(this), this.duration*1000);
	}
	,updateContent: function(){
		if(this.currentIndex == this.sections.length){
			this.currentIndex = 0;
		}
		//this.element.src = this.path + this.images[this.currentIndex] +"."+ this.ext;
		this.sections.each(function(element/*,index*/){
			//if(index != this.currentIndex){
				element.hide();
			/*}else{
				element.show();
			}*/
		});
		this.sections[this.currentIndex].show();
		this.currentIndex++;
	}
	,showhide: function(element,index){
		if(index != this.currentIndex){
			element.hide();
		}else{
			element.show();
		}
	}
}