﻿function $(id){return document.getElementById(id);}

function $GetEvent(e) {
	e = (window.event) ? window.event : e;
	if (!e.target) e.target = e.srcElement;
	e.cancel = function() {this.cancelBubble = true; if (this.stopPropagation) this.stopPropagation();};
	e.key = (typeof(e.keyCode)!= 'undefined') ? e.keyCode : ((typeof(e.charCode)!= 'undefined') ? e.charCode : 0);
	if (typeof(e.offsetX)=='undefined') e.offsetX=e.layerX;
	if (typeof(e.offsetY)=='undefined') e.offsetY=e.layerY;
	return e;
}

function subclassElement(e) {
	if (e.subclassed) return;
	var methods = {
		t: function(v) {if (typeof(v)!="undefined")this.style.top=v;return this.offsetTop;},
		l: function(v) {if (typeof(v)!="undefined")this.style.left=v;return this.offsetLeft;},
		w: function(v) {if (typeof(v)!="undefined")this.style.width=v;return this.offsetWidth;},
		h: function(v) {if (typeof(v)!="undefined")this.style.height=v;return this.offsetHeight;},
		wh: function(p) {if (typeof(p)!="undefined"){this.style.width=p.w;this.style.height=p.h;};return {w:this.offsetWidth,h:this.offsetHeight};},
		ltwh: function(l,t,w,h) {this.l(l);this.t(t);this.w(w);this.h(h);}
	};
	for (var property in methods)
		e[property] = methods[property];
		
	e.subclassed = true;
}
if (window.HTMLElement)
	subclassElement(Element.prototype);

function createElement(parent,tag,className,id) {
	var e = document.createElement(tag);
	if (className) e.className=className;
	if (id) e.id=id;
	parent=$(parent);
	if (!parent) parent = document.body;
	subclassElement(e);
	parent.appendChild(e);
	return e;
}