function get_win_width(){
  if(typeof(document.body.clientWidth) != "undefined"){
    return document.body.clientWidth;
  }else if(typeof(document.innerWidth) != "undefined"){
    return document.innerWidth;
  }
  throw "get_win_width()::undefined";
}


function get_win_height(){
  if(typeof(document.body.clientHeight) != "undefined"){
    return document.body.clientHeight;
  }else if(typeof(document.innerHeight) != "undefined"){
    return document.innerHeight;
  }
  throw "get_win_height()::undefined";
}

function scroll_x(delta){
  if(typeof(document.body.scrollLeft) != "undefined"){
    document.body.scrollLeft += delta;
  }else if(typeof(window.pageXOffset) != "undefined"){
    window.pageXOffset += delta;
  }
}

function scroll_y(delta){
  if(typeof(document.body.scrollTop) != "undefined"){
    document.body.scrollTop += delta;
  }else if(typeof(window.pageYOffset) != "undefined"){
    window.pageYOffset += delta;
  }
}

function get_scroll_x(){
  if(typeof(document.body.scrollLeft) != "undefined"){
    return document.body.scrollLeft;
  }else if(typeof(window.pageXOffset) != "undefined"){
    return window.pageXOffset;
  }
  throw "get_scroll_x()::undefined";
}

function get_scroll_y(){
  if(typeof(document.body.scrollTop) != "undefined"){
    return document.body.scrollTop;
  }else if(typeof(window.pageYOffset) != "undefined"){
    return window.pageYOffset;
  }
  throw "get_scroll_y()::undefined";
}


function patch_ff_onscroll(){
  if(navigator.userAgent.indexOf( 'Firefox' ) != -1){
    if(typeof(HTMLElement) != "undefined"){
      HTMLElement.prototype.__defineGetter__("onscroll", function () {
        return this._onscroll;
      });
      HTMLElement.prototype.__defineSetter__("onscroll", function (handler) {
        this._onscroll = handler;
        if(this._onscroll_timer_id)
          clearInterval(this._onscroll_timer_id);
        var _handler = handler, old_x = get_scroll_x(), old_y = get_scroll_y();
        this._onscroll_timer_id = setInterval(function(){
          var new_x = get_scroll_x();
          var new_y = get_scroll_y();
          if(old_x != new_x || old_y != new_y){
            _handler();
          }
          old_x = new_x;
          old_y = new_y;
        }, 100);
      });
    }
  }
}
patch_ff_onscroll();

