var nTime;
var nTick;
var nInt = 30;
var iFeed = 5000;
var feeder;
function initNews() 
{
	var a=document.getElementById("content-front-feed").getElementsByTagName("div");
	feeder = new newsfeed(a.length);
	for (i=0; i < a.length; i++)
	{
		a[i].id="content-front-item-0" + (i+1);
	}
	document.getElementById("content-front-item-01").style.opacity = 1.0;
	document.getElementById("content-front-item-01").style.filter = 'alpha(opacity=100)';
	document.getElementById("content-front-item-01").style.visibility="visible";
    clearTimeout(nTime);
    nTime = setTimeout("nextNews()", iFeed);
}
function nextNews() 
{
    var nxt = (feeder.curIdx + 1  > feeder.max  ? 1 : feeder.curIdx + 1);
	feeder.nextIdx=nxt;
	document.getElementById("content-front-item-0" + feeder.nextIdx).style.visibility="visible";
	feeder.state=0;
    clearTimeout(nTime);
    clearInterval(nTick);
    nTick = setInterval("feeder.tick()", nInt);
}

/********************Application Object: Animates the newsfeed*****************/
function newsfeed(num) 
{
    this.curIdx = 1;
	this.curOpc = 1.0;
    this.nextIdx = 2;
	this.nextOpc = 0;
	this.fadeInc=0.03;
    this.minTick = 2;
    this.max = num;
	this.state = 0;

    this.update = update;
    this.tick = tick;
    this.render = render;
	this.tfadeIn=tfadeIn;
	this.tfadeOut=tfadeOut;
	this.rfadeIn=rfadeIn;
	this.rfadeOut=rfadeOut;
}
function update() 
{

}
function render() 
{
    switch (this.state)
	{
		case 0:
			this.rfadeOut();
			this.rfadeIn();
			break;
		default:
			break;
	}
}
function tick() 
{
	switch (this.state)
	{
		case 0:
			var bOut=this.tfadeOut();
			var bIn=this.tfadeIn();
			this.render();
			if (bOut && bIn)
			{
				this.state+=1;
			}
			break;
		default:
			this.nextOpc=0;
			this.curOpc=1;
			this.curIdx = this.nextIdx;
			clearInterval(nTick);
			clearTimeout(nTime);
			nTime = setTimeout("nextNews()", iFeed);
			this.state=-1;
			break;
	}
}
function tfadeOut()
{
	this.curOpc=( this.curOpc - this.fadeInc > 0 ? this.curOpc - this.fadeInc : 0);
	if (this.curOpc == 0)
	{
		document.getElementById("content-front-item-0" + this.curIdx).style.visibility="hidden";
		return true;
	}
	else
	{
		return false;
	}
}
function rfadeOut()
{
	document.getElementById("content-front-item-0" + this.curIdx).style.opacity = this.curOpc;
	document.getElementById("content-front-item-0" + this.curIdx).style.filter = 'alpha(opacity='+ this.curOpc * 100 +')';
}
function tfadeIn()
{
	this.nextOpc=( this.nextOpc + this.fadeInc < 1 ? this.nextOpc + this.fadeInc : 1);
	if (this.nextOpc == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function rfadeIn()
{
	document.getElementById("content-front-item-0" + this.nextIdx).style.opacity = this.nextOpc;
	document.getElementById("content-front-item-0" + this.nextIdx).style.filter = 'alpha(opacity='+ this.nextOpc * 100 +')';
}


