var HomeShow = {
	currentFeature: 1,
	featureCount: 1,
	slideshowTimer: 4000,
	slideshow: null,

	init: function() {
		// hide all features that aren't the first
		var featureList = $('featureList');
		if(featureList)
		{
			// set the initial feature count
			this.featureCount = featureList.immediateDescendants().length;
			// set a good class name
			featureList.immediateDescendants().each(function(s) {
				if(!s.hasClassName('1'))
				{
					s.hide();
				}
			});

			HomeShow.slideshow = setInterval("HomeShow.nextFeature()", HomeShow.slideshowTimer);
		}
	},

	nextFeature: function(event) {
		if(event != null)
		{
			Event.stop(event);
			clearInterval(this.slideshow);
			this.slideshow = setInterval("HomeShow.nextFeature()", this.slideshowTimer);
		}

		var featureToShow = (this.currentFeature == this.featureCount) ? 1 : this.currentFeature + 1;
		this.showFeature(null, featureToShow);
	},

	showFeature: function(event, featureNumber) {
		if(event != null)
		{
			Event.stop(event);
			clearInterval(this.slideshow);
			this.slideshow = setInterval("HomeShow.nextFeature()", this.slideshowTimer);
		}

		if((featureNumber >= 1) && (featureNumber <= this.featureCount))
		{
			var featureList = $('featureList');

			var toHide = null; var toShow = null;
			featureList.immediateDescendants().each(function(s, i) {
				if(s.hasClassName(HomeShow.currentFeature))
				{
					toHide = s;
				}
				else if(s.hasClassName(featureNumber))
				{
					toShow = s;
				}
			});

			if((toHide != null) && (toShow != null))
			{
				Effect.Fade(toHide, {
					duration: 1.2,
					beforeStart: function() { Effect.Appear(toShow, { duration: 1.2 }); }
				});
			}

			this.currentFeature = featureNumber;
		}
	}
};
