var txCeRotator =  {
	periodicalExecuter: null,
	period: 6,

	elements: null,
	position: -1,


	change: function (el1, el2) {
		var posEl = null;
		Effect.Fade(txCeRotator.elements[el1], { duration: 1, from: 1.0, to: 0.0 });
		Effect.Appear(txCeRotator.elements[el2], { duration: 1, from: 0.0, to: 1.0 });

		posEl = document.getElementById('ceRotator-pos');
		if (posEl !== null) {
			posEl.replaceChild(document.createTextNode(el2 + 1), posEl.firstChild);
		}
	},

	rotate: function () {
		var current = txCeRotator.position;
		txCeRotator.position += 1;
		if (txCeRotator.position >= txCeRotator.elements.length) {
			txCeRotator.position = 0;
		}
		txCeRotator.change(current, txCeRotator.position);
	},

	start: function () {
		this.periodicalExecuter = new PeriodicalExecuter(this.rotate, txCeRotator.period);
	},

	stop: function () {
		this.periodicalExecuter.stop();
	},

	prev: function () {
		var current = txCeRotator.position;

		this.stop();
		txCeRotator.position -= 1;
		if (txCeRotator.position < 0) {
			txCeRotator.position = txCeRotator.elements.length - 1;
		}
		txCeRotator.change(current, txCeRotator.position);
		this.start();
	},

	next: function () {
		var current = txCeRotator.position;

		this.stop();
		txCeRotator.position += 1;
		if (txCeRotator.position >= txCeRotator.elements.length) {
			txCeRotator.position = 0;
		}
		txCeRotator.change(current, txCeRotator.position);
		this.start();
	},

	init: function (css) {
		this.elements = document.getElementsByClassName(css);
		this.start();
		this.position = 0;
	}
};
