if (window.ActiveXObject) {
  try {
    document.execCommand("BackgroundImageCache", false, true);
  } catch(err) {}
}

function $(id) {
  return document.getElementById(id);
}

function getPageOffsetLeft(el) {

  var x;

  // Return the y coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the y coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function addWindowEvent(fn, evt) {
  if (typeof(window["on" + evt]) == "function") {
    var oldfn = window["on" + evt];
    window["on" + evt] = function() {
      oldfn();
      fn();
    }
  }
  else {
    window["on" + evt] = function() { fn(); };
  }
}

function addLoadEvent(fn) {
  if (typeof(window.onload) == "function") {
    var oldfn = window.onload;
    window.onload = function() {
      oldfn();
      fn();
    }
  }
  else {
    window.onload = function() { fn(); };
  }
}

function SizeWatcher() {
  this.oldw = -1; this.oldh = -1
  this.el = null;
  this.tmrId = null;
  
  this.init = function() {
    this.el = document.createElement("div");
    document.body.appendChild(this.el);
    this.el.style.position = "absolute";
    this.el.style.visibility = "hidden";
    this.el.style.fontSize = "1em";
    this.el.innerHTML = "Test";
    
    this.tmrId = setInterval( function() {
    if (this.el.offsetWidth == this.oldw && this.el.offsetHeight == this.oldh) { return; }
    this.oldw = this.el.offsetWidth;
    this.oldh = this.el.offsetHeight;
    if (window.onresize && typeof(window.onresize) == "function") {
      window.onresize();
    }
  }, 100);
  }
  
  this.callback = function() {
    if (this.el.scrollWidth == this.oldw && this.el.scrollHeight == this.oldh) { return; }
    this.oldw = this.el.scrollWidth;
    this.oldh = this.el.scrollHeight;
    if (window.onresize && typeof(window.onresize) == "function") {
      window.onresize();
    }
  }
  
  addLoadEvent(this.init);
}

var watch = new SizeWatcher();
