/* 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.
*/

// The chaser object. Since we don't anticipate having more
// than one on a page, we don't bother making this into
// a class definition. All necessary properties are set as
// properties of this object to avoid global variables.

var oChaser = {
	topMargin	: 115,
	callRate	: 10,
	targetY		: -99,
	slideTime	: 1000,
	maxDiff		: document.all ? document.body.clientHeight : window.innerHeight,
	br : getbrowser()
}

if (oChaser.br =='nn4'){oChaser.chaserDiv=document.layers.myChaser;oChaser.byStyle=false;}
if (oChaser.br =='nn6'){oChaser.chaserDiv=document.getElementById ('myChaser');oChaser.byStyle=true;}
if (oChaser.br =='IE'){oChaser.chaserDiv=document.all.myChaser;oChaser.byStyle=true;}

window.setInterval("oChaser.main()", oChaser.callRate);

oChaser.main = function() {
	this.currentY = this.byStyle ? parseInt(this.chaserDiv.style.top) : this.chaserDiv.top;
	this.scrollTop= (this.br == 'IE' ? document.body.scrollTop : window.pageYOffset);
//	alert(document.body.scrollTop+'::'+window.pageYOffset);
	var newTargetY	= this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			this.slideInit();
		}
		this.slide()
	}
}
// .slideInit(). Initializes the slide animation. Sets properties
// of the oChaser object that will represent the various paramaters
// for the sine wave function.
oChaser.slideInit = function() {
	var now	= new Date();
	this.A		= this.targetY - this.currentY;
	this.B		= Math.PI / ( 2 * this.slideTime);
	this.C		= now.getTime();
	if (Math.abs(this.A) > this.maxDiff) {
		this.D = this.A > 0 ? this.targetY - this.maxDiff : this.targetY + this.maxDiff;
		this.A = this.A > 0 ? this.maxDiff : -this.maxDiff;
	} else {
		this.D = this.currentY;
	}
}

// .slide(). Moves the oChaser one frame. Its rate decreases and
// is defined by a sine wave.
oChaser.slide = function() {
	var now	= new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round( newY );
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
		if ( this.byStyle ) {
			this.chaserDiv.style.top = newY+'px';
		} else {
			this.chaserDiv.top = newY;
		}
	}
}


// get browser type
function getbrowser(){
	if (document.layers) {
		bN = "nn4";
	} else if (document.getElementById) {
		bN = (document.all?'IE':'nn6');
	} else {
		bN = '??';
	}
	return bN
}
