﻿function NewsTicker(ul)
{
	this.ul = document.getElementById(ul);	
	if (this.ul)
	{
		this.lis = Array();
		this.current = 0;
		this.previous = null;
		this.runonce = false;
		this.delay = 5000;
		this.news	= null;
		
		var length = this.ul.childNodes.length;
		
		while (this.ul.childNodes.length>0)
		{
			var child = this.ul.childNodes[0];
			//alert(child.innerHTML);
			
			if (child.tagName == 'LI')
			{
				//child.style.display = 'inline-block';
				//child.style.display = 'block';
				child.style.filter = "alpha(opacity=" + 0 + ")";
				child.style.opacity = 0;
				
				this.lis.push(child);				
			}
			
			this.ul.removeChild(child);
		}

		this.ul.style.visibility = 'visible';
		this.start();
	}
}
NewsTicker.prototype.start=function()
{
	try
	{
		if (this.previous)
			this.ul.removeChild(this.previous);
		this.ul.appendChild(this.lis[this.current]);
			
		var callback = this.wait.bind(this);
		if (this.runonce && (this.current == this.lis.length-1))
			callback = null;
				
		var obj1 = new Opacity(this.lis[this.current], 4500, callback);
		obj1.FadeIn();
			
		if (this.runonce && (this.current+1 >= this.lis.length))
			this.previous = this.lis[this.current+1];
		else
			this.previous = this.lis[this.current];	
	}
	catch(err)
	{		
	}
}
NewsTicker.prototype.wait=function()
{
	setTimeout(function(){this.remove();}.bind(this), this.delay/2);
	setTimeout(function(){this.next();}.bind(this), this.delay);	
}
NewsTicker.prototype.next=function()
{
	this.current = (this.current+1 < this.lis.length) ? this.current+1 : 0;
	this.start();
}
NewsTicker.prototype.stop=function()
{	
}
NewsTicker.prototype.pause=function()
{	
}
NewsTicker.prototype.resume=function()
{	
}
NewsTicker.prototype.remove=function()
{
	if (this.previous)
	{
		var o = new Opacity(this.previous, 5000);
		o.FadeOut();		
	}
}
