// "hook.js" v1.01, disturbed (c) 2004

function wg_hook()
{
	this.baits = new Array();			//collection of events
	this.next_id = 0;
	
	this.hook = function(varEvent,varFunction)	//hooks function to event
	{
		//if(!this.baits)this.baits=new Array();
		if(!this.baits[varEvent])this.baits[varEvent] = new Array();
		var next_bait = this.baits[varEvent].length;
		
		this.baits[varEvent][next_bait] = new Array();
		
		this.baits[varEvent][next_bait]['id'] = this.next_id++;
		this.baits[varEvent][next_bait]['function'] = varFunction;
		
		return this.baits[varEvent][next_bait]['id'];
		
	}

	this.unhook = function(id)
	{
	
		var varEvent
		for (varEvent in this.baits)
		{
			
			for(hc=0;hc<this.baits[varEvent].length;hc++)
			{
		
				if(this.baits[varEvent][hc]!=undefined)
				{
					if(this.baits[varEvent][hc]['id']==id)
					{
						this.baits[varEvent].remove(hc);
						if(this.next_id-1==id) this.next_id--;
						break;
					}
				}
				
			}
			
		}

	}

	this.run_event = function(e, varEvent)		//execs all f. in event collection
	{
		
		if(e==undefined)	this.event = window.event;
		else
		{
			this.event = e;
			window.event = e;
		}
		
		if(this.event.x==undefined && this.event.pageX!=undefined)
		{
			this.event.mouse_x = this.event.pageX
			this.event.mouse_y = this.event.pageY
		}
		else if(document.body)
		{
			this.event.mouse_x = this.event.x + document.body.parentNode.scrollLeft
			this.event.mouse_y = this.event.y + document.body.parentNode.scrollTop
		}
		else
		{
			this.event.mouse_x = 0;
			this.event.mouse_y = 0;
		}
			
		if(this.baits[varEvent])
		{
			for(hc=0;hc<this.baits[varEvent].length;hc++)
			{
				eval(this.baits[varEvent][hc]['function']);
			}
		}
	
	}

}


if(window.hook==undefined) var hook = new wg_hook();

window.onload	= function(e){hook.run_event(e, 'load')}
window.onresize	= function(e){hook.run_event(e, 'resize')}
window.onunload	= function(e){hook.run_event(e, 'unload')}

document.onmousemove	= function(e){hook.run_event(e, 'mousemove')}
document.onmouseover	= function(e){hook.run_event(e, 'mouseover')}
document.onmouseout	= function(e){hook.run_event(e, 'mouseout')}
document.onfocus	= function(e){hook.run_event(e, 'focus')}
