
function FadingBoxControl(tBoxIDs, cycle, speed, wait)
{
	this.boxIDs = tBoxIDs;
	this.currentID = -1;
  this.currentBox = null;
  this.opacityStep = 0;
  this.defaultStep = 5;
	this.opacityChange = this.defaultStep;
	this.skipTimer = 0;
	this.cycle = (cycle == undefined ? true : cycle);
	this.speed = (speed == undefined ? 60 : Math.round(speed/2));
	this.wait = (wait == undefined ? 40 : wait);
	this.stopNow = false;
	
	this.fadingBoxFade();
}

FadingBoxControl.prototype.fadingBoxFade = function()
{
	var thisObject = this;
	var extraDec = 0;
	
	this.stopNow = false;
	
	if (this.skipTimer > 0)
	{
		this.skipTimer = this.skipTimer - 1;
		setTimeout(function() {thisObject.fadingBoxFade();}, this.speed);
		return;
	}
	
	if (this.opacityStep == 0)
	{
		if (this.currentBox) this.currentBox.style.display = 'none';
		if ((this.cycle) || (this.currentID == -1))
		{
			this.currentID++;
			if (this.currentID >= this.boxIDs.length) this.currentID = 0;
			this.currentBox = document.getElementById(this.boxIDs[this.currentID]);
			this.opacityChange = this.defaultStep; this.opacityStep = this.defaultStep;
		}
		else
			this.currentBox = null;
	}
	else if (this.opacityStep == 100)
	{	
		if (!this.cycle) this.stopNow = true;
		this.opacityChange = - this.defaultStep;
		this.skipTimer = this.wait;
		extraDec = - this.defaultStep;
	}
	else
		this.opacityStep += this.opacityChange;
	
	if (this.currentBox)
	{
		this.currentBox.style.display = 'block';
		this.currentBox.style.filter = 'alpha(opacity=' + this.opacityStep + ')';
		this.currentBox.style.opacity = (this.opacityStep/100);
		if ((!this.stopNow) || ((this.wait == 0)&&(currentMouseElement != this.boxIDs[this.currentID])))
			setTimeout(function() {thisObject.fadingBoxFade();}, this.speed);
	}
	
	this.opacityStep += extraDec; extraDec = 0;	
}

FadingBoxControl.prototype.fadeOut = function()
{
	var thisObject = this;
	
	if (this.stopNow)
	{
		this.skipTimer = 0;
		setTimeout(function() {thisObject.fadingBoxFade();}, this.speed);
	}
}

