/* Copyright (c) 2009 Oleg Ukhabin (ukhabin@gmail.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2009-02-21 11:41:02 -0600 (Sat, 21 Feb 2009) $
 * $Rev: 12 $
 *
 * Version: 1.0
 *
 * Requires: jQuery 1.2.6+
 */

(function($){
	
$.waiting = {
	version: '1.0'
};

$.fn.extend({

	_opacity : 0.8,
	
	_uniqID : 0,
	
	_random: function() { 
		return new String((new Date()).getTime()).replace(/\D/gi,''); 
	},

	isBusy: function() {
		eval('var res = ' + this.attr('waiting'));
		return this.attr('waiting') && res;
	},
	
	busy: function(className) {	
		this.uniqID = this._random();	
		this.attr('waiting', true);
		var e = $(document.createElement('div'));
		e.attr('id', this._uniqID);								
		e.css('position', 'absolute');
		e.css('opacity', this._opacity);
		e.css('left', this.offset().left);
		e.css('top', this.offset().top);
		e.css('padding', '0px');
		e.css('margin', '0px');
		e.css('width', this.width());
		e.css('height', this.height());
		e.css('z-index', 100);
		if (className) {
			e.addClass(className);		
		} else {
			e.addClass('waiting');
		}
		e.css('display', 'block');
		this.append(e);
	},
	
	free: function() {
		if (this.attr('waiting')) {
			this.attr('waiting', false);
			jQuery('#' + this._uniqID).remove();
		}
	}	
	
});

})(jQuery);
