




function cSlider (instanceName, maxButtons, autoChangeDelay) {
	this.buttonSelected 	= 1;
	this.buttonHighlighted 	= 0;
	this.maxButtons 		= maxButtons;
	this.instanceName 		= instanceName;
	this.autoChange			= true;
	this.autoChangeID		= 0;
	this.autoChangeDelay	= autoChangeDelay;
	
	
	
	// ********************************************************************************************
	this.buttonHover = function (selected) {
		if (this.buttonHighlighted == selected || selected < 0 || selected > this.maxButtons)  return false;
	
		if (this.buttonHighlighted > 0) $(this.instanceName +'_button_'+ this.buttonHighlighted).removeClassName('Button_Hover');

		if ( this.buttonSelected != selected ) {
			$(this.instanceName +'_button_'+ selected).addClassName('Button_Hover');
		}
		
		this.buttonHighlighted = selected;
	};
	
	
	// ********************************************************************************************
	this.buttonClick = function (selected) {
		this.switchFeature(selected, false);
		
		// Turn off the auto switching 
		this.stopAutoChange()
	};

	
	// ********************************************************************************************
	this.switchFeature = function (selected) {
		var newSelected = this.buttonSelected;
		
		if (isNaN(selected)) { 
			// Check to see if we are incrementing or decrementing
			if (selected == '+') newSelected = this.buttonSelected + 1;
			if (selected == '-') newSelected = this.buttonSelected - 1;
			if (newSelected > maxButtons) newSelected = 1;
			if (newSelected <= 0) newSelected = maxButtons;
		} else {
			if (this.buttonSelected == selected || selected < 0 || selected > this.maxButtons)  return false;
			newSelected = selected	
		}
		
		// Hide the last selected feature if there is one
		if (this.buttonSelected > 0) {
			$(this.instanceName +'_button_'+ this.buttonSelected).removeClassName('Button_On');
			$(this.instanceName +'_feature_'+ this.buttonSelected).hide();
		}
		
		// Show the selected feature
		$(this.instanceName +'_button_'+ newSelected).removeClassName('Button_Hover');
		$(this.instanceName +'_button_'+ newSelected).addClassName('Button_On');
		Effect.Appear(this.instanceName +'_feature_'+ newSelected, {duration: .25});
		
		
		this.buttonSelected = newSelected;
		return true;
	}

	// ********************************************************************************************
	this.startAutoChange = function () {
		if (this.autoChangeDelay > 0) {
			this.autoChange = true;
			this.autoChangeID = setInterval(this.instanceName +'.switchFeature("+")', this.autoChangeDelay);
		}
	}
	// ********************************************************************************************
	this.stopAutoChange = function () {
		clearInterval(this.autoChangeID);
		this.autoChange = false;
		this.autoChangeID = 0;
	}
	


	// ********************************************************************************************
	// ********************************************************************************************
	this.startAutoChange();
}


