function FRotator(dlname, interval) {
	var feat = $(dlname);

	this.dts = feat.getElementsByTagName('dt');
	this.dds = feat.getElementsByTagName('dd');

	this.interval = interval ? interval : 4000;

	for (var i = 0; i < this.dts.length; i++) {
		this.dts[i]._thisnum = i;
		this.dts[i]._rotator = this;
		this.dds[i]._rotator = this;

		if (i > 0) Element.hide(this.dds[i]);
		this.dds[i].className = 'current';

		this.dts[i].onmouseover = function() {
			this._rotator.switchTo(this._thisnum);
			this._rotator.setRotation(false);
		}
		this.dts[i].onmouseout = function() {
			this._rotator.setRotation(true);
		}
		this.dds[i].onmouseover = function() {
			this._rotator.setRotation(false);
		}
		this.dds[i].onmouseout = function() {
			this._rotator.setRotation(true);
		}
		this.dts[i]
	}

	this.curr_num = 0; // currently active
	this.trans_to = null; // currently being transitioned to
	this.next_num = null; // next one to be transitioned to

	this.max_num = this.dts.length-1;

	this.setRotation(true);
}

FRotator.prototype.setRotation = function(val) {
	var rotator = this;

	if (!val) {
		clearInterval(this.timeout);
	} else {
//		this.timeout = setInterval(FRotateDone, this.interval);
		this.timeout = setInterval(function() { rotator.rotate(); }, this.interval);
	}
}

FRotator.prototype.rotate = function() {
	if (this.trans_to != null || (this.next_num != null && this.curr_num != this.next_num)) {
		return;
	}

	var n = this.curr_num+1;
	if (n > this.max_num) n = 0;

	this.switchTo(n);
}

FRotator.prototype.switchTo = function(num) {
	if (this.dts.length < 1) return;

	// make sure no dt is active
	if (this.curr_num != null) this.dts[this.curr_num].className = '';
	if (this.next_num != null) this.dts[this.next_num].className = '';

	// make the correct dt active
	this.dts[num].className = 'current';

	// set the next one to be transitioned to
	this.next_num = num;

	// transition going on, wait for it
	if (this.trans_to != null) {
		return;
	}

	// transit
	this.transTo(num);
}

FRotator.prototype.transTo = function(num) {
	if (this.curr_num == num) return;

	this.trans_to = num;

//	new Effect.Fade(this.dds[this.curr_num]);
//	new Effect.Appear(this.dds[num], {afterFinish: transDone});

	var rotator = this;

	new Effect.Parallel(
		[
			new Effect.Fade(this.dds[this.curr_num]),
			new Effect.Appear(this.dds[num])
		],
//		{afterFinish: transDone}
		{afterFinish: function(obj) { rotator.transDone(); } }
	);
}

FRotator.prototype.transDone = function() {
	this.curr_num = this.trans_to;
	this.trans_to = null;

	// o-oh, user moved focus to another one while we were transitioning
	if (this.next_num != null && this.next_num != this.curr_num) this.transTo(this.next_num);
}

function transDone(obj) {
//	obj.element._rotator.transDone();
	obj.effects[0].element._rotator.transDone();
}

var frotator;

addLoadEvent(
	function() {
		frotator = new FRotator('featured');
	}
);
