/******************************************************************* 
* File    : JSFX_VerticalScroller.js  © JavaScript-FX.com
* Created : 2001/09/28 
* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com 
* Purpose : To create a cross browser news scroller
* History 
* Date         Version        Description 
* 2001-09-28	1.0		I have seen hundreds of news scrollers so I thought
*					I would try and write one that  was easy to install.
***********************************************************************/ 

JSFX.VerticalScroller = function(x, y, w, h)
{
	this.state = "NOT_BUILT";
	this.x = x;
	this.y = y;
	this.sx = 0;
	this.sy = 0;
	this.w = w;
	this.h = h;
	this.scrollLayer = null;
	this.outerLayer = null;
	this.bgColor = null;
	this.messages = new Array();
	this.currMessage = 0;
	this.step = 2;
	this.id = "JSFXScroll" + JSFX.VerticalScroller.no++;
	window[this.id]=this;
}
JSFX.VerticalScroller.no = 0;
JSFX.VerticalScroller.prototype.build = function()
{
	this.outerLayer = new JSFX.Layer(" ");
	this.outerLayer.moveTo(this.x, this.y);
	this.outerLayer.resizeTo(this.w, this.h);
	this.outerLayer.show();
	this.outerLayer.clip(0,0,this.w, this.h);
	if(this.bgColor != null)
		this.outerLayer.setBgColor(this.bgColor);

	this.scrollLayer = new JSFX.Layer(" ", this.outerLayer);
	this.scrollLayer.moveTo(0,0);
	this.scrollLayer.resizeTo(this.w, this.h);
	this.scrollLayer.show();
	this.scrollLayer.setzIndex(100);

	this.state = "OFF";
}
JSFX.VerticalScroller.prototype.setBgColor = function(color)
{
	this.bgColor = color;
	if(this.state != "NOT_BUILT")
		this.outerLayer.setBgColor(color);
}
JSFX.VerticalScroller.prototype.addMessage = function(message)
{
	this.messages[this.messages.length] = message;
}
JSFX.VerticalScroller.prototype.animate = function(message)
{
	if(this.state == "OFF")
	{
		this.sx=0;
		this.sy=this.h;
		this.scrollLayer.moveTo(this.sx, this.sy);
		if(ns4)
			this.scrollLayer.setContent("<TABLE WIDTH='"+this.w+"' cellpadding=0 cellspacing=0 border=0><TR><TD>"+this.messages[this.currMessage]+"</TR></TD></TABLE>");
		else
			this.scrollLayer.setContent(this.messages[this.currMessage]);
			this.scrollLayer.setOpacity(100);
		this.state = "ANIMATING";	
		this.setTimeout("animate()", 40);
	}
	else if(this.state == "ANIMATING")
	{
		this.sy -= this.step;
		this.scrollLayer.moveTo(this.sx, this.sy);
		if(this.sy <= 0)
		{
			this.currMessage = (this.currMessage + 1) % this.messages.length;
			this.state = "FADING";
			this.op=100;
			this.setTimeout("animate()", 8000);
		}
		else
			this.setTimeout("animate()", 40);
	}
	else if(this.state == "FADING")
	{
		this.op -= 10;
		if(this.op == 0)
			this.state = "OFF";
		this.scrollLayer.setOpacity(this.op);
		this.setTimeout("animate()", 40);
	}
}
JSFX.VerticalScroller.prototype.setTimeout = function(f, t) 
{
	setTimeout("window."+this.id+"."+f, t);
}
