CallWrapper.counter = 0;
CallWrapper.pendingCalls = {};

function CallWrapper(object, method)
{
	CallWrapper.prototype.init				= this.init				= init;
	CallWrapper.prototype.execute			= this.execute			= execute;
	CallWrapper.prototype.asyncExecute		= this.asyncExecute		= asyncExecute;
	CallWrapper.prototype.doAsyncExecute	= this.doAsyncExecute	= doAsyncExecute;
	CallWrapper.prototype.cancel			= this.cancel			= cancel;
	
	this.init(object, method);
	
	function init(object, method)
	{
		this.id = "CallWrapper_" + (CallWrapper.counter++);
		this.object = object;
		this.method = method;
		this.timerId = 0;
		
		CallWrapper.pendingCalls[this.id] = this;
	}
	
	function execute(arg0, arg1, arg2, arg3, arg4, arg5)
	{
		this.object[this.method](arg0, arg1, arg2, arg3, arg4, arg5);
		delete CallWrapper.pendingCalls[this.id];
	}
	
	function cancel()
	{
		clearTimeout(this.timerId);
		delete CallWrapper.pendingCalls[this.id];
	}
	
	function asyncExecute(delay, arg0, arg1, arg2, arg3, arg4, arg5)
	{
		this.arg0 = arg0;
		this.arg1 = arg1;
		this.arg2 = arg2;
		this.arg3 = arg3;
		this.arg4 = arg4;
		this.arg5 = arg5;
		this.timerId = setTimeout("CallWrapper.pendingCalls[\"" + this.id + "\"].doAsyncExecute()", delay);
	}
	
	function doAsyncExecute()
	{
		this.execute(this.arg0, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5);
	}
}
