var uid = 1;

function scroller(sconf,article,name){

	this.article = article;
	this.id = uid++;
	this.name = name;

	
	this.isIE = (document.getElementById && document.all)?true:false;
	this.isNS4 = (document.layers)?true:false;
	this.isNS6 = (document.getElementById && !document.all)?true:false;

	this.ns4Text = "Click Here to visit the PlanMagic Software";
	this.ns4URL = "http://planmagic.com";
	this.ns4Target = "_top";

	this.table = sconf['table'];
	this.divs = sconf['divs'];
	this.orientation = sconf['orientation'];
	this.scrollerWidth = sconf['scrollerWidth'];
	this.scrollerHeight = sconf['scrollerHeight'];
	this.borderWidth = sconf['borderWidth'];
	this.borderColour = sconf['borderColour'];
	this.backColour = sconf['backColour'];
	this.staticColour = sconf['staticColour'];
	this.stopScroll = sconf['stopScroll'];
	this.textAlignment = sconf['textAlignment'];
	this.linkFont = sconf['linkFont'];
	this.linkWeight = sconf['linkWeight'];
	this.linkColour = sconf['linkColour'];
	this.linkSize = sconf['linkSize'];
	this.linkDecoration = sconf['linkDecoration'];
	this.slinkFont = sconf['slinkFont'];
	this.slinkWeight = sconf['slinkWeight'];
	this.slinkColour = sconf['slinkColour'];
	this.slinkSize = sconf['slinkSize'];
	this.slinkDecoration = sconf['slinkDecoration'];
	this.scrollerDivider = sconf['scrollerDivider'];

	this.run = false;

	this.style='<style type="text/css">';
//	this.style+='p{font-family:'+this.linkFont+'; color:'+this.staticColour+'; font-size:'+this.linkSize+'pt; font-weight:'+this.linkWeight+'; text-align:'+this.textAlignment+'}';
	this.style+='a.rcScroller'+this.id+',a.rcScroller'+this.id+':active,a.rcScroller'+this.id+':visited{color:'+this.linkColour+';text-decoration:'+this.linkDecoration+'; font-weight:'+this.linkWeight+'}';
	this.style+='a.rcScroller'+this.id+':hover{color:'+this.slinkColour+';text-decoration:'+this.slinkDecoration+'; font-weight:'+this.slinkWeight+'}';
	this.style+='rcScrollerHoverNS'+this.id+'{color:red;text-decoration:'+this.slinkDecoration+'; font-weight:'+this.slinkWeight+'}';
	this.style+='<\/style>';
	document.writeln(this.style);
	

	this.setWidth = function()
	{ 
		this.tableObj=(this.isIE)?document.all(this.table):document.getElementById(this.table);
		this.obj=(this.isIE)?document.all(this.divs):document.getElementById(this.divs);
		this.objWidth=(this.orientation.toLowerCase()=="horizontal")?this.getOffset(this.tableObj,"width"):this.getOffset(this.tableObj,"height");
		this.HalfWidth=Math.floor(this.objWidth/2);
		this.newWidth = (this.HalfWidth*2)+2;
		this.obj.style.width=this.newWidth
		this.moveLayer();
	}

	this.moveLayer = function()
	{
		this.maxLeft = (0-(this.newWidth/2)+2)/2
		if(this.orientation.toLowerCase()=="horizontal")
		{
			this.obj.style.left=(parseInt(this.obj.style.left) <= this.maxLeft)?0:parseInt(this.obj.style.left)-1
		}
		else
		{
			if(this.obj.style.top=="")
			{
				this.obj.style.top=0;
			}
			if (parseInt(this.obj.style.top)<(0-(this.newWidth/2)+6))
			{
				this.obj.style.top = 0
			}
			else
			{
				this.obj.style.top = parseInt(this.obj.style.top)-1
			}
		}
	
		this.timer = setTimeout (this.name+".moveLayer(this.obj, "+this.newWidth+");", 25); 			
	}



	this.getOffset = function(obj, dim) 
	{
		if(dim=="width")
		{
			oWidth = obj.offsetWidth
			return oWidth
		}
		else if(dim=="height")
		{
			oHeight = obj.offsetHeight
			return oHeight
		}
	}

	this.stopScroller = function()
	{
		clearTimeout(this.timer)
		this.run=false;
	}

	this.runScroller = function()
	{
		if(!this.isNS4)
		{
			this.setWidth();
		}
	}

	this.buildScroller = function()
	{
		if(this.isNS4)
		{
			this.scroller='<table border="0" cellpadding="0" cellspacing="0" width="'+this.scrollerWidth+'" bgcolor="'+this.borderColour+'"><tr><td>'
			this.scroller+='<table border="0" cellpadding="3" cellspacing="1" width="100%" height="'+this.scrollerHeight+'" bgcolor="'+this.backColour+'"><tr><td align="center" nowrap><p>';
		    if(this.ns4URL.toLowerCase()!="none")
			{
				this.scroller+='<a href="'+this.ns4URL+'" class="rcScroller" target="'+this.ns4Target+'">'+this.ns4Text+'</a>';
			}
			else
			{
				this.scroller+=this.ns4Text;
			}
			this.scroller+='</p></td></tr></table></td></tr></table>'
		}
		else
		{
			this.scroller='<table border="0" cellpadding="0" cellspacing="0" style="width:'+this.scrollerWidth+';height:'+this.scrollerHeight+';border:'+this.borderWidth+'px solid '+this.borderColour+';background-color:'+this.backColour+'">';
			this.scroller+='<tr valign="middle"><td><div id="div" style="';
			if(this.orientation.toLowerCase()=="vertical")
			{
				this.scroller+='height:'+this.scrollerHeight+';';
			}
			this.scroller+='width:'+this.scrollerWidth+'; position:relative; background-color:'+this.backColour+'; overflow:hidden">';
			this.scroller+='<div id="'+this.divs+'" style="position:relative; left:0; z-index:1">';
			this.scroller+='<table border="0" name="'+this.table+'" id="'+this.table+'"';
			if(this.orientation.toLowerCase()=="vertical")
			{
				this.scroller+='style="width:'+this.scrollerWidth+'"';
			}
			this.scroller+='><tr>';
			this.y=0;
			while (this.y<4)
			{
				for (this.x=0; this.x<(this.article.length); this.x++)
				{
					if(this.orientation.toLowerCase()=="vertical")
					{
						this.scroller+='<tr>';
					}
					this.scroller+='<td ';
					if(this.orientation.toLowerCase()=="horizontal")
					{
						this.scroller+='nowrap';
					} 
					if(this.stopScroll==1)
					{
						this.scroller+=' onMouseOver="'+this.name+'.stopScroller();" onMouseOut="'+this.name+'.setWidth()"';
					}
					this.scroller+='><p>';
					if(this.article[this.x][1].toLowerCase()!="none")
					{
						this.scroller+='<a class="rcScroller" href="'+this.article[this.x][1]+'" target="'+this.article[this.x][2]+'" >'+this.article[this.x][0]+'<\/a>';
					}
					else
					{
						this.scroller+=this.article[this.x][0];
					}
					this.scroller+='</p><\/td>';
        
					if(this.orientation.toLowerCase()=="vertical")
					{
						this.scroller+='<\/tr>';
					}
              
					if(this.scrollerDivider.toLowerCase() != "none")
					{
						this.scroller+='<td nowrap><p>'+this.scrollerDivider+'<\/p><\/td>';
					}
				}
				this.y++
			}
			
			this.scroller+='<\/tr><\/table><\/div><\/div><\/td><\/tr><\/table>';  
		}
		
		document.writeln(this.scroller);
	}
}
