var intval=0;
function scroll(step) {
    window.clearInterval(intval);
    cypos = getCurrentYPos();
	cyhei = getTotalHeight();
	if (step=="bas") {
	stepsize = parseInt((cypos+document.documentElement.clientHeight-cyhei)/10);
    intval=window.setInterval('scrollWindowBottom('+stepsize+')',10);
	}
	if (step=="down") {
	stepsize = getCurrentYPos()+200;
    intval=window.setInterval('scrollWindowDown('+stepsize+')',10);
	}
	if (step=="up") {
	stepsize = getCurrentYPos()-200;
    intval=window.setInterval('scrollWindowUp('+stepsize+')',10);
	}
	if (!step) {
	stepsize = parseInt((0-cypos)/10);
	intval=window.setInterval('scrollWindowTop('+stepsize+')',10);
	}
  }
  
  function scrollWindowDown(scramount) {
	var dest=scramount;
    wascypos = getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + 30);
    iscypos = getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      window.scrollTo(0,dest);
      window.clearInterval(intval);
    }
  }
  
  function scrollWindowUp(scramount) {
	var dest=scramount;
    wascypos = getCurrentYPos();
    isAbove = (wascypos > dest);
    window.scrollTo(0,wascypos - 30);
    iscypos = getCurrentYPos();
    isAboveNow = (iscypos > dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      window.scrollTo(0,dest);
      window.clearInterval(intval);
    }
  }
 
  function scrollWindowTop(scramount) {
  var dest=0;
    wascypos = getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      window.scrollTo(0,dest);
      window.clearInterval(intval);
    }
  }
  
  function scrollWindowBottom(scramount) {
  var dest=getTotalHeight();
    wascypos = getCurrentYPos();
	isAbove = (wascypos > dest);
    window.scrollTo(0,wascypos - scramount);
    iscypos = getCurrentYPos();
    isAboveNow = (iscypos > dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      window.scrollTo(0,dest);
      window.clearInterval(intval);
    }
  }
 
   function getCurrentYPos() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  }
  
function getTotalHeight() {
  // firefox is ok
  var height = document.documentElement.scrollHeight;
  // now IE 7 + Opera with "min window"
  if(document.documentElement.clientHeight > height ) {
    height  = document.documentElement.clientHeight;
  }
  // last for safari
  if(document.body.scrollHeight > height) {
    height = document.body.scrollHeight;
  }
  return height;
}