(function($){

	/**
	 * Ajax setup
	 */
	jQuery.json = function (a,b,d,x){if($.isFunction(b)){x=x||($.isString(d)?d:'');d=b;b=null}return $.ajax({type:"POST",url:a,data:b,success:d,dataType:'json',beforeSend:function(xhr){xhr.setRequestHeader('X-Requested-With','jQuery.json');if(x)xhr.setRequestHeader('X-Requested-With',x)}})};
	jQuery.sjson = function (a,d,x){try{return JSON.decode($.ajax({type:"POST",url:a,data:d,dataType:'json',async:false,beforeSend:function(xhr){xhr.setRequestHeader('X-Requested-With','jQuery.ajson');if(x)xhr.setRequestHeader('X-Requested-With',x)}}).responseText);}catch(e){};return null;};
	
	
	/**
	 * Some compatibility with MooTools
	 */
	window.$$ = jQuery;
	jQuery.fn.addEvent = jQuery.fn.bind;
	jQuery.fn.addEvents = jQuery.fn.bind;
	jQuery.fn.removeEvent = jQuery.fn.unbind;
	jQuery.fn.removeEvents = jQuery.fn.unbind;
	jQuery.fn.fireEvent = jQuery.fn.trigger;
	jQuery.fn.setStyle = jQuery.fn.css;
	jQuery.fn.getStyle = jQuery.fn.css;

	jQuery.fn.erase = jQuery.fn.removeAttr;
	jQuery.fn.set = jQuery.fn.attr;
	// jQuery.fn.get = jQuery.fn.attr; // collision with http://api.jquery.com/get/ method

	jQuery.fn.getWidth = jQuery.fn.width;
	jQuery.fn.getHeight = jQuery.fn.height;
	jQuery.fn.getParent = jQuery.fn.parent;
	jQuery.fn.getChildren = jQuery.fn.children;
	jQuery.fn.getElements = jQuery.fn.find;

	jQuery.fn.getBoundingClientRect = jQuery.fn.offset;
	
	document.addEvent = jQuery.fn.bind.bind(jQuery(document));
	document.addEvents = jQuery.fn.bind.bind(jQuery(document));
	
	jQuery.fn.store = jQuery.fn.data;
	jQuery.fn.retrieve = jQuery.fn.data;
	
	jQuery.fn.appendText = jQuery.fn.append;
	jQuery.fn.adopt = jQuery.fn.append;

	jQuery.fn.destroy = jQuery.fn.remove;
	jQuery.fn.dispose = jQuery.fn.detach;

//	jQuery.tag = function(a){ if(a===window||typeof a!=="object")return null;if(a.length==1)return a.get(0).tagName.toLowerCase();var r=[];a.each(function(i,b){r[i]=jQuery(b).tag()});return r}
	jQuery.tag = function(a){ if(a===window||$type(a)!=="object")return null; return a.get(0).tagName.toLowerCase();}
	jQuery.fn.tag = function(){ return jQuery.tag(this); }

	// for numeric values
	jQuery.numval = function(a){ if(a===window||$type(a)!=="object")return null; if(!a.val || !a.val()) return 0.0; return a.val().replace(/ /g,'').replace(',','.').replace(/[^0-9\.]+/g,'').toFloat(); }
	jQuery.fn.numval = function(v) { if(v) return jQuery(this).val(v.replace('.',',')); return jQuery.numval(this); };

	jQuery.touch = function(a, d, cb) {
		var el = jQuery(a);
		if(!el.length) return null;
		var tag = el.tag();
		if(tag!='a') return null;

		var data = d || {};
		var callback = cb || function(){};
		var url = $(a).attr('href');

		var o = {
			'url' : url,
			'type' : $H(data).getLength() == 0 ? 'GET' : 'POST',
			'data' : data,
			'dataType' : 'json'
		};

		if (cb) {
			o.success = function(r) {
				if(r.out) alert(r.out);
				callback(r.result || null);
			};
			o.async = true;
			return jQuery.ajax(o);
		}

		o.async = false;

		var resp = jQuery.ajax(o).responseText;
		if ($type(resp) == 'string')
			resp = jQuery.parseJSON(resp);

		return resp.result || resp;
	};
	jQuery.fn.touch = function(d, cb) { return jQuery.touch(this, d, cb); };

})(jQuery);


jQuery(document).ready(function($){

	/**
	 * Logger
	 */
	if (window.console)
	jQuery.log = (window.console && console.log
		? (console.log.bind ? console.log.bind(console) : console.log)
		: (console.debug && console.debug.bind ? console.debug.bind(console) : $empty));

	/**
	 * Splash screen)
	 */
	window.splash = {
		init: function( cls ) {
			this._cls = ''+(cls||'');
		},
		visible: function( cls ) {
			cls = '.'+(cls || this._cls);
			return $('div.splash'+cls).length > 0;
		},
		show: function( cls ) {
			cls = ''+(cls || this._cls);
			if( !this.visible( cls ) )
				$('body').append( $('<div class="splash '+cls+' big" />').click(function(){window.splash.hide();}) );
		},
		hide: function( cls ) {
			cls = '.'+(cls || this._cls);
			$('div.splash'+cls).remove();
		}
	};


});



