function getScrollTop() {
 return (document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop;
}

function getY(elem) {
 if(elem != null) {
  if(elem.style.position == 'absolute') return elem.offsetTop;
  else return elem.offsetTop + getY(elem.offsetParent);
 } else return 0;
}

function setY(elem, y) { elem.style.top = y + "px"; }

function ScrollGliss(elemId, noScrollTime, glissIntervalTime, dyByStep, minY, finalDy) {
 this.noScrollTime = noScrollTime;
 this.glissIntervalTime = glissIntervalTime;
 this.dyByStep = dyByStep;
 this.glissElem = document.getElementById(elemId);
 this.minY = minY;
 this.finalDy = finalDy;

 this.onScrollTimer = null;
 this.glissInterval = null;

 this.onScrollFun = function() {
  clearTimeout(this.onScrollTimer);
  var localThis = this;
  this.onScrollTimer = window.setTimeout(function() { localThis.startGliss() }, this.noScrollTime);
 }

 this.startGliss = function() {
  clearInterval(this.glissInterval);
  var localThis = this;
  this.glissInterval = window.setInterval(function() { localThis.gliss(); }, this.glissIntervalTime);
 }

 this.gliss = function() {
  var scrollTop = getScrollTop();
  if(scrollTop < this.minY) scrollTop = this.minY;
  var y = getY(this.glissElem) - this.finalDy;
  var step = (Math.abs(scrollTop - y) > 2000)?this.dyByStep*this.dyByStep:this.dyByStep;
  if(scrollTop > y) {
   y += step;
   if(y > scrollTop) y = scrollTop;
  } else {
   y -= step;
   if(y < scrollTop) y = scrollTop;
  }
  setY(this.glissElem, y + this.finalDy);
  if(y == scrollTop) clearInterval(this.glissInterval);
 }

 var localThis = this;
 window.onscroll = function() { localThis.onScrollFun() };
}
