/**
 * Esta classe representa os eventos.
 * 
 * @author Jamillo
 */
ICore.events.Event = function (obj) {
	this.obj = null;
	this.functions = [];
	this.setObj(obj);
}

/**
 * @type {Function[]}
 */
ICore.events.Event.prototype.functions = null;

/**
 * Altera o valor da propriedade {ICore.events.Event#obj}.
 * 
 * @param {Object} value
 * @see {ICore.events.Event#obj}
 */
ICore.events.Event.prototype.setObj = function (value) {
	this.obj = value;
};

/**
 * Retorna o valor da propriedade {ICore.events.Event#obj}.
 * 
 * @return {Object}
 */
ICore.events.Event.prototype.getObj = function () {
	return this.obj;
};

/**
 * Método que adiciona funções a lista do evento.
 * 
 * @method ICore.events.Event.addListener
 * @param {Function} fnc
 */
ICore.events.Event.prototype.addListener  = function (obj, fnc) {
	var isf = ICore.util.isFunction(obj);
	if (isf) {
		fnc = obj;
		delete obj;
		obj = this;
	}
	fnc.___obj = obj;
	var i = this.functions.push(fnc);
};

/**
 * Remove uma funções da lista.
 * 
 * @param {Function} fnc
 */
ICore.events.Event.prototype.removeListener = function (fnc) {
	var i = this.functions.remove(fnc);
};

/**
 * Limpa a lista de funções.
 */
ICore.events.Event.prototype.clear = function () {
	this.functions.splice(0, this.functions.length);
};

/**
 * Dispara o evento.
 */
ICore.events.Event.prototype.fire = function () {
	for (var i = 0; i < this.functions.length; i ++) {
		if (ICore.util.isUndefined(this.functions[i].___obj)) { // O que faz o contexto
			this.functions[i].call(this.obj/*, arguments*/);
		} else {
			this.functions[i].call(this.functions[i].___obj/*, arguments*/);
		}
	}
};

/**
 * Evento de carregamento da página.
 * @var {ICore.events.Event}
 */
ICore.onLoad = new ICore.events.Event(ICore);

ICore.onLoad.addListener(function () {
	ICore.pageLoaded = true;
});

ICore.dom.addListener(window, 'load', function () {
	ICore.onLoad.fire();
});

