var FeatureRotator = {
	featureInterval: 7000,
	aryFeatures: [],
	curFeature: 0,
	isCycling: true,
	isAnimating: false,
	
	setupRotate: function() {
		FeatureRotator.aryFeatures = $$("#features .feature");
		if(FeatureRotator.aryFeatures.length) {
			setTimeout("FeatureRotator.rotateFeature();", FeatureRotator.featureInterval);
			$('features').onmouseover = function() {
				$('prev-feature').style.display = "block";
				$('next-feature').style.display = "block";
				// Effect.Appear('prev-feature', { duration: .3 });
			};
			$('features').onmouseout = function() {
				$('prev-feature').style.display = "none";
				$('next-feature').style.display = "none";
				// Effect.Fade('prev-feature', { duration: .3 });
			};
		}
	},
	
	rotateFeature: function(dir, force) {
		if(!dir) {
			dir = 1;
		}
		
		if(!FeatureRotator.isAnimating && (FeatureRotator.isCycling || (!FeatureRotator.isCycling && force))) {
			FeatureRotator.isAnimating = true;
			
			Effect.Fade(FeatureRotator.aryFeatures[FeatureRotator.curFeature], { duration: .5 });
			FeatureRotator.curFeature = (FeatureRotator.curFeature+dir) % FeatureRotator.aryFeatures.length;
			if(FeatureRotator.curFeature < 0) {
				FeatureRotator.curFeature = FeatureRotator.aryFeatures.length - 1;
			}
			Effect.Appear(FeatureRotator.aryFeatures[FeatureRotator.curFeature], { duration: .5, afterFinish: function() { FeatureRotator.isAnimating = false; } });
		}
		
		if(FeatureRotator.isCycling) {
			setTimeout("FeatureRotator.rotateFeature(1);", FeatureRotator.featureInterval);
		}
	},
	
	previousFeature: function() {
		FeatureRotator.isCycling = false;
		FeatureRotator.rotateFeature(-1, true);
	},
	
	nextFeature: function() {
		FeatureRotator.isCycling = false;
		FeatureRotator.rotateFeature(1, true);
	},
}
