var timerSpeed       = 90;  // how often the timer will run, the lower the number the faster it will run
var timerIncrement   = 1;   // how much the time will go up each time
var timerMax				 = 100; // when timer reaches this it will reset
var timerCurrent		 = 0;   // the value the timer is currently at
var timerFadeAt			 = 100;  // value that the timer will start to fade out at, this must be an exact value
var timerCurrent		 = 0;

var FeaturedImages = Class.create();

FeaturedImages.prototype = {

	initialize: function() {
		this.timer();
	},

	timer: function() {
		timerCurrent += timerIncrement;
		if(timerCurrent == timerFadeAt) {
			this.hideCurrentImage();
		}
		if(timerCurrent >= timerMax) {
			this.next();
			timerCurrent = 0;
		} 
		
		setTimeout('myFeaturedImages.timer()', timerSpeed);
	},

	next: function() {
		this.advanceCurrentImageId();
		this.showCurrentImage();
	},

	advanceCurrentImageId: function() {
		currentImageId = currentImageId + 1;
	  if (currentImageId == totalImages) currentImageId = 0;
	},

	hideCurrentImage: function() {
		Effect.Fade($('feature_'+currentImageId), {duration:2.5});
	},

	showCurrentImage: function() {
		Effect.Appear($('feature_'+currentImageId), {duration:2.5});
	}
};

function initFeaturedImages() { myFeaturedImages = new FeaturedImages(); }
Event.observe(window, 'load', initFeaturedImages, false);
