/*
		dw_stat.js
		glide to location on scroll
		requires dw_core.js, dw_util.js
		version date: March 2003 

		This code is from Dynamic Web Coding 
    at http://www.dyn-web.com/
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    Permission granted to use this code 
    as long as this entire notice is included.				
*/

/* 
 * The gliding layer code is a modification of:
 * chaser.js
 * by Aaron Boodman v1.0 000919
 * Copyright (c) 2000 Aaron Boodman. All Rights Reserved.
 * Created for GreatEqualizer.com (http://www.greatequalizer.com/) and
 * documented at DHTML Lab (http://www.webreference.com/dhtml/)
 * License to use is granted if and only if this entire
 * copyright notice is included.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
*/

statObj.ar = new Array();
function statObj(id,x,y,w,h,d) {
	this.dur=d||1000; this.xOff=x; 
	if (y>=0) this.yOff=y;	
	else { 
		this.relBtm = y;
		this.yOff = y = getWinHeight() + y;
	}
	this.bobj = dynObj;
	this.bobj(id,x,y,w,h);
  statObj.ar[statObj.ar.length] = this;
  this.show();
}
statObj.prototype = new dynObj;
statObj.prototype.checkStatLyr=checkStatLyr;
statObj.prototype.glideInit=statGlideInit; 
statObj.prototype.glide=statGlide;
statObj.prototype.onGlideInit=function(){}

// adapted from ypChaser
// Aaron Boodman's updated chaser from www.youngpup.net
window.setInterval("statObj.timer()",20);
statObj.timer = function() {
  for (var i=0; i<statObj.ar.length; i++) {
    curObj = statObj.ar[i];
    if (curObj) curObj.checkStatLyr();
  }
}

// monitors scrolling and position of statLyr
function checkStatLyr() {
	var yScroll = getScrollY();
	this.curTop = parseInt(this.css.top);
	this.newDestY = yScroll + this.yOff;
	if (this.newDestY!=this.curTop) {
		if (this.newDestY!=this.destY) {
			this.destY = this.newDestY;
			this.glideInit();
			this.onGlideInit();
		} 
		this.glide();
	}
}

function statGlideInit() {
	var now = new Date();
	this.a = this.destY-this.curTop;
	this.b = Math.PI/(2*this.dur);
	this.c = now.getTime();
	if (Math.abs(this.a)>winHt) {	// distance greater than window height?
		this.d = (this.a>0)? this.destY-winHt: this.destY+winHt;
		this.a = (this.a>0)? winHt : -winHt;
	} else this.d = this.curTop;
}

function statGlide() {
	var now = new Date();
	var t = now.getTime()-this.c;
	var y = Math.round(this.d+this.a*Math.sin(this.b*t));
	if ((this.a>0&&y>this.curTop)||(this.a<0&&y<this.curTop)) {
		this.shiftTo(null,y);
	}
}
