String.prototype.trim = function() {
  return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
};
function addClassName (elem, className) {
  if(elem) {
    removeClassName(elem, className);
    elem.className = (elem.className + " " + className).trim();
  }
}
function removeClassName (elem, className) {
  if(elem) {
    elem.className = (elem.className.replace(className, "")).trim();
  }
}
function hide(el) {
  if(typeof(el) === "undefined") { return; }
	el.style.display = "none";
}
function show(el) {
  if(typeof(el) === "undefined") { return; }
	el.style.display = "";
}
function delegate(that, thatMethod) {
  return function() { return thatMethod.call(that); };
}
function toggle(id) {
	var el = document.getElementById(id);
	if(el.style.display === "none") {
		(new IShow(id)).run();
	}	else {
		(new IHide(id)).run();
	}
}
function IHide(id) {
  this.id=id;
  this.el = document.getElementById(this.id);
  this._height = this.el.clientHeight;
  this.duration = 500;

  this.run = function() {
    this.startTime = (new Date()).getTime();
    this.el.style.height = this._height;
    this.el.style.overflow = "hidden";

    window.setTimeout(delegate(this, this.next), 10);
  };

  this.next = function() {
    var t = (new Date()).getTime();
    var n = t - this.startTime;
    var p = n / this.duration;
    if(n > this.duration) {
      this.el.style.height = "";
      this.el.style.overflow = "";
      hide(this.el);
      return;
    }
    this.el.style.height = (this._height * (1.0-p)) + "px";
    window.setTimeout(delegate(this, this.next), 10);
  };
}
function IShow(id) {
  this.id=id;
  this.el = document.getElementById(this.id);
  this.el.style.display="block";
  this.el.style.visibility = "hidden";
  this._height = this.el.clientHeight;
  this.el.style.visibility = "";
  this.duration = 500;
  this.run = function() {
    this.startTime = (new Date()).getTime();
    this.el.style.height = 0;
    this.el.style.overflow = "hidden";

    window.setTimeout(delegate(this, this.next), 10);
  };
  this.next = function() {
    var t = (new Date()).getTime();
    var n = t - this.startTime;
    var p = n / this.duration;
    if(n > this.duration) {
      this.el.style.height = "";
      this.el.style.overflow = "";
      this.el.style.visibility = "";
      this.el.style.display = "";
      show(this.el);
      return;
    }
    this.el.style.height = (this._height * p) + "px";
    window.setTimeout(delegate(this, this.next), 10);
  };
}
