// Copyright 2001 eSolutions Ltd.
// Obtain written permission before using any part of this code from info@esol-group.com.

function classXChaser(id,top,dur){
  var ie=document.all
	this.chasetop=top?top:0
	this.duration=dur?dur:800
	this.chase=true
	this.intervalID=null
	this.el=document[ie?'all':'layers'][id]
  this.hscroll = 0
	this.main=function(){
    if(this.hscroll)this.el.style.pixelLeft = document.body.scrollLeft + this.hscroll
		this.currentY = ie ? this.el.style.pixelTop : this.el.top
		this.scrollTop = this.chase?(ie ? document.body.scrollTop : window.pageYOffset):0
		var newTargetY = this.scrollTop + this.chasetop
		if ( this.currentY != newTargetY ) {
			if ( newTargetY != this.targetY ) {this.targetY=newTargetY; this.slideInit()}
			this.slide()
		}
		else {clearInterval(this.intervalID); this.intervalID=null}
	}
	this.slideInit = function(){
		var now	= new Date(), h=ie?document.body.clientHeight:window.innerHeight
		this.A = this.targetY - this.currentY
		this.B = Math.PI / ( 2 * this.duration )
		this.C = now.getTime()
		if (Math.abs(this.A) > h) {
			this.D = this.A > 0 ? this.targetY - h : this.targetY + h
			this.A = this.A > 0 ? h : -h
		} else this.D = this.currentY
	}
	this.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 ( ie )this.el.style.pixelTop = newY
				else this.el.top = newY
		}
	}
	this.onscroll = function(){if(this.intervalID==null){ this.intervalID=setInterval(id+'.main()',10);}}
}