//<script language="JavaScript">
window.browser = new _Browser();

function CreateBrowser() {
  return new _Browser();
}

function _Browser() {
  // public:
  this.version        = navigator.appVersion;
	this.dom            = document.getElementById ? 1:0;
	this.ie10           = (this.version.indexOf("MSIE 10") >-1 && this.dom)? 1:0;
	this.ie9            = (this.version.indexOf("MSIE 9") >-1 && this.dom)? 1:0;
	this.ie8            = (this.version.indexOf("MSIE 8") >-1 && this.dom)? 1:0;
	this.ie7            = (this.version.indexOf("MSIE 7") >-1 && this.dom)? 1:0;
	this.ie6            = (this.version.indexOf("MSIE 6") >-1 && this.dom)? 1:0;
	this.ie5            = (this.version.indexOf("MSIE 5") >-1 && this.dom)? 1:0;
	this.ie4            = (document.all && !this.dom) ? 1:0;
	this.ie             = (this.ie6 || this.ie5 || this.ie4);
	this.ns5            = (this.dom && parseInt(this.version) >= 5) ? 1:0;
	this.ns4            = (document.layers && !this.dom) ? 1:0;
	this.ns             =  (this.ns5 || this.ns4);
	
	this.dhtml          = (this.ie10 || this.ie9 || this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5);
	
	this.getOuterLeft   = _Browser_getOuterLeft;
	this.getOuterTop    = _Browser_getOuterTop;
	this.getOuterWidth  = _Browser_getOuterWidth;
	this.getOuterHeight = _Browser_getOuterHeight;
	
	this.getInnerLeft   = _Browser_getInnerLeft;
	this.getInnerTop    = _Browser_getInnerTop;
	this.getInnerWidth  = _Browser_getInnerWidth;
	this.getInnerHeight = _Browser_getInnerHeight;
	
	this.getViewLeft    = _Browser_getViewLeft;
	this.getViewTop     = _Browser_getViewTop;
	this.getViewWidth   = _Browser_getViewWidth;
	this.getViewHeight  = _Browser_getViewHeight;
	
	this.captureScrollEvents  = _Browser_captureScrollEvents;
	
	// private:
	this._watchForScroll      = _Browser__watchForScroll;
	
	return this;
}

function _Browser_getOuterWidth() {
  if (this.ns) {
    if (window.outerWidth != null) {
      return window.outerWidth + 10;
    }
  } else if (this.ie) {
    return this.getInnerWidth() + 10;
  }
  return null;
}

function _Browser_getOuterHeight() {
  if (this.ns) {
    if (window.outerHeight != null) {
      return window.outerHeight + 50;
    }
  } else if (this.ie) {
    return this.getInnerHeight() + 50;
  }
  return null;
}

function _Browser_getOuterLeft() {
  if (this.ns) {
    if (window.screenX != null) {
      return window.screenX;
    }
  } else if (this.ie) {
    if (window.screenLeft != null) {
      return window.screenLeft;
    }
  }
  return null;
}

function _Browser_getOuterTop() {
  if (this.ns) {
    if (window.screenY != null) {
      return window.screenY;
    }
  } else if (this.ie) {
    if (window.screenTop != null) {
      return window.screenTop;
    }
  }
  return null;
}

function _Browser_getInnerWidth() {
  if (this.ns) {
    if (window.innerWidth != null) {
      return window.innerWidth;
    } else {
      return null;
    }
  } else {
    if (document.body != null) {
      return document.body.scrollWidth;
    } else {
      return null;
    }
  }
}

function _Browser_getInnerHeight() {
  if (this.ns) {
    if (window.innerHeight != null) {
      return window.innerHeight;
    } else {
      return null;
    }
  } else {
    if (document.body != null) {
      return document.body.scrollHeight;
    } else {
      return null;
    }
  }
}

function _Browser_getInnerLeft() {
  return 0;
}

function _Browser_getInnerTop() {
  return 0;
}


function _Browser_getViewWidth() {
  if (this.ns) {
    if (window.innerWidth != null) {
      var width = window.innerWidth;
      if (window.scrollbars.visible) {
        width -= 16;
      }
      return width;
    } else {
      return null;
    }
  } else {
    if (document.body != null) {
      return document.body.scrollWidth;
    } else {
      return null;
    }
  }
}

function _Browser_getViewHeight() {
  if (this.ns) {
    if (window.innerHeight != null) {
      var height = window.innerHeight;
      if (window.scrollbars.visible) {
        height -= 16;
      }
      return height;
    } else {
      return null;
    }
  } else {
    if (document.body != null) {
      return document.body.scrollHeight;
    } else {
      return null;
    }
  }
}

function _Browser_getViewLeft() {
  return (this.ns) ? window.pageXOffset : document.body.scrollLeft;
}

function _Browser_getViewTop() {
  return (this.ns) ? window.pageYOffset : document.body.scrollTop;
}


/////////////// Window scroll watcher //////////////
function _Browser_captureScrollEvents() {
  this._oldViewLeft = this.getViewLeft();
  this._oldViewTop = this.getViewTop();
  setInterval("window.browser._watchForScroll()", 100);
}

function _Browser__watchForScroll(timeout) {
  if (this._oldViewLeft != this.getViewLeft()
   || this._oldViewTop != this.getViewTop()) {
    this._oldViewLeft = this.getViewLeft();
    this._oldViewTop  = this.getViewTop();
    if (typeof(this.onscroll) == "function") {
      this.onscroll();
    } else if (typeof(this.onScroll) == "function") {
      this.onScroll();
    }
  }
}
