
(function($){
		  ;
	$.fn.customFadeIn = function(speed, callback) {		
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);

(function($)
{
	$.overlayAlert = function(pParams)
	{
		var params = $.extend({
			
			bgOpacity: 0.4,
			bgColor: '#000000',
			durationFade: 400,
			zIndex:5000,
			baseUrl: 'http://debian.adacto.it/myerg/',
			callback: function(){alert('')}
		},pParams);
		
		var isBlocked = false;
		
		var ie6		= ($.browser.msie && $.browser.version < 7);
		var $body	= $(document.body);
		var $window	= $(window);		
		
		
		
		var $container = $('<div></div>');
		var $opacityBox = $('<div></div>');
		var $content = $(pParams.content);
		
		$content.find('#chiudi_reserved').click(function(){
			removeOverlay();
			return false;
		});
		
		
		
		$window.resize(function(){positionOverlay();});
		
		var positionOverlay = function()
		{
			$container.css({
				width: '100%',
				height: $window.height(),
				position: ((ie6) ? 'absolute' : 'fixed'),
				top:((ie6) ? $window.scrollTop() : 0),
				left:0,
				right:0,
				left:0
			});
			
			$opacityBox.css({
				position: 'absolute',
				top : 0,
				bottom : 0,
				left : 0,
				right : 0,
				width : '100%',
				height: $window.height()
			});
			
			$content.css({
				top: '50%',
				left:'50%',
				position:'absolute',
				marginLeft: ($content.outerWidth() / 2)*-1,				
				marginTop: ($content.outerHeight() / 2)*-1,
				zIndex:5002
			});
			
		};
		
		var styleOverlay = function()
		{
			$container.css({
				zIndex: params.zIndex
			});
			
			$opacityBox.css({
				backgroundColor : params.bgColor,
				opacity: 0,
				zIndex: params.zIndex + 1
			});
		};
		
		
		
		
		$opacityBox.click(function()
		{
			
			removeOverlay();
		});
		
		$opacityBox.appendTo($container);
		$content.appendTo($container);
		$container.appendTo($body);
		
		styleOverlay();
		positionOverlay();
		
		if(ie6)
			$window.scroll(ie6Scroll);
			
		showOverlay();
		
		function ie6Scroll()
		{
			$container.css({
				top: $window.scrollTop()
			});
		}
		
		function showOverlay()
		{
			
			$opacityBox.animate({opacity: params.bgOpacity}, params.durationFade);
			setTimeout(function(){$content.fadeIn(150)},100);
		}
		
		function removeOverlay()
		{
			if(($.browser.msie))
			{
				$content.css('display','none');
				$window.unbind('resize');
				$container.remove();
			}else
			{
				$content.customFadeOut(200);
				$opacityBox.customFadeOut(params.durationFade, function(){
					$window.unbind('resize');
					$container.remove();
				});
			}
		}
	};
})(jQuery);


