
      function GetObj (name) {
        if (document.getElementById && !document.all) {
          var obj = document.getElementById (name);
        } else if (document.all) {
//          if (!document.all [name])
//            alert ('no obj ' + name);
          var obj = document.all [name];
        } else if (document.layers) {
          var obj = document.layers [name];
        }
        return obj;
      }

      function IEX (o) {
        if (o.getBoundingClientRect)
          return o.getBoundingClientRect().left;
        with (o) {
          return o.offsetParent ? IEX (offsetParent) + offsetLeft : offsetLeft;
        }
      }
      function IEY (o) {
        if (o.getBoundingClientRect)
          return o.getBoundingClientRect().top;
        with (o) {
          return offsetParent ? IEY (offsetParent) + offsetTop : offsetTop;
        }
      }

      function ObjXY (o) {
        return {
          x: IEX (o),
          y: IEY (o)
        }
      }
      function MouseXY (event, relToObj) {
        var relX = 0, relY = 0;
        if (relToObj) {
          relX = IEX (relToObj);
          relY = IEY (relToObj);
        }

        return {
          x: (event.pageX ? event.pageX : event.clientX + (document.body ? document.body.scrollLeft : document.documentElement.scrollLeft)) - relX,
          y: (event.pageY ? event.pageY : event.clientY + (document.body ? document.body.scrollTop  : document.documentElement.scrollTop )) - relY,
          toString: function () {
            return 'x: ' + this.x + ' y: ' + this.y;
          }
        }
      }

      /* scrolling save off */
      var sx = 20;
      var sy = 51;
      var tDelta = 1000 / 50;  /* ms */
      var tTotal = 1000; /* ms */

      function fadein (o) {
        var o  = GetObj (o);
        var o2 = GetObj ('scroller');
        var h = parseInt (o2.style.paddingTop);
        o2.style.paddingTop =  h > 1 ? Math.round (5 * h / 6) + 'px' : '0px';
        window.status = h;
        if (h <= 1) {
          window.clearInterval (o.pSto);
          o.pSto = 0;
        }
      }

      function scrollup (o) {
        o  = GetObj (o);
        if (o.mSto) {
          window.clearTimeout (o.mSto);
        }
        o.scrollToTop  = Math.max (0, o.scrollTop - o.clientHeight);
        o.startTime = new Date ().getTime ();
        o.endTime   = o.startTime + tTotal;
        o.startLeft = o.scrollLeft;
        o.startTop  = o.scrollTop;
        if (o.scrollTop != o.scrollToTop) {
          o.mSto = window.setTimeout (
            function () {
              o.scrollDelta2 ();
            },
            tDelta
          );
        }
      }
      function scrolldown (o) {
        o  = GetObj (o);
        if (o.mSto) {
          window.clearTimeout (o.mSto);
        }
        o.scrollToTop  = Math.min (Math.ceil (o.scrollHeight / o.clientHeight) * o.clientHeight, o.scrollTop + o.clientHeight);
        o.startTime = new Date ().getTime ();
        o.endTime   = o.startTime + tTotal;
        o.startLeft = o.scrollLeft;
        o.startTop  = o.scrollTop;
        if (o.scrollTop != o.scrollToTop) {
          o.mSto = window.setTimeout (
            function () {
              o.scrollDelta2 ();
            },
            tDelta
          );
        }
      }
      
      function makeScrollable (o) {
        if (!o)
          return false;
        if (typeof o.scrollTop == 'undefined') {
          alert (o.id + ' ' + ' no scrollTop');
          return false;
        }

        o.style.overflow = 'hidden';
        o.scrollTop  = 0;
        o.scrollLeft = 0;

        window.onunload = function () {
          setCookie ('SaveX', o.scrollLeft);
          setCookie ('SaveY', o.scrollTop);
          return true;
        }
        if (o.scrollWidth <= o.offsetWidth && o.scrollHeight <= o.offsetHeight)
          return false;

//        window.status = 'makeScrollable ' + o.scrollWidth + ' ' + o.offsetWidth;

        o.scrollLeft = getCookie ('SaveX', 0);
        o.scrollTop  = getCookie ('SaveY', 0);
        

        o.scrollDelta = function () {

          var dx = this.scrollToLeft - this.scrollLeft;
          var dy = this.scrollToTop  - this.scrollTop;

          this.scrollLeft += Math.abs (dx) <= 1 ? dx  : dx >> 1;
          this.scrollTop  += Math.abs (dy) <= 1 ? dy  : dy >> 1;

  //        window.status = this.id + ' ' + this.scrollLeft + '(' + this.scrollToLeft + ') ' + this.scrollTop + '(' + this.scrollToTop + ')';

          if (Math.abs (dx) == 0 && Math.abs (dy) == 0) {
            window.clearInterval (this.mSto);
            this.mSto = 0;
  //          window.status += ' cleared';
          }
        }

        o.scrollDelta2 = function () {
          var t = new Date ().getTime () - this.startTime;
          if (t >= tTotal) {
            this.scrollTop  = this.scrollToTop;
//            window.status = t + ' ' + this.startTop + 'px ' + this.scrollTop + 'px';
            this.mSto = 0;
            return true;
          }
          /* 0 < d < 1
            t = 0 => d = 0
            t = tTotal => d = 1
          */
          var da = t / tTotal;
//          var d = 1 - Math.pow (1 - da, 3);
          var pow = 3;
          var dpow = Math.pow (0.5, 1 - pow);
          var d = da < 0.5 ? Math.pow (da, pow) * dpow : 1 - Math.pow (1 - da, pow) * dpow;
//          window.status = (da + '').substring (0, 5) + ' ' + (d + '').substring (0, 5);
          

//          this.scrollLeft += (this.scrollToLeft - this.startLeft) * Math.sqrt (tTotal - t);
          this.scrollTop  = this.startTop + Math.round ((this.scrollToTop - this.startTop ) * d);
//          window.status = t + ' ' + this.startTop + 'px ' + this.scrollTop + 'px';

          this.mSto = window.setTimeout (
            function () {
              o.scrollDelta2 ();
            },
            tDelta
          );

          return true;
        }

        o.onmousemove = function (evt) {
          evt = evt || window.event;
          var target = evt.srcElement || evt.target;
          var mp = MouseXY (evt, this);
          var mx = mp.x; /* - border */
          var my = mp.y; /* - border */

          var ow = this.clientWidth  || this.offsetWidth; /* - 2 * border */
          var oh = this.clientHeight || this.offsetHeight; /* - 2 * border */

          var sw = this.scrollWidth; /* - 2 * border */
          var sh = this.scrollHeight; /* - 2 * border */

//          window.status = mp;

          mx = Math.max (sx, Math.min (ow - sx, mx)) - sx;
          mx = Math.floor ((sw - ow) * mx / (ow - 2 * sx));

          my = Math.max (sy, Math.min (oh - sy, my)) - sy;
          my = Math.floor ((sh - oh) * my / (oh - 2 * sy));

          this.scrollToLeft = Math.max (0, mx);
          this.scrollToTop  = Math.max (0, my);

//          window.status = mp.y + ' ' + sh + ' ' + oh + ' ' + this.scrollToTop + ' ' + (oh + this.scrollToTop);

//          window.status = o.id + ' ' + ow + ' ' + oh + ' ' + sw + ' ' + sh + ' ' + o.scrollLeft + '(' + o.scrollToLeft + ') ' + o.scrollTop + '(' + o.scrollToTop + ')';

          this.startTime = new Date ().getTime ();
          this.endTime   = this.startTime + tTotal;
          this.startLeft = this.scrollLeft;
          this.startTop  = this.scrollTop;
          if ((this.scrollTop != this.scrollToTop || this.scrollLeft != this.scrollToLeft)) {
            if (!this.mSto) {
              this.mSto = window.setInterval (
                function () {
                  o.scrollDelta ();
                },
                tDelta
              );
            }
          }
          return true;
        }
      }
      

