function Rotator()
{
	var me = this;
	var timer = null;
	var idx = 0;
	var rotating = false;

	this.items = [];
	this.interval = 1000;
	this.selectedIndex = -1;
	this.selectedItem = null;

	this.move = function(value)
	{
		if (typeof (value) != "number")
			value = idx;
		else if (value < 0 || !(value < this.items.length))
			return (false);
		clearInterval(timer);
		this.selectedIndex = idx = value;
		this.selectedItem = this.items[idx];
		if (rotating)
			timer = setInterval(next, this.interval);
		return (true);
	}

	this.start = function(value)
	{
		if (typeof (value) != "number")
			value = idx;
		else if (value < 0 || !(value < this.items.length))
			return (false);
		clearInterval(timer);
		rotating = true;
		return (this.move(value));
	}

	this.stop = function()
	{
		clearInterval(timer);
		rotating = false;
		return (true);
	}

	function next()
	{
		if (!handler("onbeforechange"))
			return (false);
		me.move((idx + 1) % me.items.length);
		return (handler("onchange"));
	}

	function handler(name)
	{
		return (typeof (me[name]) != "function" || me[name]() != false);
	}
}
