function $(id) {

	return document.getElementById(id);
}


var global = function() {

	var obj = {};

	obj.trim = function(s) { return s.replace(/^\s+|\s+$/g,''); };

	obj.d2h = function(d) { return d.toString(16); };

	obj.h2d = function(h) { return parseInt(h,16); };

	obj.getquerystring = function() { return window.location.search.replace(/^\?/,''); };

	return obj;
}();


global.event = function() {

	var obj = {},
		win = window,
		eventcache = [];

	obj.add = function(o,type,func) {

		if (win.addEventListener) {
			// W3 add event
			o.addEventListener(type,func,false);

		} else if (win.attachEvent) {
			// IE add event
			// methods here to fix 'this' upon event call, correct passing of the event object
			// and event tracking (eventcache) to allow memory cleanup on document unload
			var fname = type + func,
				ename = 'e' + fname;

			o[ename] = func;
			o[fname] = function() { return o[ename](win.event); };
			o.attachEvent('on' + type,o[fname]);
			eventcache[eventcache.length] = { o: o, type: type, func: func };
		}
	};

	obj.remove = function(o,type,func) {

		if (win.removeEventListener) {
			// W3 remove event
			o.removeEventListener(type,func,false);

		} else if (win.detachEvent) {
			// IE remove event
			var fname = type + func;

			o.detachEvent('on' + type,o[fname]);
			o[fname] = null;
			o['e' + fname] = null;
		}
	};

	obj.preventdefault = function(e) {

		if (e.preventDefault) {
			e.preventDefault();
			return;
		}

		e.returnValue = false; // IE equivalent
	};

	obj.gettarget = function(e) {

		// W3/IE target
		var target = e.target || e.srcElement;

		// defeat Safari bug
		return (target.nodeType == 3) ? target.parentNode : target;
	};

	obj.getrelatedtarget = function(e) {

		return e.relatedTarget || ((e.type == 'mouseover') ? e.fromElement : ((e.type == 'mouseout') ? e.toElement : false));
	};

	obj.ismouseenterleave = function(el,e) {

		var rel = obj.getrelatedtarget(e);
		return !(!rel || el === rel || ischildof(el,rel));
	};

	function ischildof(parent,child) {

		while (child && (child !== parent)) child = child.parentNode;
		return (child === parent);
	}

	obj.getkeycode = function(e) { return e.keyCode || e.which; };

	if (win.detachEvent) {
		// setup IE event cleanup routine to run on document unload
		obj.add(win,'unload',function() {

			// cycle eventcache array and remove all events to avoid IE memory leaks
			for (var i = 0,j = eventcache.length;i < j;i++) {
				obj.remove(eventcache[i].o,eventcache[i].type,eventcache[i].func);
			}

			eventcache = null;
		});
	}

	return obj;
}();