jQuery.fn.box=function(opt){

	if(opt==null){
		opt = { title : ''};
	}
	
	$(this).each(function(){
	
		if($(this).hasClass('box'))return;
		$(this).addClass('box');
		
		$(this).append('<div class="top" style="position:relative;">'
							+opt.title+'<span class="ui-icon ui-icon-circle-close close"  />'
						+'</div>'
						+'<div class="body"><div class="contents" style="overflow:auto"><div>');
		
		if(opt.close!=null){
			$(this).find('.top .close').click(opt.close);
		}
		
		$(this).find('.top .close')
			.css({
					cursor : 'pointer',
					position: 'absolute',
					top : '8px',
					right : '4px'
				})
			.click(function(){
					$(this).parents('.box:first').remove(); 
				});
		
		
		
		
		$(this).section();
		
		
		$(this).find('.top:first').css('cursor','move')
				.mousedown(function(){ 
			  		$(this).parent().draggable({ 
			  			opacity: 0.85, 
			  			stop: function(event,ui){ $(this).draggable('destroy');}
			  		}); 
				})
				.hover(function(){
						$(this).addClass('ui-state-hover');
					},
					function(){
						$(this).removeClass('ui-state-hover');
					}
				);
		
		$(this).mousedown(function(){
			$('.section').css('z-index','1000').removeClass('active').find('.top:first').removeClass('ui-state-active');
			
			$(this).css('z-index','2000').addClass('active').find('.top:first').addClass('ui-state-active');
		});
		
		
		
		$(this).find('.body').resizable({
			
			resize: function(){
				//spoiler
				var section = $(this).parent();
				section.width($(this).width()+22);
				section.height($(this).height()+22);
				section.find('.top table:first').width($(this).width()-10);
				section.find('.contents').height(section.height()-20);
			}
		});
		
		$(this).css('position','absolute');
		$(this).mousedown();
		return this;
		
	});
}

//chiedere al ced
/*keyboard.addEvent([27],function(){
	$('.box').filter('.active').remove();
});*/
//commentato da Simone Pavlovich 31/03/2010