function Chaser (name, rate, time, topOffset, leftOffset)
{
   var node= document.createElement("div");
   node.style.position = "absolute";
   node.style.left= leftOffset +"px";
   node.style.top= "5px";
   node.style.width = "0px";
   node.style.display = "none";
   document.body.appendChild(node);
   this.div = node;
   this.div.innerHTML = "";
   this.topMargin = topOffset;
   this.callRate = rate;
   this.slideTime = time;
   this.leftOffset = leftOffset;
   this.maxDiff = document.body.clientHeight;
   this.timer = null;

   this.currentY=80;
   this.isIE = (navigator.appVersion.indexOf("MSIE") != -1)?  true: false;

   this.leftMarginMin = 0;
   this.topMarginMin = 0;
   this.rightMarginMin = 0;
   this.bottomMarginMin	= 0;
   var me = this;
   this.mainProxy = function () {me.main()}
}

// Main loop. Updates targetY, and decides whether to start
// the animation over again, continue an existing animation,
// or do nothing at all.
Chaser.prototype.main = function( )
{
	var ctxheight=0;
	var ctxwidth=0;
	var scrollTop=0;
	var scrollBottom=0;
	if (this.isIE)  {
   		ctxheight = document.body.clientHeight;
   		ctxwidth = document.body.scrollWidth;
		scrollTop = document.body.scrollTop;
		if (scrollTop == 0) {
			scrollTop = document.documentElement.scrollTop;	
		}
		//scrollBottom = document.body.scrollTop+document.body.scrollHeight;
		scrollBottom = document.getElementsByTagName("body")[0].offsetHeight;//replaced by pp 310808
	}
	else {
   		ctxheight = window.innerHeight;
   		ctxwidth = window.innerWidth;
		scrollTop =  window.pageYOffset;
		//scrollBottom = window.outerHeight; //window.outerHeight;
		scrollBottom = document.getElementsByTagName("body")[0].offsetHeight;//replaced by pp 310808
	}

	//this.currentY   = this.div.style.pixelTop;

	this.currentY = parseInt(this.div.style.top);
	var width = parseInt(this.div.style.width);
	var bottom 	= this.currentY + this.div.offsetHeight;


  	var left = (this.leftOffset<0 )? ctxwidth+this.leftOffset : this.leftOffset
	// check left
	if( left < this.leftMarginMin )
		left = this.leftMarginMin;
	// check right
	else if( left > ctxwidth - width - this.rightMarginMin) {
		//alert( "left set by right margin: " +left + (ctxwidth - (right-left) - this.rightMarginMin));
		left = ctxwidth - (right-left) - this.rightMarginMin;
	}
  	this.div.style.left = left+"px";
   	this.div.style.zIndex="100";

	var newTargetY   = scrollTop + this.topMargin;
	// check top
	if( newTargetY < this.topMarginMin )
		newTargetY = this.topMarginMin;
	// check bottom
	else if( newTargetY > scrollBottom - this.div.offsetHeight - this.bottomMarginMin )
   		newTargetY = scrollBottom - this.div.offsetHeight - this.bottomMarginMin;

	//STFramework.trace("Chaser","(rect.bottom-rect.top)",(rect.bottom-rect.top) ,"this.bottomMarginMin",this.bottomMarginMin);
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			this.slideInit();
		}
		this.slide();
	}
}

// Initializes the slide animation.
Chaser.prototype.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;
   }
}

// Moves the oChaser one frame.
Chaser.prototype.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));
          //this.div.style.pixelTop = newY;

   if ((this.A > 0 && newY > this.currentY) || (this.A < 0 && newY < this.currentY)) {
   	this.div.style.top = newY+"px";
   	this.currentY=newY;
   }

}


Chaser.prototype.setMargin = function(left,top,right,bottom)
{
   this.leftMarginMin 		= left;
   this.topMarginMin 		= top;
   this.rightMarginMin 	= right;
   this.bottomMarginMin = bottom;
}

Chaser.prototype.setText = function(text)
{
   this.div.innerHTML = text;
}

Chaser.prototype.getText = function()
{
   return this.div.innerHTML;
}

Chaser.prototype.start = function()
{
   this.div.style.display="block";
   clearInterval(this.timer);
   this.timer = setInterval(this.mainProxy, this.callRate);
}

Chaser.prototype.stop = function()
{
   clearInterval(this.timer);
   this.div.style.display="none";
}

