
//Rotator
Event.observe(window, 'load', function() {
	activeFeature = 1;
	totalFeatures = 4;
	interval = 3000;
	timer = null;
	startTimer();
	Event.observe('featurette','mouseover', stopTimer);
	Event.observe('featurette','mouseout', startTimer);
});

function switchFeature(nextElementIndex){
	if(nextElementIndex != activeFeature){
		currentElement = 'feature'+activeFeature;
		nextElement = 'feature'+nextElementIndex;
		topPosition = $(currentElement).getStyle('z-index');
		$(nextElement).setStyle('z-index:'+(topPosition-1));
		$(nextElement).show();
		$(currentElement).fade({afterFinish: function(){
			$(nextElement).setStyle('z-index:'+(topPosition));
		} });
		activeFeature = nextElementIndex;
	}
	
	// Uncomment the following line for debugging purposes only.
	// debug();
	
}

function switchNext(){
// 2. Set next feature to active feature
		if(activeFeature<totalFeatures) switchFeature(activeFeature+1);
		else switchFeature(1);
}

function debug(){
		$('debug').update(
		$('feature1').getStyle('z-index') + '<br />' +
		$('feature2').getStyle('z-index') + '<br />' +
		$('feature3').getStyle('z-index') + '<br />' +
		$('feature4').getStyle('z-index')
	);
	
}

function stopTimer(){
	timer=window.clearInterval(timer)
}
function startTimer(){
	timer = setInterval("switchNext()",interval);
}
