TabRotator = function(configObj) {
//	Dynamic, state-oriented properties
	this.currentTab = null;
	this.status = null;	// 0 = stopped; 1 = running; -1 = paused

//	Initialization configurable properties (example below)
/*	configObj = {
		items = jQuery([list-item selector])
	,	delay = 3000
	,	activeClass = "active"
	}
*/
	if(typeof(configObj) != "object") var configObj = {};
	if(!configObj.hasOwnProperty("stopSelector")) {
		this.stopSelector = null;
	} else {
		this.stopSelector = configObj.stopSelector;
	}
	if(!configObj.hasOwnProperty("pauseSelector")) {
		this.pauseSelector = null;
	} else {
		this.pauseSelector = configObj.pauseSelector;
	}
	if(!configObj.hasOwnProperty("tabs")) {
		this.tabs = 0;
	} else {
		this.tabs = configObj.tabs;
	}
	if(!configObj.hasOwnProperty("delay")) {
		this.delay = 0;
	} else {
		this.delay = configObj.delay;
	}
	this.tabCount = this.tabs.length - 1 || 0;
	this.interval = null;
};

//	UI methods
TabRotator.prototype.start = function() {
	var THIS = this;
	this.setCurrent(0);
	this.interval = setInterval(function(){THIS.next.apply(THIS);},this.delay);
	jQuery(THIS.stopSelector).bind("click",function() {
		THIS.stop();
	});
	this.setStatus(1);
};

TabRotator.prototype.stop = function() {
	if(this.getStatus() != 1) {
		return;
	}
	clearInterval(this.interval);
	this.setStatus(0);
};

//	Utility methods
TabRotator.prototype.getCurrent = function() {
	return this.currentTab;
};

TabRotator.prototype.setCurrent = function(tabIndex) {
	this.currentTab = tabIndex;
};

TabRotator.prototype.getNext = function() {
	if(this.getCurrent() == this.tabCount) {
		return 0;
	} else {
		return this.getCurrent() + 1;
	}
};

TabRotator.prototype.getStatus = function() {
	return this.status;
}

TabRotator.prototype.setStatus = function(status) {
	this.status = status;
}

TabRotator.prototype.next = function() {
	if(this.getStatus() != 1) {
		return;
	}
	var next = this.getNext();
	var nextTab = this.tabs[next];
	this.setCurrent(next);
	jQuery(nextTab).trigger("rotatorClick", nextTab);
};



