//    SCROLL begin
function getparentheight(node,n) {

  y=n+node.offsetTop;

  if (node.offsetParent){

    par=node.offsetParent;

    getparentheight(par,y);

  }

  return y;

}



function scroll(){

  var cnt=document.getElementById("content");

  var sb=document.getElementById("scrollbar");

  var sc=sb.firstChild.nextSibling?sb.firstChild.nextSibling:sb.firstChild;

  var th=parseInt(cnt.offsetHeight);

  var h=parseInt(sc.offsetHeight);

  var hh=Math.round(h/2);

  var max=parseInt(sb.offsetHeight);

  var min=0;

  var move=false;

  var lept=(th-max)/(max-h);

  var m=0;

  y=getparentheight(sb,0);

  

  window.onmousewheel=document.onmousewheel=function(e){

    if (th>max){

      if (e==undefined) e=event;

      var delta = 0;

      if (e.wheelDelta) {

        delta = e.wheelDelta/120;

        //if (window.opera) delta = -delta;

      } else if (e.detail) {

        delta = -e.detail/3;

      }

      if (delta){

          if (delta < 0) {

            m+=20;

            if (m>=max-h) m=max-h;

          }      

          else {

            m-=20;

            if (min+h>=m) m=0;

          }

        sc.style.top=m+"px";

        cnt.style.top=-Math.round((m)*lept)+"px";

      }

      if (e.preventDefault)

      e.preventDefault();

    	e.returnValue = false;

    }

  }

  

  if (window.addEventListener) window.addEventListener('DOMMouseScroll', window.onmousewheel, false);

  

  sc.onmousedown=function(){

    move=true;

    return false;

  }

  

  document.onmousemove=function(e){

    if (move && th>max){

      if (e==undefined) e=event;

      m=parseInt(e.clientY)-y;

      if (min+hh<=m && m<=max-hh){

        sc.style.top=m-hh+"px";

        cnt.style.top=-Math.round((m-hh)*lept)+"px";

        //if (document.selection) document.selection.empty();

        //else 

        if (window.getSelection) window.getSelection().removeAllRanges();

      }

    }

    return false;

  }

  

  document.body.onselectstart=function(){

    return false;

  };



  

  sb.onclick=function(e){

    if (th>max){

      if (e==undefined) e=event;

      m=parseInt(e.clientY)-y;

      if (min+h>=m) m=0+hh;

      else if (m>=max-h) m=max-h+hh;

      sc.style.top=m-hh+"px";

      cnt.style.top=-Math.round((m-hh)*lept)+"px";

    }

    return false;

  }

  

  document.onmouseup=function(){

    move=false;

    return false;  

  }

}
//    SCROLL end




//    ONLOAD begin
window.onload=function(){
  scroll();
  //if (document.getElementById('gmap')) load();

}
//    ONLOAD end
