FadeApi = function(NumberOfImages, StartNumber,ID,PauseTime,FadeLoopTime)
{
    // Store constructor parameters
    this.NumberOfImages = NumberOfImages;
	this.CurrentItem = null;
	this.NextItem = null;
	this.CurrentNumber = StartNumber;
	this.ID = ID;
	this.nextValue = 0;
	this.Currentvalue = 1;
	this.timeout = null;
	this.PauseTime = PauseTime;
	if(FadeLoopTime != null)
		this.FadeLoopTime = FadeLoopTime;
	else
		this.FadeLoopTime = 4;


    // Hook the onLoad event
    addOnLoadHandler(this, this.onLoad);
    return this;
}

FadeApi.prototype.onLoad = function()
{
	this.CurrentItem = document.getElementById(this.ID +this.CurrentNumber);
	if(this.NumberOfImages > this.CurrentNumber)
	{
		this.NextItem = document.getElementById(this.ID +(this.CurrentNumber+1));
		var obj = this;
		this.timeout = setTimeout(function () { obj.Fade(); }, this.PauseTime);
	}
}

FadeApi.prototype.Fade = function()
{
	var obj = this;
    this.CurrentItem.style.display = "inline";
    this.NextItem.style.display = "inline";
	this.nextValue = this.nextValue + 0.010000000000000;
	this.Currentvalue = this.Currentvalue - 0.010000000000000;
	var num = new Number(this.Currentvalue);

    if (this.CurrentItem.filters != null){
		this.NextItem.filters.alpha.opacity = (100*this.nextValue);
		this.CurrentItem.filters.alpha.opacity = (100 * num.toFixed(10));
    }
    else if (this.CurrentItem.style.MozOpacity != null)
    {
		this.NextItem.style.MozOpacity=this.nextValue
		this.CurrentItem.style.MozOpacity=num.toFixed(10)
    }
    else if (this.CurrentItem.style.KhtmlOpacity != null)
    {
		this.NextItem.style.KhtmlOpacity=this.nextValue
		this.CurrentItem.style.KhtmlOpacity=num.toFixed(10)
    }

	if (this.nextValue <= 1)
	{
		this.timeout = setTimeout(function () { obj.Fade(); },this.FadeLoopTime);
	}
	else
	{
		this.CurrentNumber++;
		this.nextValue = 0;
		this.Currentvalue =1;
		this.CurrentItem.style.display = "none";
		if(this.CurrentNumber == this.NumberOfImages)
		{
			this.CurrentItem = document.getElementById(this.ID +this.CurrentNumber);
			this.NextItem = document.getElementById(this.ID +"1");
			this.CurrentNumber = 0;
		}
		else
		{
			this.CurrentItem = document.getElementById(this.ID +this.CurrentNumber);
			this.NextItem = document.getElementById(this.ID +(this.CurrentNumber+1));
		}
		obj = this;
		setTimeout(function () { obj.Fade(); },this.PauseTime);
	}
}