//$.fn.loadingBox = function(){
//	
//	//alert($(this).attr('id'));
//	
//	$(this).css('position','relative');
//	
//	var box = '<div id="loading" style="display:none; z-index:1000;">'
//		+'	<div class="ui-overlay">'
//		//+'		<div class="ui-widget-overlay"></div>'
//		+'		<div class="ui-widget-shadow ui-corner-all" style="width: 100%; height: 100%; position: absolute; left: 0px; top: 0px;">'
//		+'		</div>'
//		+'	</div>'
//		+'	<div class="ui-widget ui-widget-content ui-corner-all" style="padding: 0px; position: absolute; width: 200px; height: 60px;">'
//		+'		<table style="width:100%;height:100%;" cellspacing="0" cellpadding="0">'
//		+'			<tr>'
//		+'				<td align="center" valign="middle">'
//		+'					<img src="/img/loading.gif" style="vertical-align:middle"/>Caricamento dati'
//		+'				</td>'
//		+'			</tr>'
//		+'		</table>'
//		+'	</div>'
//		+'</div>';
//	$(this).append(box);
//	
//	var left = ($(this).children().eq(1).outerWidth(true)/2) - 100;
//	var top = ($(this).children().eq(1).outerHeight(true)/2) - 30;
//	
//	$('.ui-widget',$(this)).css('left',left+'px');
//	$('.ui-widget',$(this)).css('top',top+'px');
//	
//}



(function($) {
	
	var target = null;
	
	$.extend($.fn, {
		loadingBox2: function(options){
			target = $(this);
			//alert($(this).attr('id'));
			
			switch(typeof options){
				case 'string':
					opts.method[options]();
					break;
				case 'undefined':
				case 'object':
					target = $(this);
					// Costruzione delle proprietà in base a quella passate per parametro
					opts = $.extend({}, $.fn.loadingBox2.defaults, options);
					
					target.css('position','relative');
			
					var box = '<div id="loading" style="display:none; z-index:1000;">'
						+'	<div class="ui-overlay">'
						//+'		<div class="ui-widget-overlay"></div>'
						+'		<div class="ui-widget-shadow ui-corner-all" style="width: 100%; height: 100%; position: absolute; left: 0px; top: 0px;">'
						+'		</div>'
						+'	</div>'
						+'	<div class="ui-widget ui-widget-content ui-corner-all" style="padding: 0px; position: absolute; width: 200px; height: 60px;">'
						+'		<table style="width:100%;height:100%;" cellspacing="0" cellpadding="0">'
						+'			<tr>'
						+'				<td align="center" valign="middle">'
						+'					<img src="/img/loading.gif" style="vertical-align:middle"/>Caricamento dati'
						+'				</td>'
						+'			</tr>'
						+'		</table>'
						+'	</div>'
						+'</div>';
					target.append(box);
					
					return target;
					break;
			}
			
			
			
			
//			var left = ($(this).outerWidth(true)/2) - 200;
//			var top = ($(this).outerHeight(true)/2) - 30;
//			
//			alert(top+' '+left);
//			
//			$('.ui-widget',$(this)).css('left',left+'px');
//			$('.ui-widget',$(this)).css('top',top+'px');
		}, 
		
		loadingBox: function(){
			
			//alert($(this).attr('id'));
			
			$(this).css('position','relative');
			
			var box = '<div id="loading" style="display:none; z-index:1000;">'
				+'	<div class="ui-overlay">'
				//+'		<div class="ui-widget-overlay"></div>'
				+'		<div class="ui-widget-shadow ui-corner-all" style="width: 100%; height: 100%; position: absolute; left: 0px; top: 0px;">'
				+'		</div>'
				+'	</div>'
				+'	<div class="ui-widget ui-widget-content ui-corner-all" style="padding: 0px; position: absolute; width: 200px; height: 60px;">'
				+'		<table style="width:100%;height:100%;" cellspacing="0" cellpadding="0">'
				+'			<tr>'
				+'				<td align="center" valign="middle">'
				+'					<img src="/img/loading.gif" style="vertical-align:middle"/>Caricamento dati'
				+'				</td>'
				+'			</tr>'
				+'		</table>'
				+'	</div>'
				+'</div>';
			$(this).append(box);
			
			var left = ($(this).children().eq(1).outerWidth(true)/2) - 100;
			var top = ($(this).children().eq(1).outerHeight(true)/2) - 30;
			
			$('.ui-widget',$(this)).css('left',left+'px');
			$('.ui-widget',$(this)).css('top',top+'px');
			
		}
	})
	
	
	$.extend($.fn.loadingBox2, {
		defaults : {
			method: {
				'open': function(){
					if(!target.children('#loading').is(':visible')){
						width  = (target.outerWidth(true)/2) -150;
						height = (target.outerHeight(true)/2) - 30;
						
						$('.ui-widget',target).css('left',width+'px');
						$('.ui-widget',target).css('top',height+'px');
						
						target.children('#loading').show();
					}
				}, 
				'close': function(){
					if(target.children('#loading').is(':visible')) target.children('#loading').hide();
				}
			}
		}
	});
	
})(jQuery);

//$.fn.loadingBox2 = function(id_box){
//	
//	//alert($(this).attr('id'));
//	
//	$(this).css('position','relative');
//	
//	var box = '<div id="loading" style="display:none; z-index:1000;">'
//		+'	<div class="ui-overlay">'
//		//+'		<div class="ui-widget-overlay"></div>'
//		+'		<div class="ui-widget-shadow ui-corner-all" style="width: 100%; height: 100%; position: absolute; left: 0px; top: 0px;">'
//		+'		</div>'
//		+'	</div>'
//		+'	<div class="ui-widget ui-widget-content ui-corner-all" style="padding: 0px; position: absolute; width: 200px; height: 60px;">'
//		+'		<table style="width:100%;height:100%;" cellspacing="0" cellpadding="0">'
//		+'			<tr>'
//		+'				<td align="center" valign="middle">'
//		+'					<img src="/img/loading.gif" style="vertical-align:middle"/>Caricamento dati'
//		+'				</td>'
//		+'			</tr>'
//		+'		</table>'
//		+'	</div>'
//		+'</div>';
//	$(this).append(box);
//	
//	var left = ($(this).outerWidth(true)/2) - 200;
//	var top = ($(this).outerHeight(true)/2) - 30;
//	
//	alert(top+' '+left);
//	
//	$('.ui-widget',$(this)).css('left',left+'px');
//	$('.ui-widget',$(this)).css('top',top+'px');
//	
//}
