﻿//<![CDATA[
/********************************************************************
 * You may use this code for free on any web page provided that     *
 * these comment lines and the following credit remain in the code. *
 * Keep In View (c) JavaScript-FX. (www.javascript-fx.com)          *
 ********************************************************************/
	JSFX_KeepInView = function(id) {
		var getPageY = function(el) { return (el == null) ? 0 : el.offsetTop + getPageY(el.offsetParent); };
		var getScrollTop = function() { return document.body.scrollTop || document.documentElement.scrollTop };
		var el = document.getElementById(id); if (el == null) return;
		if (el.style.position == "absolute") { el.startPageTop = -el.offsetTop; el.currentX = el.offsetLeft; el.currentY = el.offsetTop; }
		else { el.style.position = "relative"; el.startPageTop = getPageY(el); el.currentX = el.currentY = 0; };
		el.floatInView = function() {
			var targetY = (getScrollTop() > this.startPageTop) ? getScrollTop() - this.startPageTop : 0;
			this.currentY += (targetY - this.currentY) / 4; this.style.top = this.currentY + "px";
		};
		return setInterval('document.getElementById("' + id + '").floatInView()', 40);
	};
//]]>
