/* Original Scroll layer script provided by Quirksmode 
http://www.quirksmode.org/js/layerscroll.html
*/

var clipTop = 0;
var clipWidth = 1690;
// if  set clip in the html style then this value should be the same as 'bottom' or thrid value across
var clipBottom = 195;
//this should be the same as the variable in the style sheet left: otherwise will jump
var topper = 0;
var clipLeft = 0;
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;
//following variables for auto scrolling allows when reaches end to return
var instanceIsAuto = false;
var start = 0;
var amountToMove = 0;
var autoAmnt = 0;

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	 
	var x = new getObj('images');
	if (document.layers)
	{
		//lyrheight = x.style.clip.bottom;
		//lyrheight += 20;
		lyrWidth = x.style.clip.left;
		lyrWidth += 20;
		
		x.style.clip.top = clipTop;
		x.style.clip.left = clipLeft;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if (document.getElementById || document.all)
	{
		//lyrheight = x.obj.offsetHeight;
		//alert(lyrheight); 
		//we take 86 off as this is the offset amount so it loops correctly.
		lyrWidth = x.obj.offsetWidth - 500;
		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,'+clipLeft+'px)';
	}
	
	//crappy workaround that some browsers won't return the offsetWidth so give it the width manually.
	if(lyrWidth <= 0)
	{
		lyrWidth = 500 - 76;
	}	
	
	//stuff it layer width is fixed 
	lyrWidth = 1690 - 500;
	autoAmnt = 10;
}

function scrollayer(layername,amt,tim,isAuto)
{
	if (!DHTML) return;
	
	thelayer = new getObj(layername);
	if (!thelayer) return;
	
	//amountToMove = lyrWidth - 500;
	//amountToMove = amountToMove - (amountToMove * 2);
	
	amountToMove = -1690;
	
	instanceIsAuto = isAuto;
	if(instanceIsAuto == true && topper < (amountToMove + 20))
	{		
		autoAmnt = -2;
	}
	if(instanceIsAuto == true && topper > -10)
	{		
		autoAmnt = 2;
	}
	amount = amt;
	if(instanceIsAuto == true)
	{	
		amount = autoAmnt;
	}	
	theTime = tim;
	start = 0;
	
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	
	clipWidth += amount;
	clipLeft += amount;
	topper -= amount;
	start ++;
	
	if(instanceIsAuto == true)
	{
		if (clipLeft < 0 || topper < amountToMove || start > 60)
			{
				clipWidth -= amount;
				clipLeft -= amount;
				topper += amount;
				//alert(topper+":topper "+amountToMove+":amountto move");
				return;
			}
	} else 	{
		if (clipLeft < 0 || topper < amountToMove)
			{
				clipWidth -= amount;
				clipLeft -= amount;
				topper += amount;
					if (document.getElementById || document.all)
					{
							//clipstring = 'rect(0px,452px,173px,2px)';
							clipTop = 0;
							clipWidth = 502;
							clipBottom = 195;
							clipLeft = 2;
							topper = -2;
							
							clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,'+clipLeft+'px)';
							thelayer.style.clip = clipstring;
							thelayer.style.left = topper + 'px';
							document.getElementById('scrollingText').style.left = topper * 1.34 + 'px';
						}
						else if (document.layers)
						{	
							clipTop = 0;
							//thelayer.style.clip.top = clipTop;
							clipBottom = 195;
							//thelayer.style.clip.bottom = clipBottom;
							topper = -2;
							//thelayer.style.left = topper;
						}
				//return;
			} else {
				if (document.getElementById || document.all)
				{
					clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,'+clipLeft+'px)';
					thelayer.style.clip = clipstring;
					thelayer.style.left = topper + 'px';
					document.getElementById('scrollingText').style.left = topper * 1.34 + 'px';
				}
				else if (document.layers)
				{
					thelayer.style.clip.top = clipTop;
					thelayer.style.clip.bottom = clipBottom;
					thelayer.style.left = topper;
					document.getElementById('scrollingText').style.left = topper * 1.34;
				}
		}		
	}		
	time = setTimeout('realscroll()',theTime);
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}