function FeatureWriter() {}

FeatureWriter.features = [];
FeatureWriter.currentFeature = 0;
FeatureWriter.maxFeatures = 0;
FeatureWriter.changeInterval = 8000;
FeatureWriter.timer = null;

/*
 * Show the first feature and start the timer.
 * Parameters:
 * 		stopCycle
 * 			Specify 'true' to not cycle through the features.
 */
FeatureWriter.init = function( stopCycle )
{
	var featureArea = dojo.byId( "featureArea" ),
		features = dojo.query( "div", featureArea );
	
	/*
	 * Find the features. One will be in the featureSwap area and the rest are
	 * in the hiddenFeatures area.
	 */
	dojo.forEach( features, function( feature ){
		if( feature.id && "feature-" == feature.id.substr( 0, 8 ) ) {
			FeatureWriter.features.push( feature );
		}
	});
	
	/*
	 * Now remove the hidden features from the DOM. We have them safely tucked
	 * in the features array.
	 */
	var hiddenFeatures = dojo.byId( "hiddenFeatures" );
	hiddenFeatures.parentNode.removeChild( hiddenFeatures );
	
	FeatureWriter.maxFeatures = FeatureWriter.features.length;
	
	if( !stopCycle )
	{
		FeatureWriter.timer = setInterval( function() {
			FeatureWriter.changeFeature();
		}, FeatureWriter.changeInterval );
	}
}

/*
 * Change the feature.
 */
FeatureWriter.changeFeature = function()
{
	var newFeatureNdx = ( FeatureWriter.currentFeature + 1 ) % FeatureWriter.maxFeatures,
		newFeature = FeatureWriter.features[newFeatureNdx],
		featureSwap = dojo.byId( "featureSwap" ),
		curFeature = FeatureWriter.features[FeatureWriter.currentFeature];
	
	fadeOut = dojo.fadeOut( { node:curFeature.id }, 500 );

	fadeOut.onEnd = function()
	{
		featureSwap.removeChild( curFeature );
		featureSwap.appendChild( newFeature );
		dojo.style( newFeature, "opacity", 1 );

		FeatureWriter.currentFeature = newFeatureNdx;
	}

	fadeOut.play();

}

