window.offscreenBuffering=true;

function StayAtNull(id, init, k, yPad, yMin) {

	this.init = init;
	this.k = k;
	this.yPad = yPad;
	this.yMin = yMin;

	this.yPos = 0;
	this.dy = 0;
	
	this.dest = 0;
	this.lastYOffset = 0;
	this.scrolled = false;

    // global reference to this object
    this.gRef = 'StayAtNull_' + id
    eval(this.gRef+'=this')
    
    if (yPad < yMin) yPad = yMin;
    setInterval(this.gRef + '.checkScroll()', 250);
}

StayAtNull.prototype.getPageYOffset = function() {
	if (window.pageYOffset) {
		return window.pageYOffset;
	}
	if (document.body && document.body.scrollTop) {
		return document.body.scrollTop;
	}
	if (document.documentElement && document.documentElement.scrollTop) {
		return document.documentElement.scrollTop;
	}
	return 0;
}

StayAtNull.prototype.slide = function() {
    var y = this.dest - this.yPos;
	this.dy = this.dy * this.init + y * this.k;
    this.yPos += this.dy; 
     document.getElementById('nav').style.top = Math.round(this.yPos) + 'px';
    if (Math.round(this.dy) != 0) {
    	setTimeout(this.gRef + '.slide()', 100);
      }
    if(this.yPos < 0){
    this.yPos = 0;
    }
}

StayAtNull.prototype.checkScroll = function() {
	var y = this.getPageYOffset() + document.documentElement.clientHeight - 80;
	
	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();
	}
}
                                                                                                                                        