function MyEvent(rawEvent) {
	this.ie = isNaN(rawEvent.pageX);
	if (!this.ie) {
		this.target = (rawEvent.target.tagName ? rawEvent.target : rawEvent.target.parentNode);
		this.mouseButton = rawEvent.mouseButton;
		this.relatedTarget = rawEvent.relatedTarget;
		this.rawEvent = rawEvent;
		this.stopPropagation = function () { this.rawEvent.stopPropagation(); }
		this.preventDefault = function () { this.rawEvent.preventDefault(); }
		this.preventBubble = function () { this.rawEvent.preventBubble(); }
		this.offsetX = function() { return this.left - getElLeft(this.target); }
		this.offsetY = function() { return this.top - getElTop(this.target); }
		this.left = parseInt(rawEvent.pageX);
		this.top = parseInt(rawEvent.pageY);
		if (rawEvent.keyCode) {
			this.keyCode = rawEvent.keyCode;
		}
		else {
			this.keyCode = rawEvent.which;
		}
	}
	else {
		this.srcElement = rawEvent.srcElement;
		this.target = rawEvent.srcElement;
		this.mouseButton = rawEvent.button;
		this.relatedTarget = rawEvent.toElement;
		this.rawEvent = rawEvent;
		this.stopPropagation = function () { this.rawEvent.cancelBubble = true; }
		this.preventDefault = function () { this.rawEvent.returnValue = false; }
		this.preventBubble = function () { this.rawEvent.cancelBubble = true; }
		this.offsetX = function() { return this.rawEvent.offsetX; }
		this.offsetY = function() { return this.rawEvent.offsetY; }
		this.keyCode = rawEvent.keyCode;
		this.left = document.body.scrollLeft+rawEvent.clientX;
		this.top = document.body.scrollTop+rawEvent.clientY;
		//this.left = rawEvent.offsetX;
		//this.top = rawEvent.offsetY;
	}
	this.clientX = rawEvent.clientX;
	this.clientY = rawEvent.clientY;
	this.ctrlKey = rawEvent.ctrlKey;
	this.shiftKey = rawEvent.shiftKey;
	this.altKey = rawEvent.altKey;
	this.adjusted = true;
}

function getEventObject(rawEvent) {
	if (typeof(rawEvent)=="undefined") {
		rawEvent = window.event;
	}
	if (rawEvent.adjusted) { return rawEvent; }
	if (!rawEvent) { rawEvent = window.event; }
	var evt = new MyEvent(rawEvent);
	return evt;
}

var geo = getEventObject;

/***
el: either id of element as string, or element itself
name: string name of event, without 'on' prefix
funcName: string name of function
bubble: (bool) whether event bubbles up
*/
function setEventListener(el, eventName, funcName, bubble) {
	if (typeof(el)=="string") {
		el = document.getElementById(el);
	}
	if (el.addEventListener) {
		el.addEventListener(eventName, eval(funcName), bubble);
	}
	else {
		str = "el.on"+eventName+" = function () { evt = getEventObject(event);\n";
		str += funcName+ "(evt);\n";
		if (!bubble) {
			str += "event.cancelBubble = true;\n";
		}
		str += "return "+(!bubble)+";\n";
		str += "}";
		eval(str);
	}
}

function setEventObjectListener(el, eventName, objName, funcName, bubble) {
	var mglName = objName+"__"+funcName;
	eval(mglName +' = function(evt) { \
		'+objName+'.'+funcName+'(evt); \
	}');
	setEventListener(el, eventName, mglName, bubble);
}


if (typeof(onloads)=="undefined") {
	onloads = [];
}

function onloadAll(event) {
	event = geo(event);
	for (var i=0; i<onloads.length; i++) {
		onloads[i](event);
	}
}