<!--
/* Overlay Box
Criado em: 2009/05/08
Empresa: www.fluence.com.br
Programador: www.rafaeldouglas.com

Alterado em: 2009/09/03
*/

// Funcçoes Gerais
// Funcção chamada pelo flash
function overlayBox(URL, w, h){	
	// Estrutura HTML
		
	var boxStucture  
	= '<div id="overlayBox"></div>'
	+ '<div id="containerBox">'
	+ '	<a id="overlayBoxClose" title="Fechar">&nbsp;</a>'
	+ '	<div id="containerData"></div>'
	+ '</div>'
	
	// Adiciona estrutura a página
	$("body").append(boxStucture);
	
	$("#overlayBox").css({
		opacity: 0.8 ,
		filter: "alpha(opacity=80)"
	});
	
	// Conteúdo da estrutura
	$.ajax({
		type: "GET",
		url: URL,
		cache: false,
		//data: queryString,			
		beforeSend: function()
		{
			//content.html('');
			//btn.prepend("<img class='img-loader' src='../../../imgs/icones/ico_loading.gif' />");
			//btn.find(".img-loader").fadeIn();
		},
		success: function(data)
		{
			//btn.find(".img-loader").fadeOut(function(){$(this).remove()});
			// Insere o conteúdo da página
			//$("#containerData").html(data);
			dataBox = data;
		},
		error: function(data)
		{
			$("#containerData").html(data.responseText);
			w = 300;
			h = 60;
			dataBox = "<span style='float: left; width:100%; padding: 20px 0px; font-size: 16px;'>Ops, um erro!</span>"
		},
		complete: function()
		{			
			animateOverlay(w,h);
		}		
	});
	
	// Ajuste de layout
	overlayAjust();
	
	$("#overlayBoxClose").click(overlayBoxClose);
	jQuery(document).bind("keypress", function(e) {
	  var code=e.charCode || e.keyCode;
	  if(code==27){
		overlayBoxClose();
		jQuery(document).unbind();
	  }
	});
}

function overlayAjust(){
	$('#overlayBox').css({
		//opacity: 0.80,
		//filter: "Alpha(Opacity=80)",
		//width: $(document).width(),// - (jQuery.browser.msie6?21:0),
		width: $(window).width() - (jQuery.browser.msie6?21:0),
		height: $(document).height()
	});
}

function overlayBoxClose() {
	$('#containerBox').remove();
	$('#overlayBox').fadeOut(150,function(){
		$('#overlayBox').remove();
		// Exibe obejtos conflitantes
		$('embed, object, select').css({ 'visibility' : 'visible' });	
	});
}

jQuery(window).resize(function(){
	 overlayAjust();							  
});


function containerClick (){
	$("#containerData .overlayClick").click(function(evt){
		evt.preventDefault();
		obj = $(this);
		URL = obj.attr("href");		
		boxSize = obj.attr("rel").split(',');		
		w = boxSize[0];
		h = boxSize[1];
	
		$.ajax({
			type: "GET",
			url: URL,
			cache: false,
			//data: queryString,			
			beforeSend: function()
			{
				$("#containerData").empty();
				//content.html('');
				//btn.prepend("<img class='img-loader' src='../../../imgs/icones/ico_loading.gif' />");
				//btn.find(".img-loader").fadeIn();
			},
			success: function(data)
			{
				//btn.find(".img-loader").fadeOut(function(){$(this).remove()});
				// Insere o conteúdo da página
				//$("#containerData").html(data);
				dataBox = data;
			},
			error: function(data)
			{
				$("#containerData").html(data.responseText);
				w = 280;
				h = 200;
				dataBox = "<p style='padding-top:80px;'>Ops!</p>"
			},
			complete: function()
			{		
				animateOverlay(w,h);
			}		
		});
	});
}


function submitForm(){
	$("form").bind("submit",function(evt){
		evt.preventDefault();
		obj = $(this);
		URL = obj.attr("action");
		boxSize = $("#rel").val().split(',');	
		
		w = boxSize[0];
		h = boxSize[1];
		
		$.ajax({
			type: "POST",
			url: URL,
			cache: false,
			data: obj.serialize(),			
			beforeSend: function()
			{
				$("#containerData").empty();
				//content.html('');
				//btn.prepend("<img class='img-loader' src='../../../imgs/icones/ico_loading.gif' />");
				//btn.find(".img-loader").fadeIn();
			},
			success: function(data)
			{
				//btn.find(".img-loader").fadeOut(function(){$(this).remove()});
				// Insere o conteúdo da página
				//$("#containerData").html(data);
				dataBox = data;
			},
			error: function(data)
			{
				$("#containerData").html(data.responseText);
				w = 280;
				h = 200;
				dataBox = "<p style='padding-top:80px;'>Ops!</p>"
			},
			complete: function()
			{		
				animateOverlay(w,h);
			}		
		});
	});
}

// redimensiona o overlay Box
function animateOverlay(w,h){
	$('#overlayBox').fadeIn(300, function(){			
		$('#containerBox').animate({
		width:w,
		marginLeft: (w*0.5)*-1,
		height:h,
		marginTop:(h*0.5)*-1},
		600,
		function(){
			$('#containerData').html(dataBox).fadeIn(200);
			$('#containerBox').css("background-image","none");					
		});
	});
}
-->
