/*
 * $RCSfile: scroll.js,v $
 * $Source: /cvs/inghamweb-dev/scroll.js,v $, $Revision: 1.1 $, $Date: 2008/08/08 09:35:38 $, $State: Exp $
 */

//SCROLLING NEWS

//var sp = null;

window.onload = function() {
	if (document.getElementById('scrollingpanel')) {
		sp = getObj("scrollingpanel");
		var y = window.setInterval('scroll(sp, 1)', 40);		
	}
}
	
	function findPosY(obj){
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
	
	function getObj(name)
	{
	   var thisObj;
	   if (document.getElementById)
	   {
		thisObj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	   }
	   else if (document.all)
	   {
		thisObj = document.all[name];
		this.style = document.all[name].style;
	   }
	   else if (document.layers)
	   {
		thisObj = getObjNN4(document,name);
		this.style = this.obj;
	   }
	   return thisObj;
	}
	
	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;
	}
	
	function scroll(element, step){
		var elementparent = element.parentNode;
		var etop = findPosY(element) - findPosY(elementparent);
		var eheight = element.offsetHeight;
		var epheight = elementparent.offsetHeight;
		
//alert(element.clientTop);
		
		if((etop * etop) >= (eheight * eheight)){
			element.style.top = epheight+"px";
		}
		else{
			element.style.top = (etop-step)+"px";
		}
	}
	
