// Loading indicator
// using.js and jQuery must be already loaded
// alex@regio.ee

;(function() {

var startedCount = 0;
$(".loading").addClass("hidden");

function _start() {
	if(0 == startedCount++) {
		$(".loading").removeClass("hidden");
	}
}

function _stop() {
	if(0 == --startedCount) {
		$(".loading").addClass("hidden");
	}
}

$(".loading")
.ajaxStart(function(){
	_start();
})
.ajaxStop(function(){
	_stop();
});

using._loadBegin = function() {
	_start();
}

using._loadDone = function() {
	_stop();
}

$(document).bind("loadingStarted", function() {
	_start();
});

$(document).bind("loadingStopped", function() {
	_stop();
});

})();