var Faders = {
	steps: 20,
	transitionInterval: 50,
	relaxTime: 3000,
	start: function () {
		this.element = document.getElementById('faders_images');
		if (!this.element) return;
		this.images = this.element.getElementsByTagName('img');
		if (!this.images) return;
		if (this.images.length < 2) return;

		this.currentImage = this.images[0];
		this.currentImageIndex = 0;
		this.imagesTotal = this.images.length;

		this._start_transition = function () {Faders.startTransition.apply(Faders)};
		this._on_transition_timer = function () {Faders.onTransitionTimer.apply(Faders)};
		setTimeout(this._start_transition, this.relaxTime);
	},
	startTransition: function () {
		this.stepsLeft = this.steps;
		this.newImageIndex = (this.currentImageIndex == this.imagesTotal - 1? 0: this.currentImageIndex + 1);
		this.newImage = this.images[this.newImageIndex];
		this.onTransitionTimer();
	},
	onTransitionTimer: function () {
		this.stepsLeft--;
		var oldOpacity = this.stepsLeft * 100 / this.steps; // 0.. 100
		var newOpacity = 100 - oldOpacity;
		this.currentImage.style.opacity = this.currentImage.style.MozOpacity = this.currentImage.style.KhtmlOpacity = oldOpacity / 100;
		this.currentImage.style.filter = 'alpha(opacity=' + oldOpacity + ')';

		this.newImage.style.opacity = this.newImage.style.MozOpacity = this.newImage.style.KhtmlOpacity = newOpacity / 100;
		this.newImage.style.filter = 'alpha(opacity=' + newOpacity + ')';

		if (this.stepsLeft == 0) {
			this.currentImage = this.newImage;
			this.currentImageIndex = this.newImageIndex;
			setTimeout (this._start_transition, this.relaxTime);
		} else {
			setTimeout (this._on_transition_timer, this.transitionInterval);
		}
	}
}
function startTopFaders() {
	Faders.start();
}
