/**
 * copyright (c) 2010 De Cecco Simone
 * www.simonedececco.it
 * info@simonedececco.it
 */

function Banner(id, textList) {
	var item = document.getElementById(id);
	if (item) {
		this._id = id;
		this._item = item;
		this._textList = textList;
		this._currentIndex = 0;
		this._fadeStep = 10;
		this._fadeTimeOut = 100;
		this._updateTimeOut = 3000;
		this._state = 0;
		this._item.innerHTML = this._textList[0];
		this._item.banner = this;
		this.requestUpdate();
	}
}

Banner.prototype.requestUpdate = function() {
	setTimeout(
		'document.getElementById(\'' + this._id + '\').banner.update()',
		(this._state == 0) ? this._updateTimeOut : this._fadeTimeOut
	);
}

Banner.prototype.update = function() {
	switch (this._state) {
	case 0:
		this._state = 1;
		this._opacity = 100;
	case 1:
		this._opacity -= this._fadeStep;
		break;
	case 2:
		this._opacity += this._fadeStep;
		break;
	}
	this._item.style.filter = 'alpha(opacity=' + this._opacity + ')';
	this._item.style.opacity = (this._opacity / 100);
	if (this._opacity == 0) {
		this._currentIndex = (this._currentIndex + 1) % this._textList.length;
		this._item.innerHTML = this._textList[ this._currentIndex ];
		this._state = 2;
	}
	else if (this._opacity == 100)
		this._state = 0;
	this.requestUpdate();
}
