if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.childNodes && !document.all && !navigator.taintEnabled) window.webkit = true;
else if (document.getBoxObjectFor != null) window.gecko = true;
if (window.ie6) try {document.execCommand("BackgroundImageCache", false, true);} catch(e){};//IE6 enable image caching, to prevent flickering
if(typeof $ == 'undefined'){
	function $(el){
		if(typeof el == 'string') el = document.getElementById(el);	
		return el;
	}
}
$extend = function(){
	var a = arguments;
	if (!a[1]) a = [this, a[0]];
	for (var p in a[1]) a[0][p] = a[1][p];
	return a[0];
};
$extend(Function.prototype,{
	bind : function(bind/*, arg1, arg2, arg3*/){
		var f = function(){
			var c = arguments.callee;
			return c._f.apply(c._b, c._a.concat([].slice.call(arguments, 0)));
		};
		f._f = this;
		f._b = bind;
		f._a = [].slice.call(arguments, 1);
		return f;
	},
	bindAsEventListener : function(bind){
		var f = function(event){
			var c = arguments.callee;
			return c._f.apply(c._b, [event || window.event].concat(c._a));
		};
		f._f = this;
		f._b = bind;
		f._a = [].slice.call(arguments, 1);
		return f;
	},
	delay : function(ms, bind){
		return setTimeout(this.bind(bind || this), ms);
	},
	periodical : function(ms, bind){
		return setInterval(this.bind(bind || this), ms);
	}
});
$extend(window, {
	addDOMReadyListener : function(fn){
		var state = document.readyState;
		if(state && window.webkit){
			if(/loaded|complete/.test(state)) return fn();
			else return window.addDOMReadyListener.bind(window, fn).delay(100);
		}else if(state && window.ie){
			if(!$('ie_ready')){
				var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
				document.write('<script id="ie_ready" defer src="' + src + '"><\/script>');
			}
			var s = $('ie_ready');
			var f = function(){
				var c = arguments.callee;
				if (c._b.readyState == 'complete'){
					c._f();
					return true;
				}
				return false;
			};
			f._f = fn;
			f._b = s;
			if(!f())s.attachEvent('onreadystatechange', f);
		}else{
			var f = function(){
				var c=arguments.callee;
				if (c.done) return;
				c.done = true;
				c._f();
			};
			f._f = fn;
			window.addEventListener('load', f, false);
			document.addEventListener('DOMContentLoaded', f, false);
		}
	}
});
