/**
/*  events.js
/*  Gets properties of any event and cancel bubble upon construction with optional param.
/*  Keys handles events trigged by user keyboard input
/*  addDOMEvent registers events with the document 

/*  Ben Ipsen  2005. No Copyright. No license. Just Love. 
/*  Use wisely and for the greater good.  
/*
/*  docs: http://benipsen.com/elementary/
**/

function EventInfo(e, cancel){
		if (!e) var e = window.event;		
	
		if (e.target) this.source = e.target;
		else if (e.srcElement) this.source = e.srcElement;
		if (this.source.nodeType == 3)
			this.source = this.source.parentNode;
			
		if (e.pageX || e.pageY) {
			this.xmouse = e.pageX;
			this.ymouse = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			this.xmouse = e.clientX + document.body.scrollLeft;
			this.ymouse = e.clientY + document.body.scrollTop;
		}		
		if(cancel){
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
		}	
}


//register listeners for window/document events cross-browser
//register listeners cross browser
function addWindowEventListener(eventName, callback, bubble){
	if(window.addEventListener){          
		window.addEventListener(eventName, callback, bubble);
	} else {
		//ie
		document.attachEvent('on' + eventName, callback);
	}                                                  
}
 

//listen for key press events
function Keys(){ 
	var This = this; 
	this.listeners = new Object(); 
	this.handlePress = function(key, e){
		This.listeners[key].call(e);
	}
   	this.onkeyup = function(e){ 
		var ei = new EventInfo(e, true);
	    This.handlePress(e.keyCode, e);
	}
	 
	this.addKey = function(character, callback){
	   this.listeners[character] = callback; 
	}
}  
var keyListener = new Keys();
addWindowEventListener('keyup',keyListener.onkeyup);



