if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(val) {
    for (var i=0; i<this.length; i++)
      if (this[i] == val) {
        return i;
      }
    return -1;
  };
}

var Challenges = new Object;
Challenges.Colors = ["#383850", "#304050"];
Challenges.hoverColors = ["#585870", "#506070"];
Challenges.init = function() {
  this.UpdateLists();
}
Challenges.UpdateLists = function() {
  var tab, tabs, cells, a, col;
  tabs = document.getElementsByTagName("table");
  for (var i=0; i<tabs.length; i++) {
    tab = tabs[i];
    if (tab.className.toLowerCase() != "cl_challs") {
      continue;
    }
    col = this.hoverColors[((j=this.Colors.indexOf(tab.style.backgroundColor.toUpperCase()))==-1) ? 0 : j];
    for (var j=0; j<tab.rows.length; j++) {
      tab.rows[j].onmouseover = Challenges.RowOver;
      tab.rows[j].onmouseout  = Challenges.RowOut;
      tab.rows[j].hoverColor  = col;
      cells = tab.rows[j].getElementsByTagName("td");
      a = cells[cells.length-2].getElementsByTagName("a")[0];
      a.onmouseover = Challenges.StatsOver;
      a.onmouseout  = Challenges.StatsOut;
    }
  }
}
Challenges.RowOver = function() {
  this.style.backgroundColor = this.hoverColor;
}
Challenges.RowOut = function() {
  this.style.backgroundColor = "";
}
Challenges.StatsOver = function() {
  this.style.backgroundColor = this.style.color;
  this.style.color = "#000000";
}
Challenges.StatsOut = function() {
  this.style.color = this.style.backgroundColor;
  this.style.backgroundColor = "";
}
/* Event Registrar, Simon Willison */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
    window.onload = func;
  else {
    window.onload = function() { oldonload(); func(); }
  }
}
addLoadEvent(function() { Challenges.init(); });
