/************************************************************************
 * ScrollPane.js
 * Provides scrolling functions to create scrolling panes in all 
 * browsers
 ***********************************************************************/
var scrollId = 0;
function scroll(offset, id, interval) {
	if (interval==null) {interval=100;}
	if (offset==0) {
		window.clearInterval(this.scrollId);
	}
	else {
		var js = "window.ri_scrollBy('" + id + "', " + offset + ");";
		scrollId = window.setInterval(js, interval);
	}
}

if (document.getElementById) {
	window.ri_scrollBy = function (id, value) {
		var e = document.getElementById(id);
		var w = e.parentNode;
		if (e.offsetHeight <= w.offsetHeight) {
			window.clearInterval(scrollId);
			return;
		}
		var top = 0;
		if (e.style.top) {
			top = parseInt(e.style.top);
		}
		top += value;
		if (top>0) {
			e.style.top = "0px";
			window.clearInterval(scrollId);
			return;
		}
		else if (top<(w.offsetHeight-e.offsetHeight)) {
			e.style.top = (w.offsetHeight-e.offsetHeight) + "px";
			window.clearInterval(scrollId);
			return;
		}
		e.style.top = top + "px";
	};
	window.scrollTop = function(id) {
		var e = document.getElementById(id);
		e.style.top = "0px";
		window.clearInterval(scrollId);
	};
	window.scrollBottom = function(id) {
		var e = document.getElementById(id);
		var w = e.parentNode;
		e.style.top = (w.offsetHeight - e.offsetHeight) + "px";
		window.clearInterval(scrollId);
	};
}
else if (document.layers) {
	window.ri_scrollBy = function (id, value) {
		var e = window.getLayer(document, id);
		var top = e.top + value;
		if (top>0) {
			e.top = 0;
			window.clearInterval(scrollId);
			return;
		}
		e.top = top;
	};
	window.getLayer = function (parent, id) {
		for (var i=0; i<parent.layers.length; i++) {
			var l = parent.layers[i];
			if (l.name==id) {
				return l;
			}
			if (l.layers.length!=0) {
				var sub = window.getLayer(l, id);
				if (sub!=null) {
					return sub;
				}
			}
		}
		return null;
	};
	window.scrollTop = function(id) {
		var e = window.getLayer(document, id);
		e.top = 0;
	};
}


