var CHERRY = (function(){
	var onReadyStack = [];
	var self = {
		init:function() {
			if(self.init.busy) return null;
			self.init.busy = true;
			while(onReadyStack.length) {
				onReadyStack.shift().call(self);
			}
		},
		onReady:function(func){
			if(func && func.call && func.apply) {
				onReadyStack.push(func);
			}
		},
		ajax: function(url, params, method, handler) {
			if(!url) url = document.location.protocol + '//' + document.location.hostname +
										 document.location.pathname + document.location.search;
			handler  = handler || function(){};
			var pick = function() {
				var v  = [
					function(){return new XMLHttpRequest()},
					function(){return new ActiveXObject("Msxml2.XMLHTTP")},
					function(){return new ActiveXObject("Msxml3.XMLHTTP")},
					function(){return new ActiveXObject("Microsoft.XMLHTTP")}
				], result
				for(var i=0,l=v.length; i<l; i++) {
					try { result = v[i]();
					} catch(exc) {continue}
					break
				}
				return result;
			}
			var provider = pick(), xmlhttp  = provider, closure  = function() {
				try {
				handler({readyState: xmlhttp.readyState,
								 statusCode:(xmlhttp.readyState==4) ? xmlhttp.status : null,
								 responseJS:(xmlhttp.readyState==4 && xmlhttp.status==200) ?
												(function(x){var r = '';try{eval('try{r='+(x.responseText || 'null')+'}catch(e){}');}catch(e){$.log(e)}return r})(xmlhttp) : null
								 })
				} catch(exc) {
					if(xmlhttp.readyState==4) {
					}
				}
				if(xmlhttp.readyState==4) {
					xmlhttp = null;
				}
			}
			if(!!params.shift) params = params.join('&');
			if(method=='get') url += (url.match(/\?/) ? '&' : '?') + params;
			url += (url.match(/\?/) ? '&' : '?') + '$js=' + ((new Date()).getTime());
			try {
				provider.open(method, url.toLowerCase(), true);
				provider.onreadystatechange = closure;
				provider.setRequestHeader('X-Requested-With', 'CherryAjax');
				if(method=='post') provider.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
				provider.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
				provider.setRequestHeader('Connection', 'close');
				provider.send(method=='post' ? params : null);
			} catch(exc) {
				if(('console' in window) && ('log' in console)) {
					console.log(exc);
				}
			};
			return provider
		}
	}
	return self;
})();
(function(init){
	if(document.all && document.all.item && !window.opera) {
		document.write('<scr'+'ipt id="_DOMContentLoaded_" defer="defer" src="javascript:void(0)"><\/scr'+'ipt>');
		var script = document.getElementById('_DOMContentLoaded_');
		script.onreadystatechange = function() {
			if(this.readyState=='complete') {
				init();
			}
		}
	}
	if(navigator.vendor && navigator.vendor.toLowerCase().indexOf('apple') >= 0) {
		var timer = setInterval(function() {
			if(/loaded|complete/.test(document.readyState)) {
				clearInterval(timer);
				init();
			}
		}, 10);
	}
	if(document.addEventListener) {
		document.addEventListener('DOMContentLoaded', init, false);
		document.addEventListener('load', init, false);
	}
	if(document.attachEvent) {
		document.attachEvent('onload', init);
	}
	var older = window.onload;
	window.onload = function() {
		if(older && older.call) older();
		init();
	}
})(function(){CHERRY.init()});