// <script>
var agt=navigator.userAgent.toLowerCase();
var is_ie4  = agt.indexOf("msie 4")!=-1;
var IE = document.all?true:false;
var NS = document.layers?true:false;
var NS6 = (!IE && document.getElementById)?true:false;
var Opera = navigator.userAgent.indexOf("Opera")!=-1?true:false;

var idscrcnt = new Array();

function scroller(x, y, width, height)
{

	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;

	this.bgColor = "";
	this.bgImage = "";
	
	this.itemLeft = 10;
	this.itemWidth = 0;

	this.delay = 50;
	this.pause = 2000;
	this.mousePause = 500;
	this.mouseStop = true;
	
	this.ID = idscrcnt.length;
	idscrcnt[idscrcnt.length] = this;
	
	this.items = new Array();
	
	this.curItem = 0;
	
	this.addItem = scrAddItem;
	this.init = scrInit;
}

function scrAddItem(text)
{
	// Text should be a fully qualified HTML string
	this.items[this.items.length] = text;
}

function scrInit()
{
var scrText,i, mItem, o, o1;
var tp=2; 

	if (this.itemWidth == 0)
		this.itemWidth = this.width - 2 * this.itemLeft;
	if (IE && !Opera)
	{

		var s;
		
		//This is the scroller area
		scrText = "<div id='idscr" + this.ID + "' style=\"position:relative; visibility:visible; width:" + this.width + "px; overflow-y:hidden;\"></div>";
		o1 = eval("divscroller" + this.ID);
		o1.style.width=this.width;
		o1.style.wordWrap = "break-word";
		o1.insertAdjacentHTML ("BeforeEnd", scrText);
		
		o = eval("idscr" + this.ID);

		this.o = o;
		o.obj = this;
		
		s = o.style;
		s.pixelLeft = this.x;
		s.pixelTop = this.y;
		s.pixelWidth = this.width;
		s.pixelHeight = this.height;
		s.backgroundColor = this.bgColor;
		s.backgroundImage = "url(" + this.bgImage + ")";
		s.clip = "rect(0,"+ s.pixelWidth + "," + s.pixelHeight + ",0)";

		this.loPos = is_ie4?this.height:o.clientHeight + 2;

		if(is_ie4) tp=this.loPos;
		for (i=0;i<this.items.length;++i)
		{
			//Initialize the scrolling items
			o.insertAdjacentHTML("BeforeEnd", "<span id=sci" + this.ID + i + " style=\"position:absolute;\">" + this.items[i] + "</span>");
			mItem = eval("sci" + this.ID + i); 
			mItem.style.pixelLeft = this.itemLeft;
			mItem.style.pixelWidth = this.itemWidth;

			mItem.style.pixelTop = tp;
			tp += mItem.clientHeight + 5;
			if (tp>this.loPos) tp=this.loPos;
			this.items[i] = mItem;
		}
	}
	else if (NS)
	{
	/*
		eval ("idscr" + this.ID + "= new Layer("+ this.width +",window)");
		
		o = eval("idscr" + this.ID);
		
		this.o = o;
		o.obj = this;
		
		o.left = this.x;
		o.top = this.y;
		o.width = this.width;
		o.height = this.height;
		o.visibility = "show";
		o.clip.right = this.width;
		o.clip.bottom = this.height;
		o.clip.top = 0;
		o.clip.left = 0;
		if (this.bgColor.length != 0) o.bgColor = this.bgColor;
		o.background.src = this.bgImage;
		this.loPos = this.height;
		for (i=0;i<this.items.length;++i)
		{
			eval ("sci" + i + "= new Layer("+this.itemWidth+",idscr" + this.ID + ")");
			mItem = eval("sci" + i);
			mItem.left = this.itemLeft;
			mItem.document.write( this.items[i] );
			mItem.document.close();
			mItem.top = tp;
			tp+=mItem.document.height + 5;
			if (tp>this.loPos) tp=this.loPos; 
			mItem.clip.right = this.itemWidth;
			mItem.visibility = "show";
			this.items[i] = mItem;
		}
	*/} else if (NS6 || Opera)
	{
		var s;

		var o = document.createElement("DIV");
		o.id = "idscr" + this.ID;
		o.style.position = "relative";
		o.style.visibility = "visible";
		o.style.width = this.width+"px";		

		var o2 = document.getElementById("divscroller"+this.ID);
		o2.style.position = "relative";

		o2.appendChild(o);
		
		this.o = o;
		o.obj = this;
		
		s = o.style;
		
		s.left = this.x+"px";
		s.top = this.y+"px";
		s.width = this.width+"px";
		s.height = this.height+"px";		//height is only meaningful when appended with "px"
		s.overflow = "hidden";



		s.backgroundColor = this.bgColor;
		s.backgroundImage = "url(" + this.bgImage + ")";
		s.clip = "rect(0,"+ this.width + "," + this.height + ",0)";


		this.loPos = o.offsetHeight+5;

		for (i=0;i<this.items.length;++i)
		{
			
			mItem = document.createElement("span");
			mItem.id = "sci" + this.ID + i;
			mItem.style.position = "absolute";
			mItem.innerHTML = this.items[i];
						
			mItem.style.left = this.itemLeft+"px";		
			mItem.style.width = this.itemWidth+"px";
			mItem.style.top = tp+"px";
			o.appendChild(mItem);
			tp += mItem.offsetHeight + 10;

			if (tp>this.loPos) tp=this.loPos;
			this.items[i] = mItem;
			
		}
	}
	if (tp==this.loPos)	//if the total height of the scroller items are less than the height of area, don't scroll
	{
		if (this.mouseStop)
		{
			o.onmouseover = scrMOver;
			o.onmouseout  = scrMOut;
		}
		scrTimer = window.setTimeout("scrScroll("+this.ID+")" ,this.pause);
	}
}

function scrScroll(idx)
{

var i, prevItem, nxt, pause, o, oi;

	o = idscrcnt[idx];
	oi = o.items;
	window.clearTimeout(scrTimer);
	nxt = false;
	pause = false;
	i = o.curItem;
	prevItem = i-1;
	if (prevItem < 0) prevItem = oi.length-1;
	do
	{
		if (IE && !Opera)
		{	
			if (i == o.curItem || (oi[prevItem].style.pixelTop + oi[prevItem].clientHeight + 2)<o.loPos)
			{
				oi[i].style.pixelTop -= 1;
				if (oi[i].style.pixelTop == 2) pause = true;
			}
		}
		else if (NS)
		{/*
			if (i == o.curItem || (oi[prevItem].top + oi[prevItem].document.height + 2)<o.loPos)
			{
				oi[i].top -= 1;
				if (oi[i].top == 2) pause = true;
			}
		*/}
		else if (NS6 || Opera)
		{	//parseInt will ignore "px"
			if (i == o.curItem || (parseInt(oi[prevItem].style.top) + oi[prevItem].offsetHeight + 2)<o.loPos)
			{
				oi[i].style.top = (parseInt(oi[i].style.top)-1)+"px";
				if (parseInt(oi[i].style.top) == 2) pause = true;
			}
		}
		prevItem = i;
		if (++i == oi.length) i=0;
	}
	while (i != o.curItem);
	
	if (pause)
		o.timer = window.setTimeout("scrRotate(" + idx + ")",o.pause);
	else
		o.timer = window.setTimeout("scrRotate(" + idx + ")",o.delay);
}

function scrRotate(idx)
{

var o, oi;
	o = idscrcnt[idx];
	oi = o.items;
	for (var i=0; i<oi.length;++i)
	{
		if (IE && !Opera)
		{
			if ((oi[i].style.pixelTop + oi[i].clientHeight)<0)
			{
				oi[i].style.pixelTop = o.loPos;
				if (++(o.curItem) == oi.length)
					o.curItem = 0;
			}
		}
		else if (NS)
		{/*
			if ((oi[i].top + oi[i].document.height)<0)
			{
				oi[i].top = o.loPos;
				if (++(o.curItem) == oi.length)
					o.curItem = 0;
			}
		*/}
		else if (NS6 || Opera)
		{
			
			if ((parseInt(oi[i].style.top) + oi[i].offsetHeight)<0)
			{
				
				oi[i].style.top = o.loPos+"px";
				if (++(o.curItem) == oi.length)
					o.curItem = 0;
			}
		}
	}
	scrScroll(idx);
}

function scrMOver(){window.clearTimeout(this.obj.timer);}
function scrMOut(){this.obj.timer = window.setTimeout("scrRotate(" + this.obj.ID + ")",this.obj.mousePause);}
