(function($) {// secure $ jQuery alias
/*******************************************************************************************/
// jquery.__event.js - rev 2
// Copyright (c) 2011, Larry (http://larionov.biz)
// Liscensed under the BSD License (BSD-LICENSE.txt)
// http://www.opensource.org/licenses/bsd-license.php
// Created: 2011-03-01
// Modified: 2011-06-17
/*******************************************************************************************/

$.__Event = function() {};
/**
 * @param {Object} object
 * @param {String} event
 * @param {Function} fn
 * @return {$.__Event}
 */
$.__Event.prototype.bind = function(event, fn) {
	if (!this.__events) {
		this.__events = {};
	}
	var self = this;
	if (typeof event == 'string' && fn instanceof Function) {
		$.each(event.split(' '), function (i, eventName) {
			if (self.__events[eventName] == undefined || !$.isArray(self.__events[eventName])) {
				self.__events[eventName] = [];
			}
			self.__events[eventName].push(fn);
		});
	}
	return this;
};
/**
 * @param {String} event
 * @param {Function} fn Optional
 * @return {$.__Event}
 */
$.__Event.prototype.unbind = function(event, fn) {
	if (!this.__events) {
		this.__events = {};
	}
	var self = this;
	if (typeof event == 'string') {
		$.each(event.split(' '), function (index, eventName) {
			if (fn instanceof Function && $.isArray(self.__events[eventName])) {
				for (var i = 0, count = self.__events[eventName].length; i < count; i++) {

				}
			} else {
				self.__events[eventName] = [];
			}
		});
	}
	return this;
};
/**
 * @param {String} event
 * @param {Boolean} checkReturn Optional
 * @return {Boolean}
 */
$.__Event.prototype.trigger = function(event, checkReturn, args) {
	if (!this.__events) {
		this.__events = {};
	}
	var self = this, ret, events;
	checkReturn = checkReturn || false;
	args = $.isArray(args)? args: ($.isArray(checkReturn)? checkReturn: []);
	if (typeof event == 'string') {
		events = event.split(' ');
		for (var index = events.length - 1; index >= 0; index--) {
			if ($.isArray(self.__events[events[index]])) {
				for (var i = self.__events[events[index]].length - 1; i >= 0; i--) {
					if (self.__events[events[index]][i] instanceof Function) {
						ret = self.__events[events[index]][i].apply(self, args);
						if (checkReturn && (ret === false)) {
							return false;
						}
					}
				}
			}
		}
	}
	return true;
};
$.__Event.inherit = function(dst, src) {
	var Tmp = function() {};
	Tmp.prototype = src.prototype;
	dst.prototype = new Tmp();
	dst.prototype.constructor = src;
};
})(jQuery);

