jQuery.request = jQuery.fn.request = function() {

	var complete = function(callback) {
		return function(XMLHttpRequest, textStatus){
			if (callback.container) callback.container.loading('destroy');
			if((textStatus == 'error' || textStatus == 'timeout') && callback.failure){
				callback.failure.call(callback.scope || window, {
					responseText: XMLHttpRequest.responseText,
					arguments: callback.arguments
				});
			} else if(callback.success){
					callback.success.call(callback.scope || window, {
					responseText: XMLHttpRequest.responseText,
					arguments: callback.arguments
				});
			}
		};
	};

	var getJSON = function(responce) {
		return eval('new Object(' + responce.responseText + ')');
	};

	var successHandler = function(responce) {
		var json = getJSON(responce);
		if (json && responce.arguments && responce.arguments.func) responce.arguments.func.call(this, json, responce.arguments);
	};
	var failureHandler = function(responce) {
		
	}; 

	var get = function(options) {
		var params = {
			data: (options.data) ? options.data : null, 
			dataType: 'text', 
			type: 'GET', 
			url: (options.url) ? options.url : null, 
			complete: complete({
				scope: (options.scope) ? options.scope : this, 
				failure: failureHandler, 
				success: successHandler, 
				container: ((options.container)? options.container : null), 
				arguments: $.extend((options.arguments) ? options.arguments : {}, {func: (options.func)? options.func : null})
			})
		};
		if (options.container) options.container.loading();
		jQuery.ajax(params);
	};
	
	var post = function(options) {
		if (options.form) {
			var params = {
				type: 'POST', 
				url: (options.url) ? options.url : null, 
				complete: complete({
					scope: (options.scope) ? options.scope : this, 
					failure: failureHandler, 
					success: successHandler, 
					container: ((options.container)? options.container : null), 
					arguments: $.extend((options.arguments) ? options.arguments : {}, {func: (options.func)? options.func : null})
				})
			};
			if (options.container) options.container.loading();
			options.form.ajaxSubmit(params);
		}
	};

	if (arguments[0] && (typeof arguments[0] === 'object')) {
		var options = arguments[0];
		if (options.type && (options.type == 'post')) post(options);
		else get(options);
	}
}
jQuery.plugin = jQuery.fn.plugin = function(object, plugin, func, params) {
	var cmd_ = '';
	var paramsStr = '';
	if ((params) && (params instanceof Array)) {
		for (var i = 0; i < params.length; i++) {
			paramsStr += ', params[' + i + ']';
		}			
	}
	if (typeof func === 'string') cmd_ = "'" + func + "'";
	else if (typeof func === 'object') cmd_ = 'func';
	var cmd = "object." + plugin + "(" + cmd_ + "" + paramsStr + ");";
	return eval(cmd);
}

jQuery.loading = jQuery.fn.loading = function() {
	var create = function(target) {
		modal = (this.modal = $('<div/>'))
			.addClass('loading')
			.height(target.height())
			.width(target.width());
		target.prepend(modal);
	};
	var destroy = function(target) {
		target.find('.loading').remove();
	};
	if (!arguments[0]) create(this);
	else if (arguments[0] && (typeof arguments[0] === 'string') && (arguments[0] == 'destroy')) destroy(this);
}

$.ui.widget.subclass('ui.component');