EventWrapper.callbacks = {};
EventWrapper.events = {};
EventWrapper.counter = 0;
	
for(i = 0; i < 1000; i ++)
{
	EventWrapper.callbacks[i] = new Function("e", "EventWrapper.events[" + i + "].doCallback(e)");
}

EventWrapper.unload = function()
{
	for(i in EventWrapper.events)
	{
		if(EventWrapper.events[i])
			EventWrapper.events[i].cancel();
	}
};

new EventWrapper("unload", new CallWrapper(EventWrapper, "unload"), window);

function EventWrapper(eventType, callback, element, arg0, arg1, arg2, arg3, arg4)
{
	EventWrapper.prototype.init			= this.init			= init;
	EventWrapper.prototype.cancel		= this.cancel		= cancel;
	EventWrapper.prototype.doCallback	= this.doCallback	= doCallback;
	
	this.init(eventType, callback, element, arg0, arg1, arg2, arg3, arg4);
	
	this.id;
	this.eventType;
	this.callback;
	this.element;
	this.arg0;
	this.arg1;
	this.arg2;
	this.arg3;
	this.arg4;
	
	function init(eventType, callback, element, arg0, arg1, arg2, arg3, arg4)
	{
		while(EventWrapper.events[EventWrapper.counter])
			EventWrapper.counter = (EventWrapper.counter+1)%1000;
		this.id			= EventWrapper.counter;
		this.eventType	= eventType;
		this.callback	= callback;
		this.element	= element;
		this.arg0		= arg0;
		this.arg1		= arg1;
		this.arg2		= arg2;
		this.arg3		= arg3;
		this.arg4		= arg4;
		
	
		EventWrapper.events[this.id] = this;
		
		if(!this.element.attachEvent)
			this.element.addEventListener(this.eventType, EventWrapper.callbacks[this.id], false);
		else
		{
			this.eventType = "on" + this.eventType;
			this.element.attachEvent(this.eventType, EventWrapper.callbacks[this.id]);
		}
	}
	
	function doCallback(e)
	{
		this.callback.execute(e, this.arg0, this.arg1, this.arg2, this.arg3, this.arg4);
	}
	
	function cancel()
	{
		if(!this.element.detachEvent)
			this.element.removeEventListener(this.eventType, EventWrapper.callbacks[this.id], false);
		else
			this.element.detachEvent(this.eventType, EventWrapper.callbacks[this.id]);
		delete EventWrapper.events[this.id];
	}
}