/** 
	Class which handles setting classes on page elements to 
	simulate different button states.
*/	
function BtnStateManager(){
	this.activeId;
	this.idPrefix = "";
	this.idSuffix = "";
	this.classOff = "takeAction";
	this.classOver = "takeActionOver"
	this.classOn = "takeActionOn";
	this.classDisabled = "takeActionDisabled";
}
/**
	Sets the initial on state
	@param	id		(String) An id of an element on the page. 
*/
BtnStateManager.prototype.init = function(id){
	if (!document.getElementById(this.idPrefix + id + this.idSuffix)) return;
	this.itemOn(id);
	this.activeId = id;
}
/** 
	Sets the names of the classes to be used for the button states.
	@param	obj		(Object) An object with the properties 'off', 'over', 'on', and 'disabled'. Properties 
							should be set to strings which match desired classes for button states
*/
BtnStateManager.prototype.setClassNames = function(obj){
	this.classOff = obj.off;
	this.classOver = obj.over;
	this.classOn = obj.on;
	this.classDisabled = obj.disabled;
}
/**
	Set the name of the prefix which should be concatenated in front of the 'id' string1 before 
	accessing the elemnt using document.getElementById(). The id becomes: prefix + id
	@param	str		(String) Prefix name.
*/
BtnStateManager.prototype.setIdPrefix = function(str){ this.idPrefix = str; }
/**
	Set the name of the suffix which should be concatenated with the 'id' string before 
	accessing the elemnt using document.getElementById(). The id becomes: id + suffix
	@param	str		(String) Suffix name.
*/
BtnStateManager.prototype.setIdSuffix = function(str){ this.idSuffix = str; }
/** 
	Changes the element to the 'over' state
	@param	id		(String) An id of an element on the page
*/	
BtnStateManager.prototype.itemOver = function(id){
	if (id != this.activeId && this.isEnabled(id)) 
		this.setState(this.idPrefix + id + this.idSuffix, "over");
}
/** 
	Changes the element to the 'off' state
	@param	id		(String) An id of an element on the page
*/	
BtnStateManager.prototype.itemOut = function(id){
	if (id != this.activeId && this.isEnabled(id)) 
		this.setState(this.idPrefix + id + this.idSuffix, "off");
}
/** 
	Changes the element to the 'on' state
	@param	id		(String) An id of an element on the page
*/	
BtnStateManager.prototype.itemOn = function(id){
	if (id != this.activeId && this.isEnabled(id)){
		if (this.activeId != null) {
			this.setState(this.idPrefix + this.activeId + this.idSuffix, "off");
		}
		this.setState(this.idPrefix + id + this.idSuffix, "on");
		this.activeId = id;
	}
}
/** 
	Changes the element to the 'disabled' state
	@param	id		(String) An id of an element on the page
*/	
BtnStateManager.prototype.itemDisabled = function(id){
	this.setState(this.idPrefix + id + this.idSuffix, "disabled");
}
/** 
	Changes the element to the 'off' state from a disabled state
	@param	id		(String) An id of an element on the page
*/	
BtnStateManager.prototype.itemEnabled = function(id){
	this.setState(this.idPrefix + id + this.idSuffix, "off");
}
/**
	Tests whether an item has been set to the 'disabled' state
	@param	id		(String) An id of an element on the page
*/
BtnStateManager.prototype.isEnabled = function(id){
	var el = document.getElementById(this.idPrefix + id + this.idSuffix);
	if (el.className != this.classDisabled) return true;
	else return false;
}
/** 
	Changes the class applied to represent a button state
	@param	id		(String) An id of an element on the page
	@param	state	(String) A string indicating the desired state of the button. 
							 Accepts: 'off', 'over', 'on', 'disabled'
*/
BtnStateManager.prototype.setState = function(id, state){
	var el = document.getElementById(id);
	if (!el) return;
	switch (state){
		case "off":
			el.className = this.classOff;
			break;
		case "over":
			el.className = this.classOver;
			break;
		case "on":
			el.className = this.classOn;
			break;
		case "disabled":
			el.className = this.classDisabled;
			break;	
		default:
			break;	
	}
}

