
var spinControl = Class.create();
spinControl.prototype = {
	initialize: function(triggersId, progressId, contentListToHideId) {
		this.initError = false;
		this.progressId = progressId;
		this.contentListToHideId = contentListToHideId;

		if( triggersId != '*' ) {
			this.filterList = (triggersId).split(',');
			if(this.filterList.length == 0 || !$(this.progressId)) {
				this.initError = true;
				return;
			}
		}
		
		var prm = Sys.WebForms.PageRequestManager.getInstance();
		prm.add_initializeRequest(this._initializeRequestHandler.bind(this));
		prm.add_endRequest(this._endRequestHandler.bind(this));
	},
	
	_initializeRequestHandler: function(sender, args) {
		var postBackElement = args.get_postBackElement();
		if(postBackElement == null)	{
			var postBackElementFromSender = sender._postBackSettings.panelID.split('|')[1];
			this._checkSender(postBackElementFromSender);
			return;
		}
		this._checkSender(postBackElement.id)
	},
	
	_endRequestHandler: function(sender, args) {
		$(this.progressId).hide();
	},
	
	_checkSender: function(postBackElement) {
		if(this.filterList) {
			this.filterList.each((function(el){
				if (new RegExp(RegExp.escape(el), "i").test(postBackElement)) {
					this._showProgress();
					return;
				}
			}).bind(this));
		} else {
			this._showProgress();
		}
	},
	
	_showProgress: function() {
		var hideEl = $(this.contentListToHideId);
		if(hideEl) hideEl.hide();
		
		$(this.progressId).show();
	}
}
	
Object.extend(spinControl, {
	items: [],
	add: function(triggersId, progressId, contentListToHideId) {
		var item = new spinControl(triggersId, progressId, contentListToHideId);
		if (!item.initError) {
			this.items.push(item);
			return item;
		}
		return null;
	}
});



// [AtlasScript]

if(typeof(Sys)!="undefined")
	Sys.Application.notifyScriptLoaded();

// [/AtlasScript]

