/******************************************************************* 
* 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.
***********************************************************************/ 
if(ns4)
{
	JSFX.Layer.prototype.redraw = function()
	{
		this.elem.document.open();
		if(this.sizePre)
			this.elem.document.write(this.sizePre);
		if(this.colorPre)
			this.elem.document.write(this.colorPre);

		this.elem.document.write(this.elem.innerHTML);

		if(this.colorPost)
			this.elem.document.write(this.colorPost);
		if(this.sizePost)
			this.elem.document.write(this.sizePost);

		this.elem.document.close();
	}
	JSFX.Layer.prototype.resizeTo = function(w,h)
	{
		this.sizePre  = "<TABLE WIDTH='"+w+"' cellpadding=0 cellspacing=0 border=0><TR><TD>"
		this.sizePost = "</TR></TD></TABLE>"
		this.style.clip.width	= w;
		this.style.clip.height	= h;
		this.redraw();
	}
	JSFX.Layer.prototype.setColor	= function(c)
	{
		this.colorPre  = "<FONT COLOR='"+c+"'>";
		this.colorPost = "</FONT>";
		this.color = c;
		this.redraw();
	}
	JSFX.Layer.prototype.setContent   = function(xHtml)
	{
		this.elem.innerHTML = xHtml;
		this.redraw();
	}

	JSFX.Layer.prototype.setOpacity = function(pc)
	{
		if(pc == 100)
			this.setColor("#FFFFFF");
		else if (pc == 90)
			this.setColor("#DDDDDD");
		else if (pc == 80)
			this.setColor("#BBBBBB");
		else if (pc == 70)
			this.setColor("#999999");
		else if (pc == 60)
			this.setColor("#777777");
		else if (pc == 50)
			this.setColor("#555555");
		else if (pc == 40)
			this.setColor("#333333");
		else if (pc == 30)
			this.setColor("#111111");
		else if (pc == 20)
			this.setColor("#000000");
		else if (pc == 10)
			this.setColor("#000000");
		else if(pc == 0)
			this.setColor("#000000");
	}
	JSFX.Layer.prototype.setOpacity = function(pc)
	{
	}
}

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.moveTo = function(x,y)
{
	this.x = x;
	this.y = y;
	this.outerLayer.moveTo(this.x, this.y);
}
JSFX.VerticalScroller.prototype.build = function()
{
	this.outerLayer = new JSFX.Layer(" ", null, this.w);
	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.w);
	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);
		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()", 2000);
		}
		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);
}
