/*
	Event management.
*/

// MSIE Compatibility
if (!Event)
	var Event = {};
	
// MSIE Compatibility
if (!Event.prototype)
	Event.prototype = {};

// target, no neccessarily the item which has the event listener
// this may have bubbled
Event.prototype.getTarget = function() {
	var t = this.target || this.srcElement;
	if (t.nodeType == 3)
		t = t.parentNode || t.parentElement;
		
	return t;
}

// releated target, the item which the mouse have moved onto or out of
Event.prototype.getRelatedTarget = function() {
	return this.relatedTarget || this.fromElement || this.toElement;
}

// which key code for 'keyup' and 'keydown; events
Event.prototype.getWhich = function() {
	return this.which || this.keyCode;
}

// right click (2nd mouse button)
Event.prototype.isMouseRightButton = function() {
	return this.which ? (this.which == 3) : (this.button == 2);
}

// mouse x and y
Event.prototype.getMouseX = function() {
	return this.pageX || this.clientX + document.body.scrollLeft;
}

Event.prototype.getMouseY = function() {
	return this.pageY || this.clientY + document.body.scrollTop;
}
