window.setTimeout("initBnr()",300);

function initBnr() {
	var statBnr = new Glider("glideBnr",0,0,null,null,0,-1);
	statBnr.show();
}

myObj.holder = {}; 
// constructor
function myObj(id,x,y,w,h) {
  var el = myObj.getElemRef(id);
  if (!el) return;  this.id = id; 
  myObj.holder[this.id] = this; this.animString = "myObj.holder." + this.id;
  var px = window.opera? 0: "px";
	this.x = x || 0;	if (x) el.style.left = this.x + px;
	this.y = y || 0;	if (y) el.style.top = this.y + px;
	this.w = w || el.offsetWidth || 0;	this.h = h || el.offsetHeight || 0;
	// if w/h passed, set style width/height
	if (w) el.style.width = w + px; if (h) el.style.height = h + px;
}

myObj.getElemRef = function(id) { 
  var el = document.getElementById? document.getElementById(id): null;
  return el;
} 

myObj.getInstance = function(id) {
  var obj = myObj.holder[id];
  if (!obj) obj = new myObj(id);
  else if (!obj.el) obj.el = myObj.getElemRef(id);
  return obj;
}

myObj.prototype.shiftTo = function(x,y) {
  var el = this.el? this.el: myObj.getElemRef(this.id)? myObj.getElemRef(this.id): null;
  if (el) {
    if (x != null) el.style.left = (this.x = x) + "px";
    if (y != null) el.style.top = (this.y = y) + "px";
  }
}

myObj.prototype.shiftBy = function(x,y) { this.shiftTo(this.x+x, this.y+y); }

myObj.prototype.show = function() { 
  var el = this.el? this.el: myObj.getElemRef(this.id)? myObj.getElemRef(this.id): null;
  if (el) el.style.visibility = "visible"; 
}
myObj.prototype.hide = function() { 
  var el = this.el? this.el: myObj.getElemRef(this.id)? myObj.getElemRef(this.id): null;
  if (el) el.style.visibility = "hidden"; 
}


var dw_Bezier = {
  B1: function (t) { return t*t*t },
  B2: function (t) { return 3*t*t*(1-t) },
  B3: function (t) { return 3*t*(1-t)*(1-t) },
  B4: function (t) { return (1-t)*(1-t)*(1-t) },
  // returns current value based on percentage of time passed
  getValue: function (percent,startVal,endVal,c1,c2) {
    return endVal * this.B1(percent) + c2 * this.B2(percent) + c1 * this.B3(percent) + startVal * this.B4(percent);
  }
}

dw_Animation = {
  instances: [],
  add: function(fp) {
    this.instances[this.instances.length] = fp;
  	if (this.instances.length == 1) this.timerID = window.setInterval("dw_Animation.control()", 10);
  },
  
  remove: function(fp) {
    for (var i = 0; this.instances[i]; i++) {
  		if (fp == this.instances[i]) {
  			this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
  			break;
  		}
  	}
  	if (this.instances.length == 0) {
  		window.clearInterval(this.timerID);	this.timerID = null;
  	}
  },
  
  control: function() {
    for (var i = 0; this.instances[i]; i++) {
  		if (typeof this.instances[i] == "function" ) this.instances[i]();
      else eval(this.instances[i]);
    }
  }
}

Glider.holder = [];
function Glider(id,x,y,w,h,d,ac) {
	this.glideDur = d || 1000; this.origX = x; this.origY = y; this.ac = -ac || 0;
	this.baseObj = myObj;
	this.baseObj(id,x,y,w,h);
  Glider.holder[Glider.holder.length] = this;
  if (!Glider.winHt) Glider.winHt = getWinHeight();
}
Glider.prototype = new myObj;
Glider.prototype.onGlideInit = function () {}

Glider.prototype.checkGlider = function() {
	var destY = getScrollY() + this.origY;
	if (destY != this.y) {
		if (destY != this.dy) {
			this.dy = destY;
			this.glideInit();
      this.onGlideInit();
		} 
		this.glide();
	}
}

Glider.prototype.glideInit = function() {
	this.gt = new Date().getTime();
	var distY = this.dy - this.y;
	if ( Math.abs(distY) > Glider.winHt ) {	// distance greater than window height?
		this.gsy = (distY > 0)? this.dy - Glider.winHt: this.dy + Glider.winHt;
	} else this.gsy = this.y;
  this.g_yc1 = this.gsy + ( (1+this.ac) * (this.dy - this.gsy)/3 );
	this.g_yc2 = this.gsy + ( (2+this.ac) * (this.dy - this.gsy)/3 );
}

Glider.prototype.glide = function() {
	var elapsed = new Date().getTime() - this.gt;
  if (elapsed < this.glideDur) {
    var y = dw_Bezier.getValue( elapsed/this.glideDur, this.gsy, this.dy, this.g_yc1, this.g_yc2 );
    this.shiftTo(null,y);
  } else this.shiftTo(null,this.dy);
}

Glider.control = function() {
  for (var i=0; Glider.holder[i]; i++) {
    var curObj = Glider.holder[i];
    if (curObj) curObj.checkGlider();
  }
}

dw_Animation.add(Glider.control);


function getWinHeight() {
	var winHt = 0;
	if (window.innerHeight) winHt = window.innerHeight-18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winHt = document.body.clientHeight;
	return winHt;
}	


function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}


if (window.addEventListener)
  window.addEventListener("resize", function(){ Glider.winHt = getWinHeight(); }, "false");
else if (window.attachEvent)
  window.attachEvent("onresize", function(){ Glider.winHt = getWinHeight(); } );


