InnoFade = {};

InnoFade.bPause = false;

InnoFade.arObj = new Array();

InnoFade.prevIndex = null;
InnoFade.prevObj = null;

InnoFade.currentIndex = null;
InnoFade.currentObj = null;

InnoFade.currentDuration = 0;

InnoFade.init = function()
{
	InnoFade.currentObj = this.arObj[0].obj;

	this.Change(0);
	this.SlideThread();
}

InnoFade.SlideThread = function()
{
	if (this.bPause)
	{
		this.currentDuration = 0;
		setTimeout("InnoFade.SlideThread()", 20);

		return;
	}

	if (this.currentDuration >= this.arObj[this.currentIndex].duration)
	{
		var next = this.currentIndex + 1;
		if (next > this.arObj.length-1)
		{
			next = 0;
		}

		this.Change(next);
	}

	this.currentDuration += 20;
	setTimeout("InnoFade.SlideThread()", 20);
}

InnoFade.AppendObject = function(obj, duration, title)
{
	var index = InnoFade.arObj.length;

	this.arObj[index] = new Array();
	this.arObj[index].obj = obj;
	this.arObj[index].duration = duration;
	this.arObj[index].title = title;
}

InnoFade.Change = function(index)
{
	this.currentDuration = 0;

	if (index == 0)
	{
		document.getElementById("InnoFadeSelBtnPrev_on").style.display = "none";
		document.getElementById("InnoFadeSelBtnPrev_off").style.display = "";

		document.getElementById("InnoFadeSelBtnNext_on").style.display = "";
		document.getElementById("InnoFadeSelBtnNext_off").style.display = "none";
	}
	else if (index == this.arObj.length-1)
	{
		document.getElementById("InnoFadeSelBtnPrev_on").style.display = "";
		document.getElementById("InnoFadeSelBtnPrev_off").style.display = "none";

		document.getElementById("InnoFadeSelBtnNext_on").style.display = "none";
		document.getElementById("InnoFadeSelBtnNext_off").style.display = "";
	}
	else
	{
		document.getElementById("InnoFadeSelBtnPrev_on").style.display = "";
		document.getElementById("InnoFadeSelBtnPrev_off").style.display = "none";

		document.getElementById("InnoFadeSelBtnNext_on").style.display = "";
		document.getElementById("InnoFadeSelBtnNext_off").style.display = "none";
	}

	for (var i = 0; i < this.arObj.length; i++)
	{
		this.arObj[i].obj.style.display = "none";
		document.getElementById("InnoFadeSelBtn_on_"+i).style.display = "none";
		document.getElementById("InnoFadeSelBtn_off_"+i).style.display = "";

		if (i == index)
		{
			document.getElementById("InnoFadeSelBtn_off_"+i).style.display = "none";
			document.getElementById("InnoFadeSelBtn_on_"+i).style.display = "";
		}
	}

	this.prevObj = this.currentObj;
	this.currentObj = this.arObj[index].obj;

	if (this.prevObj != null)
	{
		// this.prevObj.style.display = "";
	}

	if (this.currentObj != null)
	{
		this.currentObj.style.display = "";
	}

	document.getElementById("fade_title").innerHTML = this.arObj[index].title;

	this.prevIndex = this.currentIndex;
	this.currentIndex = index;
}

InnoFade.Prev = function()
{
	if (this.currentIndex == 0)
	{
		return;
	}

	this.Change(this.currentIndex-1);
}

InnoFade.Next = function()
{
	if (this.currentIndex == this.arObj.length-1)
	{
		return;
	}

	this.Change(this.currentIndex+1);
}
