
/**
 * @class creating delegates
 * for event listeners etc
 */
var Delegate = {
	
	/**
	 * stores the last function number
	 * used to make unique functions
	 * @type int
	 */
	func_number: 0,

	/**
	 * create a new delegate
	 * @param {object}	obj		the object to bind with
	 * @param {mixed}	func	the function (<string> or <function>) to bind with
	 * @param {mixed}	others	all other params to send with
	 * @return the created function
	 * @type function
	 */
	create: function(obj, func)
	{
		if (arguments.length > 2)
		{
			var params = jQuery.makeArray(arguments);
			params.shift();
			params.shift();

			return function() {
				if (typeof func == 'string')
					return obj[func].apply(obj, params);
				else
					return func.apply(obj, params);
			};
		}
		else
		{
			return function() {
				if (typeof func == 'string')
					return obj[func].apply(obj, arguments);
				else
					return func.apply(obj, arguments);
			};
		}
	},
	
	
	createWithObject: function(obj, func)
	{
		return function() {
			var params = jQuery.makeArray(arguments);
			params.unshift(this);
			
			if (typeof func == 'string')
				return obj[func].apply(obj, arguments);
			else
				return func.apply(obj, arguments);
		};
	},
	
	
	/**
	 * create function with a name
	 * @param {object}	obj		the object to bind with
	 * @param {mixed}	func	the function (<string> or <function>) to bind with
	 * @param {mixed}	others	all other params to send with
	 * @return the name of the created function
	 * @type string
	 */
	create_named_function: function(obj, func)
	{
		this.func_number++;
		var name = 'created_function_' + this.func_number;
		window[name] = this.create.apply(this, arguments);
		return name;
	}
};

