
function $(e) {
   return document.getElementById(e);
}

Function.prototype.bind = function(base) {
   var self = this;
   return function() {
      self.apply(base, arguments);
   }
}

var addEvent = (window.addEventListener) ?
(function(elm, type, event) {
      elm.addEventListener(type, event, false);
   }) : (window.attachEvent) ?
(function(elm, type, event) {
      elm.attachEvent('on'+type, event);
   }) :
(function(elm, type, event) {
      elm['on'+type] = event;
   }) ;

addEvent(window, 'load', function() {
      invoke_hook('load');
   });

var Hook = {};
Hook.prototype = {
   register_hook: function(name, func) {
      if(!this.__registed_hook)
         this.__registed_hook = new Array();

      if(!this.__registed_hook[name])
         this.__registed_hook[name] = new Array();
      this.__registed_hook[name].push(func);
   },

   invoke_hook: function() {
      var args = Array.apply(null, arguments);
      var name = args.shift();
      if(!this.__registed_hook || !this.__registed_hook[name])
         return;
      for(var func, i = 0; func = this.__registed_hook[name][i]; i++) {
         func.apply(this, args);
      }
   }
};

/* generate global hook */
var register_hook, invoke_hook;
(function(){
    var __hook = Hook.prototype;
    register_hook = function() {
      __hook.register_hook.apply(__hook, arguments);
    }
    invoke_hook = function() {
      __hook.invoke_hook.apply(__hook, arguments);
    }
  })();


