$(function(){
	
	/* ------------------------------- AJAX BIND LOADER ------------------------------- */
	
	$.prettyLoader({	
			animation_speed	: 'fast',
			bind_to_ajax	: true, 
			delay			: false,
			loader			: 'images/prettyLoader/ajax-loader.gif',
			offset_top		: 13,
			offset_left		: 10,
			text			: ''
	});
	
	
	/* ------------------------------- SLIDER DA HOME ------------------------------- */
	
	$('.slideshow').nivoSlider({
			controlNav	: true,
			directionNav: false,
			pauseTime	: 6000	
    	});
	
	
	
	$('table.pricing tr:odd').find('td').addClass('even');

	
	
	/* ------------------------------- RECURSOS ------------------------------- */
	
	$('div.recurso').hide();
	$('div.recurso:first').show();
	$('#nav3 li a:first').addClass('active');
	
	$('#nav3 li a').click(function(){
		
		$('div.recurso').hide();
		$('#nav3 li a').removeClass('active');
		
		$(this).addClass('active');
		$($(this).attr('href')).fadeIn(550);
		
		return false;	
		
	});
	
	$('#nav4 li a:first').addClass('active');
	
	$('#nav4 li a').click(function(){
		
		$('div.recurso').hide();
		$('#nav4 li a').removeClass('active');
		
		$(this).addClass('active');
		$($(this).attr('href')).fadeIn(550);
		
		return false;	
		
	});
	
	/* ------------------------------- LIGHTBOX ------------------------------- */
	
	$('.box-portfolio .bt-vejamais').click(function(){
		lightBOX($(this));	
	});
	$('.btn-fechar').click(function(){
		$('#overlayLb').fadeOut(350);
		return false;	
	});
	
	
	/* ------------------------------- TESTEMUNHOS DA HOME ------------------------------- */
	
	
	 $('.depoimentos-home').cycle({
		    fx      : 'fade', 
            speed   : '800', 
            timeout : 8000,
            pager   : '.paginacao'
		  });
	
	
	
	/* ------------------------------- INPUTS ------------------------------- */

	
	$('.cpf-mask').mask('999.999.999-99',{placeholder:" "});
	$('.cep-mask').mask('99999-999',{placeholder:" "});
	$('.cnpj-mask').mask('99.999.999/9999-99',{placeholder:" "});
	$('.tel-mask').mask('(99)9999-9999',{placeholder:""});
	
	
	$('input[type="text"]').focus(function(){
		$(this).parent().find('.i-e').addClass('i-e-h');
		$(this).parent().find('.i-d').addClass('i-d-h');	
	});
	
	$('input[type="text"]').blur(function(){
		$(this).parent().find('.i-e').removeClass('i-e-h');
		$(this).parent().find('.i-d').removeClass('i-d-h');	
	});
	
	$('input[name="nome"]').focus(function(){
		var val = $(this).val();
		if (val == "Nome"){$(this).val('');}
	});
	$('input[name="nome"]').blur(function(){
		
		var val = $(this).val();
		if (val == ""){$(this).val('Nome');}
	});
	
	$('input[name="email"]').focus(function(){
		var val = $(this).val();
		if (val == "Email"){$(this).val('');}
	});
	$('input[name="email"]').blur(function(){
		var val = $(this).val();
		if (val == ""){$(this).val('Email');}
	});
	
	$('input[name="telefone"]').focus(function(){
		$(this).mask('(99) 9999-9999',{placeholder:""});
		var val = $(this).val();
		if (val == "Telefone"){$(this).val('');}	
	});
	$('input[name="telefone"]').blur(function(){
		var val = $(this).val();
		if (val == "" || val == "()-)"){$(this).val('Telefone');}
		
	});
	
	$('input[name="conheceu"]').focus(function(){
		var val = $(this).val();
		if (val == "Como nos conheceu?"){$(this).val('');}
	});
	$('input[name="conheceu"]').blur(function(){
		var val = $(this).val();
		if (val == ""){$(this).val('Como nos conheceu?');}
	});
	
	$('textarea[name="mensagem"]').focus(function(){
		var val = $(this).val();
		if (val == "Digite sua Mensagem"){$(this).val('');}
	});
	$('textarea[name="mensagem"]').blur(function(){
		var val = $(this).val();
		if (val == ""){$(this).val('Digite sua Mensagem');}
	});
		
		
	/* ------------------------------- BOTÃO DE TEMAS ------------------------------- */	
		
	$('.bt-tema').click(function(){
		var tema 	= $(this).find('a').attr('rel');
		var preco	= $(this).find('a').attr('title');
		
		$('.bt-tema').removeClass('bt-tema-ativo');
		
		$('input[name="preco_tema"]').val(preco);
		$('input[name="tema_escolhido"]').val(tema);
		
		$(this).addClass('bt-tema-ativo');
		
		return false;
	});	
		
	
	/* ------------------------------- BOTÃO DE PLANOS ------------------------------- */
	
	$('.bt-p').click(function(){
		
		var plano 	= $(this).find('a').attr('rel');
		var preco	= $(this).find('a').attr('title');
		
		$('.bt-p').removeClass('bt-plano-ativo');
		$('input[name="preco_plano"]').val(preco);
		$('input[name="plano_escolhido"]').val(plano);
		$(this).addClass('bt-plano-ativo');	
		
		return false;
	});	
	

	/* ------------------------------- ABAS DA CONTRATAÇÃO ------------------------------- */
	
	$('.etp').hide();
	$('.etp:first').show();
	
	$('#etapas ul li a').click(function(){
		return false;	
	});	
	
	/* ------------------------------- ENVIAR ORÇAMENTO ------------------------------- */
	
	$('form[name="contato"]').submit(function(){
		
		// Setando Paramêtros de erro e das etapas
		// ----------------------------------------
		
		var erro				= 0;
		var erro2				= 0;
		var erro3				= 0;
		var erro4				= 0;
		var etapa1				= false;
		var etapa2				= false;
		var etapa3				= false;
		var etapa4				= false;
		
		
		// Capturando dados do Formulário
		// -------------------------------
		
		var nome_responsavel	= $('input[name="nome_responsavel"]').val();
		var cpf					= $('input[name="cpf"]').val();
		var razao_social		= $('input[name="razao_social"]').val();
		var cnpj				= $('input[name="cnpj"]').val();
		var telefone1			= $('input[name="telefone1"]').val();
		var telefone2			= $('input[name="telefone2"]').val();
		var email_geral			= $('input[name="email_geral"]').val();
		var cep					= $('input[name="cep"]').val();
		var endereco			= $('input[name="endereco"]').val();
		var numero				= $('input[name="numero"]').val();
		var complemento			= $('input[name="complemento"]').val();
		var bairro				= $('input[name="bairro"]').val();
		var cidade				= $('input[name="cidade"]').val();
		var estado				= $('select[name="estado"]').val();
		var email_tecnico		= $('input[name="email_tecnico"]').val();
		var email_cobranca		= $('input[name="email_cobranca"]').val();
		var possui_dominio		= $('input[name="possui_dominio"]:checked').val();
		var dominio				= $('input[name="dominio"]').val();
		var registrar_dominio	= $('input[name="registrar_dominio"]:checked').val();
		var plano_escolhido		= $('input[name="plano_escolhido"]').val();
		var tema_escolhido		= $('input[name="tema_escolhido"]').val();
		var preco_plano			= $('input[name="preco_plano"]').val();
		var preco_tema			= $('input[name="preco_tema"]').val();
		
		var aceita_termos		= $('input[name="aceita_termos"]:checked').val();
		
		
		
		
		var	etapa				= $('input[name="etapa"]');
		
		
		if (etapa.val() == "#etapa1")
		{
			vEtapa1(); // Executa função de verificação da etapa 1
			
			if (vEtapa1() == "etapa2")
			{
				$('#etapas').addClass('e2');
				etapa.val('#etapa2');
				$('.etp:visible').fadeOut(300,function(){
					$('#etapa2').fadeIn(300);	
				});
			}
			
			return false;	
		}
		else if (etapa.val() == "#etapa2")
		{
			vEtapa2(); // Executa função de verificação da etapa 2
			
			if (vEtapa2() == "etapa3")
			{
				$('#etapas').removeClass('e2');
				$('#etapas').addClass('e3');
				etapa.val('#etapa3');
				$('.etp:visible').fadeOut(300,function(){
					$('#etapa3').fadeIn(300);	
				});
			}
			
			return false;	
		}
		else if (etapa.val() == "#etapa3")
		{
			vEtapa3(); // Executa função de verificação da etapa 3
			
			if (vEtapa3() == "etapa4")
			{
				$('#etapas').removeClass('e2');
				$('#etapas').removeClass('e3');
				$('#etapas').addClass('e4');	
				etapa.val('#etapa4');
				$('.etp:visible').fadeOut(300,function(){
					$('#etapa4').fadeIn(300);	
				});
				
				etapa.addClass('finalizar');
			}
			
			return false;	
		}
		else if (etapa.val() == "#etapa4")
		{
			vEtapa4(); // Executa função de verificação da etapa 4
			
			if (vEtapa4() == "concluido")
			{
				
				etapa.val('#concluido');
				$('.etp:visible').fadeOut(300,function(){
					$('#concluido').fadeIn(300);	
				});
				
				etapa.click(function(){
					location.href = 'index.php';
				})
				
				etapa.removeClass('finalizar');
				etapa.addClass('voltar');
				
					$.post(
					'salva-orcamento.php',
					{
						nome_responsavel	: nome_responsavel,
						cpf					: cpf,
						razao_social		: razao_social,
						cnpj				: cnpj,
						telefone1			: telefone1,
						telefone2			: telefone2,
						email_geral			: email_geral,
						cep					: cep,
						endereco			: endereco,
						numero				: numero,
						complemento			: complemento,
						bairro				: bairro,
						cidade				: cidade,
						estado				: estado,
						email_tecnico		: email_tecnico,
						email_cobranca		: email_cobranca,
						possui_dominio		: possui_dominio,
						dominio				: dominio,
						registrar_dominio	: registrar_dominio,
						plano_escolhido		: plano_escolhido,
						tema_escolhido		: tema_escolhido,
						preco_plano			: preco_plano,
						preco_tema			: preco_tema
					},
					
					function (resposta)
					{
					
					}
			
				);
			}
			
			return false;	
		}
			
			/**/
		
		return false;
	});
	
		
});



/* ------------------------------- LIGHTBOX ------------------------------- */

function lightBOX(elem)
{
		var $tseo	= $(elem).attr("rel");
		var $ant	= $(this).parent().parent().prev('.portfolio').find('.bt-vejamais').attr('rel');
		var $prox	= $(this).parent().parent().next('.portfolio').find('.bt-vejamais').attr('rel');

		$.post(
			'lightbox.php',
			{
				tseo	: $tseo,
				ant		: $ant,
				prox	: $prox
			},
			function (resposta)
			{
				$('div').addClass('zIndex30');
				$('#lb').empty().append(resposta).css('zIndex','9999').fadeIn(350);	
			}
		);
		
		return false;	
}

function fechar()
{		
	$('#overlayLb').fadeOut(350,function(){
		$('div').removeClass('zIndex30');	
	});
	
	return false;
}



function vEtapa1()
{
	var erro = 0;
	
		var nome_responsavel	= $('input[name="nome_responsavel"]').val();
		var cpf					= $('input[name="cpf"]').val();
		var razao_social		= $('input[name="razao_social"]').val();
		var cnpj				= $('input[name="cnpj"]').val();
		var telefone1			= $('input[name="telefone1"]').val();
		var telefone2			= $('input[name="telefone2"]').val();
		var email_geral			= $('input[name="email_geral"]').val();
		var cep					= $('input[name="cep"]').val();
		var endereco			= $('input[name="endereco"]').val();
		var numero				= $('input[name="numero"]').val();
		var complemento			= $('input[name="complemento"]').val();
		var bairro				= $('input[name="bairro"]').val();
		var cidade				= $('input[name="cidade"]').val();
		var estado				= $('select[name="estado"]').val();
		var email_tecnico		= $('input[name="email_tecnico"]').val();
		var email_cobranca		= $('input[name="email_cobranca"]').val();
		
		
		
		
		
		
		if (nome_responsavel == "")
		{
			$('input[name="nome_responsavel"]').focus();
			
			erro = 1;			
			return false;
			
		}
		
		if (cpf == "")
		{
			$('input[name="cpf"]').focus();
			
			erro = 1;
			return false;
		}
		
		if (razao_social == "")
		{
			$('input[name="razao_social"]').focus();
			
			erro = 1;
			return false;
		}
		
		if (cnpj == "")
		{
			$('input[name="cnpj"]').focus();
			
			erro = 1;
			return false;
		}
		if (telefone1 == "")
		{
			$('input[name="telefone1"]').focus();
			
			erro = 1;
			return false;
		}
		if (email_geral == "")
		{
			$('input[name="email_geral"]').focus();
			
			erro = 1;
			return false;
		}
		if (endereco == "")
		{
			$('input[name="endereco"]').focus();
			
			erro = 1;
			return false;
		}
		if (numero == "")
		{
			$('input[name="numero"]').focus();
			
			erro = 1;
			return false;
		}
		if (bairro == "")
		{
			$('input[name="bairro"]').focus();
			
			erro = 1;
			return false;
		}
		if (cidade == "")
		{
			$('input[name="cidade"]').focus();
			
			erro = 1;
			return false;
		}
		if (estado == "")
		{
			$('input[name="estado"]').focus();
			erro = 1;
			return false;
		}
		if (email_tecnico == "")
		{
			$('input[name="email_tecnico"]').focus();
			
			erro = 1;
			return false;
		}
		if (email_cobranca == "")
		{
			$('input[name="email_cobranca"]').focus();
			
			erro = 1;
			return false;
		}
		
		if (erro == 0)
		{
			return "etapa2";
		}
}

function vEtapa2()
{
	var erro2 = 0;
	var possui_dominio		= $('input[name="possui_dominio"]:checked').attr("value");
	var dominio				= $('input[name="dominio"]').val();
	var registrar_dominio	= $('input[name="registrar_dominio"]:checked').attr("value");
	
	
	if (possui_dominio == "")
	{
		$('input[name="possui_dominio"]').focus();		
		erro2 = 1;
		return false;
	}
				
	if (dominio == "")
	{
		$('input[name="dominio"]').focus();
				
		erro2 = 1;
		return false;
	}
				
	if (registrar_dominio == "")
	{
		$('input[name="registrar_dominio"]').focus();
				
		erro2 = 1;
		return false;
	}
	
	
	if (erro2 == 0)
	{
		return "etapa3";
	}
}

function vEtapa3()
{
	var erro3 = 0;
	var plano_escolhido		= $('input[name="plano_escolhido"]').val();
	var tema_escolhido		= $('input[name="tema_escolhido"]').val();
	
	if (plano_escolhido == "")
	{	
		$('input[name="plano_escolhido"]').focus();				
		
		erro3 = 1;		
		return false;
	}				
	
	if (tema_escolhido == "")
	{
		$('input[name="tema_escolhido"]').focus();
						
		erro3 = 1;		
		return false;
	}
	
	if (erro3 == 0)
	{
		return "etapa4";
	}	
}


function vEtapa4()
{
	var erro4 = 0;
	var aceita_termos		= $('input[name="aceita_termos"]:checked').val();
	
	if (aceita_termos != "1")
	{					
		erro4 = 1;
		return false;
	}
	
	if (erro4 == 0)
	{
		return "concluido";
	}
}

function validaCon(){
	var nome 		= $('input[name="nome"]').val();
	var email 		= $('input[name="email"]').val();
	var telefone 	= $('input[name="telefone"]').val();
	var msg 		= $('textarea[name="mensagem"]').val();
		
	if(nome == "" || nome == "Nome" || nome == " "){$('.errors').empty().html('Nome inválido!');$('input[name="nome"]').focus(); return false;}
	if(email == "" || email == "Email" || email == " "){ $('.errors').empty().html('E-mail inválido!');$('input[name="email"]').focus(); return false;}
	if(telefone == "" || telefone == "Telefone" || telefone == " ") { $('.errors').empty().html('Telefone inválido!');$('input[name="telefone"]').focus(); return false;}
	if(msg == "" || msg == "Digite sua Mensagem" || msg == " "){ $('.errors').empty().html('Informe sua mensagem!');$('textarea[name="mensagem"]').focus(); return false;}
}
