
// 
// CLASS:
// - Event
// 
// VERSION:
// - 1.0.0 - 20071010 - Core design
// 

var Event = {};

// W3C DOM2
if (typeof document.addEventListener != 'undefined')
{
  Event.addListener = function (target, type, listener)
  {
    target.addEventListener(type, listener, false);
  };
  
  Event.removeListener = function (target, type, listener)
  {
    target.removeEventListener(type, listener, false);
  };
  
  Event.preventDefault = function (event)
  {
    event.preventDefault();
  };
  
  Event.stopPropagation = function (event)
  {
    event.stopPropagation();
  };
}

// IE
else if (typeof document.attachEvent != 'undefined')
{
  Event.addListener = function (target, type, listener)
  {
    var listener2 = function ()
    {
      var event = window.event;
      
      if (Function.prototype.call)
      {
        listener.call(target, event);
      }
      
      else
      {
        target._currentListener = listener;
        target._currentListener(event);
        target._currentListener = null;
      }
    }
    
    target.attachEvent('on' + type, listener2);
  };
  
  Event.removeListener = function (target, type, listener)
  {
    target.detachEvent('on' + type, listener);
  };
  
  Event.preventDefault = function ()
  {
    window.event.returnValue = false;
  };
  
  Event.stopPropagation = function ()
  {
    window.event.cancelBubble = true;
  };
}

// Misc.
Event.run = function (obj)
{
  var initOnce = function ()
  {
    if (arguments.callee._done)
    {
      return;
    }
    
    arguments.callee._done = true;
    obj.init();
  }
  
  Event.addListener(document, 'DOMContentLoaded', initOnce);
  Event.addListener(window, 'load', initOnce);
};

