function Accordian(target) {
  typeof target == "object" ? this.element = target : this.element = document.getElementById(target); if (!this.element) return false;
  this.ul = this.element.getElementsByTagName("ul")[0];
  this.tabs = this.ul.getElementsByTagName("a");
  this.w = this.getTabContent();
  this.bind();
}

Accordian.prototype.getTabContent = function() {
  w= new Array();
  this.divs = this.element.getElementsByTagName("div");
  for(var i = 0; i < this.divs.length; i++) {
        if (/w/i.test(this.divs[i].className)) {
        w.push(this.divs[i]);
    }
  }
  return w;
}

Accordian.prototype.bind = function() {
  var o = this;
  for(var i = 0; i < this.tabs.length; i++) {
    this.tabs[i].onclick = function() { o.open(this); return false; };
    var a = this.tabs[i].getElementsByTagName("a")[0];
    if (a) a.onclick = function() { return false; };
  }
}

Accordian.prototype.open = function(caller) {
  for(var i = 0; i < this.tabs.length; i++) {
    var tab = this.tabs[i];
    if (tab == caller) {
      this.collapse();
      tab.className = "selected"
      this.w[i].style.display = "block";
    }
  }
}

Accordian.prototype.collapse = function() {
  for(var i = 0; i < this.tabs.length; i++) {
    this.tabs[i].className = "";
    this.w[i].style.display = "none";
  }
}
