// JavaScript Document
var fundoSetado=0;
var zindex_fundo = 10;

jQuery.fn.extend({ 
	  setFundo: function()
	  { 
			var script = '<div id="fundo" style="position:fixed; width:100%; z-index:10; height:100%; background-color:#000000;opacity: 0.20;filter:alpha(opacity=20); left:0; top:0; display:none;">&nbsp;</div>';
			this.append(script);	
	  }
	});


jQuery.fn.extend({ 
	  janela: function(id, titulo, img, width, height, url, mae)
	  { 
			if(fundoSetado == 0)
			{
				$("body").setFundo();
				fundoSetado = 1;
			}
			
			var margin_left = width / 2;
			var margin_top = height / 2;
			
			var script = '<div id="'+id+'" class="janela" style="z-index:20; width:'+width+'px; height:'+height+'px; position:absolute; top: 50%; left: 50%; margin-top: -'+margin_top+'px; margin-left: -'+margin_left+'px; background-color:#FFFFFF; border:1px solid #DCDCDC; display:none; overflow:hidden;">';
			script += '<div id="'+id+'_titulo" style="height:8px; padding: 5px 7px 5px 7px;" >';
			script += '   	<div style="float:right">';
			script += '			<div style="text-decoration:underline; cursor:pointer; font-family:Arial, Helvetica, sans-serif; font-size:10px;" onclick="$(\'#'+id+'\').close(\'' + mae + '\');$(\'#fundo\').close();">Fechar (X)</div>';
			script += '   	</div>';
			script += '</div>';
			script += '<div id="'+id+'_conteudo" style="height:'+(height-45)+'px; padding: 0px 7px 7px 7px; overflow: hidden;">';
			script += ' </div> ';
			script += ' <input type="hidden" id="'+id+'_url" value="'+url+'" />';
			script += ' </div>';
			
			this.append(script);

	  }
	});

	jQuery.fn.extend({ 
	  close: function(mae, id)
	  { 
			if (mae != 'undefined')
			{
				this.hide();	
				$('#' + mae).css('z-index','20');						
				if (id != 'undefined')
				{
					this.hide();	
					$('#'+id+'_conteudo').html("");
				}				
			}
			else
			{
				this.hide();	
				$('#fundo').hide();
				$('#'+this.attr("id")+'_conteudo').html("");
				$("#janelas_ficha").html("");
			}
	  }
	});
	
	jQuery.fn.extend({ 
	  open: function(tipo, mae)
	  { 
	  	if (tipo == 'child')
		{
	  		$("html, body").animate({scrollTop:0 }, function(){});
			$('#'+this.attr("id")+'_conteudo').html('<div style="text-align:center; font-size: 12px; background: #F0F0F0; width: 100%; padding-top: 150px; height: 1000px"><img src="../images/load2.gif" /><br><b>Carregando...</b></div>');

			$('#'+this.attr("id")+'_conteudo').html("<iframe src='" + $('#'+this.attr("id")+'_url').val() + "' width='550px'  height='470px' frameborder='0'>");			
			$('#' + mae).css('z-index','5');						
			this.show();	
			$('#fundo').show();				
		}
		else
		{
	  		$("html, body").animate({scrollTop:0 }, function(){});
			$('#'+this.attr("id")+'_conteudo').html('<div style="text-align:center; font-size: 12px; background: #F0F0F0; width: 100%; padding-top: 150px; height: 1000px"><img src="http://www.buscaimo.com.br/rede_campinas/images/load2.gif" /><br><b>Carregando...</b></div>');
			$('#'+this.attr("id")+'_conteudo').load($('#'+this.attr("id")+'_url').val());			
			this.show();	
			$('#fundo').show();	
		}
	  }
	});

