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(/^\?/,'');
	};

	obj.getkeycode = function(event) {

		return event.keyCode || event.which;
	};

	return obj;
}();


global.event = function() {

	var obj = {};
	var eventcache = [];

	obj.add = function(o,type,func) {

		if (window.addEventListener) {
			o.addEventListener(type,func,false);

		} else if (window.attachEvent) {
			// note closure returns a result allowing event handlers to halt event bubbling
			o['e' + type + func] = func;
			o[type + func] = function() { return o['e' + type + func](window.event); };
			o.attachEvent('on' + type,o[type + func]);
			eventcache[eventcache.length] = { o: o, type: type, func: func };
		}
	};

	obj.remove = function(o,type,func) {

		if (window.removeEventListener) {
			o.removeEventListener(type,func,false);

		} else if (window.detachEvent) {
			o.detachEvent('on' + type,o[type + func]);
			o[type + func] = null;
			o['e' + type + func] = null;
		}
	};

	function cleanup() {

		// 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;
	}

	if (window.detachEvent) {
		// setup IE event cleanup routine
		obj.add(window,'unload',cleanup);
	}

	return obj;
}();