$(document).ready(function(){
	      $(function(){
				  $(".click").each(function(){
					  ref = $(this).attr("title");
					  var js = "location.href='"+ ref +"';";
					  var newclick = new Function(js);
					  $(this).attr("title", "");
					  $(this).attr('onclick', '').click(newclick);
					  //$(this).textShadow();
				  });

				  $(".null").hide();
				  
				  $(".clic").textShadow();

				  $(".crop-img").each(function(){
				  img = $(this).attr("src");
				  alt = $(this).attr("alt");
				  h = $(this).attr("height");
				  w = $(this).attr("width");
				  alg = $(this).attr("align");
				  //alert(img);
				  $(this).attr("src", "/tpl/default/images/space.gif");
				  $(this).css("background-image", "url("+img+")");
				  if (alg == "top") {
				  	$(this).css("backgroundPosition", "top center");
				  }else if (alg == "left") {
					$(this).css("backgroundPosition", "left top");
				  }else if (alg == "right") {
					$(this).css("backgroundPosition", "right top");
				  }else {
				  	$(this).css("backgroundPosition", "center center");
				  }
				  $(this).css("background-repeat", "no-repeat");
				  //$(this).append('<img src="/tpl/default/images/space.gif" alt="'+alt+'" border="0"  width="'+w+'" height="'+h+'" style="background:url('+img+') center center no-repeat"  />');
				});
		});
		  $(".vAlign").vAlign();
		  $(".chat").colorbox();
		  $("a[rel='album']").colorbox({slideshow:true});
		  //Funcao verifica form compra***********************************************************
		  $("#enviar").click( function(){ // quando clicar no botao enviar id=enviar
			var nome = $('#nome').val(); // pego o valor do input id nome e coloco na variavel nome
			var telefone = $('#tel').val(); // pego o valor do input id telefone e coloco na variavel
			var total_compra = $('#div_total_compra').text();
			var entrada = $("input[name='entrada']").val();
			var saida = $("input[name='saida']").val();
			var adulto = $("#adulto").val();
			var email = $("#email").val();
			var crianca = $("#crianca").val();
			var titulo = $("#title").val();
			var tipo = $("#tipo").val();
			var adicional = $("input[@name='servicos']:checked").attr("title");
			//telefone
			// passo por parametro as variaveis por post para a segunda pagina e retorno na
			//funçao (data)
			$.post("/php/comprar.php3",{nome: nome, email:email, telefone: telefone, total_compra:total_compra, entrada:entrada, saida:saida, adulto:adulto, crianca:crianca, titulo:titulo, tipo:tipo, adicional:adicional},function(data){
			// recebe a resposta da segunda página dentro da funçao (data)
			$("#retorno").html(data); // retorno dentro da div com id retorno o valor da funcao DATA que é o retorno     processado pela segunda-pagina.php
			document.getElementById('formticket').style.display="none";
			if (document.getElementById('retorno').style.display=="none"){
				document.getElementById('retorno').style.display="block"
			};
			}); // fecho o $.post
		}); // fecho o $("#envar").click( function(){  (clique no botao enviar)
		//FIM Funçao verifica form compra*********************************************************
		$("#fechar").click(function () {
		  $("#visor1").fadeOut("slow");
		  $("#visor2").fadeIn("slow");
		});
		$(".acord").click(function(){
			var v = $(this).attr("name");
			$(this).parent().find('#'+v).slideToggle("slow");
		});
		//$('a[href^="http://"]')	.attr({ target: "_blank" });
});
function alticket(){
	document.getElementById('retorno').style.display="none";
	document.getElementById('formticket').style.display="block";	
};
//Funcao finaliza compra*******************************************************************
function conticket(){
	var retorno = $('#ticket').html();
	var email = $("#email").val();
	$.post("/php/comprar.php3",{retorno: retorno, email:email, tipo:'finaliza'},function(data){
	$("#retorno").html(data);
	}); 
 }; 
//FIM Funçao finaliza compra*******************************************************************

/*function fechar(){
	$('#visor1').hide(2000);
	document.getElementById('visor2').style.display="block";
	};*/
function formatCurrency(num) {
		/* onclick="this.form.input.value=formatCurrency(this.form.input.value);" */
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+'.'+
		num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + 'R$ ' + num + ',' + cents);
}

function CalculaServicos(){	
	  var total = 0;	
	  
		if(document.comprar.CompraServico){
			if(document.comprar.CompraServico.length>1){
			  for (i=0; i<document.comprar.CompraServico.length; i++){ 
			  
				if (document.comprar.CompraServico[i].checked == true) {
					 var str=document.comprar.CompraServico[i].value;
					 var mySplitResult = str.split("@");
					 total += Number(mySplitResult[0]);  
				}
			  }
			 
			}else{
				if (document.comprar.CompraServico.checked == true) {
					 var str=document.comprar.CompraServico.value;
					 var mySplitResult = str.split("@");
					 total += Number(mySplitResult[0]);  
				}
			}
		}
		
	 if(document.comprar.CompraCarbono){
		 if (document.comprar.CompraCarbono.checked==true)
		 { 
			total += Number(document.getElementById("CompraCarbono").value); 
		 }
	 }
				
	  document.comprar.total_servicos.value = total; 
	  
	  var adulto = document.comprar.adulto.value;
	  var crianca = document.comprar.crianca.value;
	  
	  var preco_atrativo =  document.getElementById("preco_atrativo").value;
	  var total_servicos =  document.getElementById("total_servicos").value;
	  var valorTotal = +Number(total_servicos)+Number(preco_atrativo);
	  var valorFinal = valorTotal*Number(adulto);
	  if (crianca>0){
		  if (adulto==2 || adulto==3 &&  crianca>=1){			  
		  var valorCrianca = Number(valorTotal)/2;
		  valorFinal = valorFinal+valorCrianca+(Number(valorTotal)*(crianca-1));
		  }
		  if (adulto==4 || adulto==5 &&  crianca>=2){			  
		  var valorCrianca = (Number(valorTotal)*2)/2;
		  valorFinal = valorFinal+valorCrianca+(Number(valorTotal)*(crianca-2));
		  }
		  if (adulto==1){			  
		  var valorCrianca = Number(valorTotal)*crianca;
		  valorFinal = valorFinal+valorCrianca;
		  }
	  }
	  $("#visor1").fadeIn("slow");
	  document.getElementById('visor2').style.display="none";
	  var total_compra =  document.getElementById("total_compra").value = valorFinal;
	  //alert(document.getElementById("total_compra").value);
	  //alert(crianca);
	  document.getElementById('div_total_compra').innerHTML = formatCurrency(valorFinal);
  
}
 $(function(){
	$("#calendar").datepicker({
		dateFormat: 'dd/mm/yy',
		dayNames: [
			'Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'
		],
		dayNamesMin: [
			'D','S','T','Q','Q','S','S','D'
		],
		dayNamesShort: [
			'Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'
		],
		monthNames: [
			'Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro',
			'Outubro','Novembro','Dezembro'
		],
		monthNamesShort: [
			'Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set',
			'Out','Nov','Dez'
		],
		nextText: 'Próximo',
		prevText: 'Anterior'

	});
$("#calendar2").datepicker({
		dateFormat: 'dd/mm/yy',
		dayNames: [
			'Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'
		],
		dayNamesMin: [
			'D','S','T','Q','Q','S','S','D'
		],
		dayNamesShort: [
			'Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'
		],
		monthNames: [
			'Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro',
			'Outubro','Novembro','Dezembro'
		],
		monthNamesShort: [
			'Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set',
			'Out','Nov','Dez'
		],
		nextText: 'Próximo',
		prevText: 'Anterior'

	});
 });
 function popup(href,windowname,w,h,s){
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		var targetWin = window.open (href, windowname, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='+s+', resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
 };
