var hexbase="0123456789ABCDEF";
var RANEWS;
function DecToHex(number) {
  // take a decimal integer, return 2-digit hex string
  return hexbase.charAt((number>> 4)& 0xf)+ hexbase.charAt(number& 0xf);
}

function HexToDec(number) {
  // take a hex string, return decimal integer
  return parseInt(number.toUpperCase(), 16);
}

function RAColor( red, green, blue)
{
	this.red=red;
	this.green=green;
	this.blue=blue;
}
RACol=RAColor.prototype;

RACol.getHex=function()
{
	return "#"+DecToHex(this.red)+DecToHex(this.green)+DecToHex(this.blue);
}
RACol.getColor= function(changeTo,cur,end )
{
	r=Math.round( this.red+ ((changeTo.red-this.red)*cur/end) );
	g=Math.round( this.green+ ((changeTo.green-this.green)*cur/end) );
	b=Math.round( this.blue+ ((changeTo.blue-this.blue)*cur/end) );
	return "#"+DecToHex(r)+DecToHex(g)+DecToHex(b)
}
function RANewsScroller( width,height,style,bgcolor,txcolor,link)
{

	this.width=width;
	this.height=height;	
  this.style=style;
  this.stories=Array();
  this.numofstories=0;
  this.bgcolor=bgcolor;
  this.txcolor=txcolor;
  this.layer;
  this.textlayer;
  this.counter=2;
  this.lineOn=0;
  this.link=link;
  RANEWS=this;
}
RANews=RANewsScroller.prototype;
RANews.addStory = function( line )
{
	this.stories[this.numofstories]=line;
	this.numofstories++;
	this.lineOn++;
}
RANews.draw = function()
{
	document.write("<table onclick=\"window.location.href='"+this.link+"'\" id=RANewsScroller width="+this.width+" height="+this.height+" style='"+this.style+"'><tr><td><div id=RANewsScrollerText></div></td></tr></table>");
	this.layer=new layer("RANewsScroller");
	this.textlayer=new layer("RANewsScrollerText");
	this.layer.css.background=this.bgcolor.getHex();
	this.layer.css.color=this.bgcolor.getHex();
	this.fadeOut();
}
RANews.fadeIn =function()
{
	this.counter++;
	this.layer.css.color=this.bgcolor.getColor(this.txcolor,this.counter,15);
	if( this.counter< 15 )
	{
		setTimeout("RANEWS.fadeIn()",70);
	}
	else
	{
		setTimeout("RANEWS.fadeOut()",300);
	}
}

RANews.fadeOut =function()
{
	this.counter--;
	this.layer.css.color=this.bgcolor.getColor(this.txcolor,this.counter,15);
	if( this.counter> 0 )
	{
		setTimeout("RANEWS.fadeOut()",70);
	}
	else
	{
		//stories[numofstories]
	  	
		this.lineOn++;
		if( this.lineOn>=this.numofstories)
		{
			this.lineOn=0;
		}
		this.textlayer.write(this.stories[this.lineOn]);
		setTimeout("RANEWS.fadeIn()",1000);
	}
}

