var auto_suggest_enabled = true;
var dom_ready = false;
var open_dropdown = "";
var open_popup = "";
var open_editor = "";
var open_details = "";
var selected_items = [];

var registrar = {
	hooks: {},
	handlers: {},
	add_hook: function(type, o) {
    if (typeof(o) == "string") o = {element: o};
    if (this.hooks[type] == undefined) {
     this.hooks[type] = [];
    }
    this.hooks[type].push(o);
    if (this.handlers[type] != undefined) {
     for (var i=0; i < this.handlers[type].length; i++) {
       this.inform_handler(this.handlers[type][i], o);
     };
    }
	},
	add_handler: function(types, handler, opts) {
    if (typeof(types) != "object") {
     types = [types];
    }
    
    if (opts == undefined) {
     opts = {delay: 0};
    }
         
    for (var i=0; i < types.length; i++) {
     var type = types[i];
     if (this.handlers[type] == undefined) {
       this.handlers[type] = [];
     }
     var h = {handler: handler, opts: opts};
     this.handlers[type].push(h);
     if (this.hooks[type] != undefined) {
       var hook_length = this.hooks[type].length;
       if (hook_length > 0) {
 				if (h.opts.delay != 0) {
          this.chained_inform_handler(0, h, type);
 				} else {
 				  for (var i=0; i < this.hooks[type].length; i++) {
 				   this.inform_handler(h, this.hooks[type][i]);
 				  }
 				}
       }
     }
    };
	},
	chained_inform_handler: function(idx, h, type) {
		if (idx < this.hooks[type].length) {
			registrar.inform_handler(h, this.hooks[type][idx]);
			setTimeout(function() { registrar.chained_inform_handler(idx+1, h, type); }, h.opts.delay);
		}
	},
	inform_handler: function(h, hook) {
		h.handler(hook);
	}
};

registrar.add_handler("dropdown", function(o) {
  var hover = false;
  if (o.hover != undefined && o.hover != null) hover = o.hover;
  if (!o.hover && o.trigger) document.getElementById(o.trigger).onclick = function(){return false;};
});