// JavaScript Document


/* 
	Modal Mensagem
*/
/** Corta as margens do elemento definido em numItens **/

function cortaMargem(div, numItens, valorNovo, margem) {
	switch (margem) {
	case 'esquerda':
		margem = 'marginLeft';
		break;
	case 'superior':
		margem = 'marginTop';
		break;
	case 'inferior':
		margem = 'marginBottom';
		break;
	case 'direita':
		margem = 'marginRight';
		break;
	}
	$(div).each(function () {
		var pos = $(this).index(div) + 1;
		if (pos % numItens == 0) {
			$(this).css(margem, valorNovo);
		}
	});
}
function modal(tipo,msg1,msg2,msg3,msg4) {

	
	var chamdas = ' \
		<!-- Chamadas de Sucesso e Erro --> \
		<a id="chamadaErro" href="#respostaErro" rel="prettyPhoto" style="display:none;">Chamada Erro</a> \
		<a id="chamadaSucesso" href="#respostaSucesso" rel="prettyPhoto" style="display:none;">Chamada Sucesso</a>';

	
	var sucesso = '	\
		<!-- Mensagens de Sucesso e Erro --> \
		<!-- Mensagem de Sucesso INICIO--> \
		<div id="respostaSucesso" style="display:none;height:220px;"> \
			<div style="width: 516px;float: left; padding-top: 20px;text-align:center;"> \
				<img width="107" height="107" style="margin:0 auto;" src="img/icoAcerto.png" alt=""/> \
				<p style="width: 516px; font-family:Arial, Helvetica, sans-serif; font-size: 17px; color:#333333; display: block; margin-top: 25px;">'+msg1+'<br> \
					<br> \
					'+msg2+' </p> \
				<p style="width: 516px; font-family:Arial, Helvetica, sans-serif; font-size: 13px; color:#333333; display: block;"> '+msg3+' \
					'+msg4+'</p> \
			</div> \
		</div> \
		<!-- Mensagem de Sucesso FIM-->';
		
 	var erro = ' \
		<!-- Mensagem de Erro INICIO--> \
		<div id="respostaErro" style="display:none;height:220px;"> \
			<div style="width: 516px;height:120px;float:left;padding-top: 20px;text-align:center;"> \
				<img src="img/icoErro.png" width="90" height="89" style="margin:0 auto;" alt=""/> \
				<p style="width: 516px; font-family:Arial, Helvetica, sans-serif; font-size: 17px; color:#333333; display: block; margin-top: 25px;"> '+msg1+'<br> \
					<br> \
					'+msg2+' </p> \
				<p style="width: 516px;font-family:Arial, Helvetica, sans-serif; font-size: 13px; color:#333333; display: block;"> '+msg3+' \
					'+ msg4 +' </p> \
			</div> \
		</div> \
		<!-- Mensagem de Erro FIM-->';
	if ($("#respostaErro").html() == null)	 {
		$("body").append(erro);
		$("body").append(sucesso);
		$("body").append(chamdas);			
	}

	
	$("#chamadaSucesso,#chamadaErro").prettyPhoto({theme:'inclub',default_width:516,show_title:false,allow_resize:false});	
	
	if (tipo == "sucesso") {
		$("#chamadaSucesso").trigger("click");
	} else if (tipo == "erro") {
		$("#chamadaErro").trigger("click");				
	}
	
}
/*
	Configura o formulário de cadastro.
*/

function configuraForm() {
		var posForm = 0;
		$("#formulario #campos ul li").hide();
		$("#formulario #campos ul li:eq(0)").fadeIn(1000);
		$("#formulario #campos a.proximoPasso").click(function(){
		    erro = false;
		
			$(this).parent().find(".obrigatorio").each(function(){
				if ($(this).val() == "") {
					$(this).css("background-color","#ff9595");
					erro = true;
					
				}
			});
			if (erro){
				$(this).parent().find(".mensagem").css("color","#b62222")
				$(this).parent().find(".mensagem").html("* Campos de preenchimento obrigatorio");
			} else {
				$(this).parent().find(".obrigatorio").each(function(){
					if ($(this).css("background-color") == "#ff9595" || $(this).css("background-color") == "rgb(255, 149, 149)"){
						$(this).css("background-color","#FFF");
					};

				});				
				$(this).parent().hide();
				$(this).parent().next().fadeIn("500");
				$("#formulario #abas #marca").animate({marginTop: '+=35'},500)
			}
		});
		$("#formulario #abas ul li").css("cursor","pointer");
		$("#formulario #abas ul li").click(function(){
			var pos = $(this).parent().children().index($(this));
			if (pos == 0) {
				$("#formulario #abas #marca").animate({marginTop: '1'},500)
				$("#formulario #campos ul li").hide();
				$("#formulario #campos ul li:eq(0)").fadeIn("500");
				return;
			}
			pos = pos -1;
			erro = false;

			$("#formulario #campos ul li:eq("+pos+")").find(".obrigatorio").each(function(){
				if ($(this).val() == "") {
					$(this).css("background-color","#ff9595");
					erro = true;
				}				
			});

			if (erro == false) {
				pos = pos + 1;
				mov = (pos * 35)+ 1;
				$("#formulario #abas #marca").animate({marginTop: mov},500)
				$("#formulario #campos ul li").hide();
				$("#formulario #campos ul li:eq("+pos+")").fadeIn("500");
			}
			
			
			
		});
		$("#formulario #campos input.enviar").css("cursor","pointer");
		$("#formulario #campos input.enviar").click(function(){
			erro == false;
			
			$("#formulario #campos ul li").find(".obrigatorio").each(function(){
				if ($(this).val() == "") {
					$(this).css("background-color","#ff9595");
					erro = true;
				}								
			});
			
			if (erro){
				$(this).parent().find(".mensagem").css("color","#b62222")
				$(this).parent().find(".mensagem").html("* Campos de preenchimento obrigatorio");
			} else { 
				$(this).parent().parent().parent().parent().find("form").submit();
			}
		});
		
}


function bannerHome(){

		/** Código Bruno
		*$("#banner .esquerda img").css("cursor","pointer");
		$("#banner .direita img").css("cursor","pointer");
		$("#banner .esquerda img").click(function(){
			$("#banner .centro .chamadas ul").animate({left: '+=822'}, 700);
		});
		$("#banner .direita img").click(function(){
			$("#banner .centro .chamadas ul").animate({left: '-=822'}, 700);
		});*/
		
		$("#banner .chamadas").jCarouselLite({
			btnNext: "#banner .direita img",
			btnPrev: "#banner .esquerda img",
			scroll: 1,
			visible:1,
			auto: 8500,
			speed: 1000
		});
		$("#banner .chamadas li").each(function(){
			if($(this).find("img").index() != 0){
				$(this).find("div").css({
					'marginLeft':'40px',
					'width':'745px'
				});
			}
		});

}

function convenioFotos() {
	$(".convenio").each(function(i){
		var pos = i+1;
		$(this).find('.fotos').addClass('convenio'+pos);
	});
	$(".convenio").each(function(i){
		var pos = i+1;
		$(this).find(".convenio"+pos).jCarouselLite({
			btnNext: ".convenio"+pos+" .navegacao .dirNav",
			btnPrev: ".convenio"+pos+" .navegacao .esqNav",
			scroll: 1,
			visible:1,
			auto: false,
			speed: 1000
		});		
	});
	$(".convenio").each(function(i){
			var pos = i+1;
			var numFotos = $(".convenio"+pos+" .foto ul li").length-2;
			var numCorrente = $(".convenio"+pos+" .foto ul li img").attr("alt");
			$(".convenio"+pos+" .navegacao .paginas .total").html(numFotos);
							
			$(".convenio"+pos+" .navegacao .dirNav").click(function(){
				var coord = $(".convenio"+pos+" .foto ul").css("left").replace("px","");
				var corrente = Math.round(((coord / 278) * -1) +1);
				if(corrente == numFotos + 1) corrente = 1;
				$(".convenio"+pos+" .navegacao .paginas .corrente").html(corrente);
			});
			$(".convenio"+pos+" .navegacao .esqNav").click(function(){
				var coord = $(".convenio"+pos+" .foto ul").css("left").replace("px","");
				var corrente = Math.round(((coord / 278) * -1)-1);
				if(corrente == numFotos + 1) corrente = 1;
				if(corrente == 0) corrente = numFotos;
				$(".convenio"+pos+" .navegacao .paginas .corrente").html(corrente);
			});
		
	});
	

}
variacaoFonte = 0;
function tamanhoFontes() {
	$(".fonteMais").click(function() {
	
		variacaoFonte++;
		aumentaFonte();
	});
	
	$(".fonteMenos").click(function() {
	
		variacaoFonte--;
		diminuiFonte();
	});
	
	

}

function aumentaFonte(){
	$("*").each(function(){
		var size = $(this).css("font-size");
		size = size.replace("px","");
		if (size > 0) {
			if (variacaoFonte > 5) {
				soma = parseInt(size) - 5;
				$(this).css("font-size",soma+"px");
				
			} else {
				soma = parseInt(size) + 1;
				$(this).css("font-size",soma+"px");
			}
			
		}
	
	});
	if (variacaoFonte > 5) {
		variacaoFonte = 0;
	}

}
function diminuiFonte(){
	$("*").each(function(){
		var size = $(this).css("font-size");
		size = size.replace("px","");
		if (size > 0) {
			if (variacaoFonte < -5) {
				soma =  parseInt(size) + 5;
				$(this).css("font-size",soma+"px");
				
			} else {
				soma = parseInt(size) - 1;
				$(this).css("font-size",soma+"px");
			}
			
		}
	
	});
	if (variacaoFonte < -5) {
		variacaoFonte = 0;
	}

}
function voltaFonte(){
	$("*").each(function(){
		alert(variacaoFonte);
		var size = $(this).css("font-size");
		size = size.replace("px","");
		if (size > 0) {
			soma = parseInt(size) - parseInt(variacaoFonte);
			$(this).css("font-size",soma+"px");
		}
		variacaoFonte = 0;
	
	});

}
 

