Event.observe(window, 'load', function(){
  $$('.number span ').each(function(element){
    new Detail(element);
  });
});



var Details = {
  details: [],
  zIndex: 1200,
  add: function(detail) {
    this.details.push(detail);
  },

  remove: function(element) {
    var detail = this.details.find(function(t){ return t.element == $(element); });
    if (!detail) return;

    this.details = this.details.reject(function(t) { return t==detail; });
    detail.deactivate();
    if(detail.tooldetail) detail.wrapper.remove();
    if(detail.underlay) detail.underlay.remove();
  }
}

var Detail = Class.create();
Detail.prototype = {

  initialize: function(element) {
    this.element = $(element);
    Details.remove(this.element);

this.element.style.cursor = 'pointer';
    this.state = 'off';

    Details.add(this);
    this.activate();
  },

  activate: function() {
  	this.eventHide = this.hideDetail.safeBind(this);
    this.eventSwitch = this.switchDetail.safeBind(this);

    this.element.observe('click', this.eventSwitch);



  },

  deactivate: function() {
    this.element.stopObserving('click', this.eventSwitch);
     //if(!this.active) return;
    //Event.stopObserving(document, "mouseup", this.eventMouseUp);
  },

  switchDetail: function(event){
  	//this.eventShow = this.showDetail.safeBind(this);
    //this.eventHide = this.hideDetail.safeBind(this);
    if (this.state == 'off') {
    	this.showDetail(event);
    	this.state = 'on';
    } else {
    	this.hideDetail(event);
    	this.state = 'off';
    }
  },

  showDetail: function(event){

  	this.state = 'on';
    this.element.parentNode.previous().setStyle({
  display: 'block'
});
  },

  hideDetail: function(event){
    this.element.parentNode.previous().setStyle({
  display: 'none'
});
  }

}

/* fix for $A is not defined on Firefox */
Function.prototype.safeBind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
	if (typeof $A == 'function')
    return __method.apply(object, args.concat($A(arguments)));
  }
}
