/*
 * Compatibility layer
 */

/*
 * myArrayPush
 *
 * Thanks to Alexander Vincent for the idea http://www.samspublishing.com/articles/article.asp?p=30111&seqNum=3
 */

function myArrayPush()
{
  for (var i = 0; i < arguments.length; i++) {
    this[this.length] = arguments[i]
  }
  return this.length
}

if (typeof Array.prototype.push == "undefined") {
  Array.prototype.push = myArrayPush
}

/*
 * setupPopups
 * Sets up links with a rel="popup|target" so they open in a new window
 *
 * Thanks to Michael Rainey for the idea http://www.sitepoint.com/print/xhtml-strict-popups
 */
function setupPopups() {
  var anchors = document.getElementsByTagName('a');
  for (var i = 0; i < anchors.length; i++) {
    var rel = anchors[i].getAttribute('rel');
    if (rel && rel.indexOf('popup|') == 0) {
      var href = anchors[i].getAttribute('href');
      var params = rel.split('|');
      anchors[i].setAttribute('href', "javascript:var w = window.open('" + href + "', '" + params[1] + "');");
    }
  }
}

function dbg(o) {
    var s = "";
    var i = 0;
    for (var p in o) {
        s += p + ": " + o[p] + "\n";
        if (++i % 10 == 0) {
            alert(s);
            s = "";
        }
    }
    alert(s);
}

function htmlEvent()
{
  this.eventList = new Array();
  this.registerEvent = registerEvent;
  this.playEvent = playEvent;

}

function registerEvent(event, func)
{
  if (this.eventList[event]) {
    this.eventList[event].push(func);
  } else {
    this.eventList[event] = new Array();
    this.eventList[event].push(func);
  }
}

function playEvent(event)
{
  if (this.eventList[event]) {
    for (var i = 0; i < this.eventList[event].length; i++) {
      this.eventList[event][i]();
    }
  }
}

var windowEvent = new htmlEvent();

function windowOnload() {
  windowEvent.playEvent('onload');
}

windowEvent.registerEvent('onload', setupPopups);
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	windowEvent.registerEvent('onload', alphaBackgrounds);
}
window.onload = windowOnload;

