jQuery.extend({
	
	popup_fechar: function(){
		$("#ppsombra").fadeTo("fast",0,function(){
			$("#ppsombra").remove();
		});
		$("#ppcontainer").fadeTo("fast",0,function(){
			$("#ppcontainer").remove();
		});
	},
	
	popup: function(url,largura,altura){
		
		var body = $("body").get(0);
		var pageSize = Size.getPageSize();
		var pageScroll = Size.getPageScroll();
		
		/* DIMENSOES INICIAIS */
		var width_ini = 100;
		var height_ini = 100;
		
		/* DIMENSOES FINAIS */
		var width_fim = largura;
		var height_fim = altura + 30;
		
		/* POSICOES INICIAIS */
		var posx_ini = parseInt((pageSize.pageWidth - width_ini - 40) / 2);
		var posy_ini = parseInt(pageScroll.yScroll + ((pageSize.windowHeight - height_ini - 35) / 2));
		
		/* POSICOES FINAIS */
		var posx_fim = parseInt((pageSize.pageWidth - width_fim - 40) / 2);
		var posy_fim = parseInt(pageScroll.yScroll + ((pageSize.windowHeight - height_fim - 35) / 2));
		
		/* SOMBRA */
		var sombra = document.createElement("div");
		$(sombra).attr("id","ppsombra");
		$(sombra).css({
			height: pageSize.pageHeight,
			opacity: 0
		});
		
		$(sombra).click(function(){
			$.popup_fechar();
		});

		$(sombra).appendTo(body);
		$(sombra).fadeTo("fast",0.8);
		
		/* CONTAINER RECEPTOR */
		var receptor = document.createElement("div");
		$(receptor).attr("id","ppreceptor");
		$(receptor).css({
			opacity: 0
		});
		
		var loader = document.createElement("div");
		$(loader).addClass("loader");
		
		var fechar = document.createElement("a");
		$(fechar).attr({
			id: "ppbtnfechar",
			href: "javascript:void(null)"
		});
		
		$(fechar).click(function(){
			$.popup_fechar();
		});
		
		$(fechar).css("opacity",0);
		$(fechar).text("Fechar");
		
		/* CONTAINER */
		var container = document.createElement("div");
		$(container).attr("id","ppcontainer");
		
		$(container).css({
			left: posx_ini,
			top: posy_ini,
			width: width_ini,
			height: height_ini,
			opacity: 0
		});
		
		$(loader).appendTo(container);
		$(fechar).appendTo(container);
		$(receptor).appendTo(container);
		$(container).appendTo(body);
		
		$(container).fadeTo("fast",1);
		
		$.ajax({
			url: url,
			type: "GET",
			complete: function(xmlhttp){
				$("div.loader").remove();
				$(receptor).html(xmlhttp.responseText);
				$(container).animate({
					width: width_fim,
					height: height_fim,
					left: posx_fim,
					top: posy_fim
				},500,function(){
					$(receptor).animate({
						opacity: 1
					},function(){
						$(fechar).animate({
							opacity: 1
						});
					});
				});
			}
		});
	}
});