
(function ($, $x, $p) {

	$p.loading = new function () {
		var self = this;
		
		self.load = function () {
			if (typeof(self.conf.implement) == 'string')
				self.conf.implement = self.conf.implement.split(/,;/);
			for (var k in self.conf.implement)
				if (typeof($p[self.conf.implement[k]]) == 'undefined')
					self.triggerError("Can't find extension '" + self.conf.implement[k] + "' !");
				else
					self.implement(self.conf.implement[k]);
		};
		
		self.implement = function (ext_name) {
			switch (ext_name) {
				case 'ajax':
					$p[ext_name].onEvent('onOpen', self.show);
					$p[ext_name].onEvent('onDone', self.hide);
					break;
			}
		};

		self.show = function (args) {
			if (!args.aoe)
				$.showLoading();
			else
				$(args.aoe).showLoading();
		};
		
		self.hide = function (args) {
			if (!args.aoe)
				$.hideLoading();
			else
				$(args.aoe).hideLoading();
		};

	};

})(jQuery, xwp.xwpage, xwp.xwpage.plugins);