//window.offscreenBuffering=true;

function FlyingMenu(id, inertia, k, yPad, yMin) {

	this.inertia = inertia;
	this.k = k;
	this.yPad = yPad;
	this.yMin = yMin;

	this.div = document.getElementById ? 
		document.getElementById(id) : document.all[id];

	this.yPos = 0;
	this.dy = 0;

	this.dest = 0;
	this.lastYOffset = 0;
	this.scrolled = false;

    // global reference to this object
    this.gRef = 'FlyingMenu_' + id
    eval(this.gRef+'=this')
  
    if (yPad < yMin) yPad = yMin;
    this.div.style.top = yPad + 'px';

    
    setInterval(this.gRef + '.checkScroll()', 100);

}



FlyingMenu.prototype.getPageYOffset = function() {

	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;
}


FlyingMenu.prototype.slide = function() {
    var y = this.dest - this.yPos;
	this.dy = this.dy * this.inertia + y * this.k;
    this.yPos += this.dy; 
    this.div.style.top = Math.round(this.yPos) + 'px';
    if (Math.round(this.dy) != 0) {
    	setTimeout(this.gRef + '.slide()', 100);
    }
}



FlyingMenu.prototype.checkScroll = function() {
	var y = this.getPageYOffset();
	if (y != this.lastYOffset) {
		this.lastYOffset = y;
		this.scrolled = true;
	}
	else if (this.scrolled) {
		this.scrolled = false;
		this.dest = y + this.yPad;
		if (this.dest < this.yMin) this.dest = this.yMin;
		this.slide();
	}
}
/*

// returns height of window
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;
}	

// onresize, get window height
if (window.addEventListener)
  window.addEventListener("resize", function(){ Glider.winHt = getWinHeight(); }, "false");
else if (window.attachEvent)
  window.attachEvent("onresize", function(){ Glider.winHt = getWinHeight(); } );
*/