$(document).ready(function(){

	// FLASH's
	$('#header').flash({
	    src: 'swf/header.swf',
	    width: '100%',
	    height: 636,
		wmode: 'transparent',
		flashvars: {idioma: $('#header').attr('rel') },
		expressInstall: true
	});	
	
	$('#header-internas').flash({
	    src: 'swf/header.swf',
	    width: '100%',
	    height: 356,
		wmode: 'transparent',
		flashvars: {pagina:'interna',idioma: $('#header-internas').attr('rel') },
		expressInstall: true
	});		

	//ABre e fecha as div do empreendimento
	$("div.box-title a").click(function(){
		$(".box-conteudo").slideUp("fast");
		$("#"+$(this).attr('rel')).slideDown("fast");
		$("div.box-title a").removeClass('setaUp').addClass("setaDown");
		$(this).removeClass('setaDown').addClass("setaUp");
	});
	$("div.bloco-detalhe div.box-title").click(function(){
		$(".box-conteudo").slideUp("fast");
		$("#"+$(this).attr('rel')).slideDown("fast");
		$("div.box-title a").removeClass('setaUp').addClass("setaDown");
		$("#"+$(this)+" > a").removeClass('setaDown').addClass("setaUp");
	});
	
	// ABRE FORM INDICAR IMOVEL
	$(".bt-indique").click(function(){
		$("#form-interesse").toggle("fast");
	});
	
	$("a#topo").click(function(){
		$(document).scrollTo("0px", 500 );
	});
	
	//CYCLE FOTOS
	$("#hold-fotos-cycle").cycle({ 
	    fx: "scrollHorz", 
	    prev: "#nav-foto-esq", 
	    next: "#nav-foto-dir", 
	    timeout: 0 
	});
	
	//CYCLE PLANTAS
	$("#hold-plantas-cycle").cycle({ 
	    fx: "scrollHorz", 
	    prev: "#nav-plantas-esq", 
	    next: "#nav-plantas-dir", 
	    timeout: 0 
	});
	
	$(".fa-con, .trab-con, .ass-tec").click(function(){
		$("#fa-con").slideUp();
		$("#trab-con").slideUp();
		$("#ass-tec").slideUp();
		$("#text-fale-conosco").slideUp();

		$(".trab-con").removeClass('active');
		$(".ass-tec").removeClass('active');
		$(".fa-con").removeClass('active');

		var nomedadiv = $(this).attr("class");
		$("#" + nomedadiv + "").slideToggle();
		$(this).addClass('active');
	});
/*	
	$(".trab-con").click(function(){
		var nomedadiv = $(this).attr("class");
		$("#" + nomedadiv + "").slideToggle();
		$("#fa-con").slideUp();
		$("#ass-tec").slideUp();
		$("#text-fale-conosco").slideUp();
	});
	
	$(".ass-tec").click(function(){
		var nomedadiv = $(this).attr("class");
		$("#" + nomedadiv + "").slideToggle();
		$("#trab-con").slideUp();
		$("#fa-con").slideUp();
		$("#text-fale-conosco").slideUp();
	});
*/	
	//LINKS EXTERNOS
	$("a[rel=externo]").attr('target','_blank');
	
	$("div.barra-branca").css("opacity",0.85);
	$("div.ico-zoom").css("opacity",0.7);
	
	// USE HAND CURSOR
	$("input[type=submit]").css("cursor","pointer");
	$("input[type=button]").css("cursor","pointer");
	$("div.bloco-detalhe div.box-title").css("cursor","pointer");

	
	//AREAS DE ATIVACAO DO LIGHTBOX
	$('a[rel*=lightbox]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: 	'img/loading.gif',
		imageBtnClose: 	'img/close.gif',
		imageBtnPrev: 	'img/prev.gif',
		imageBtnNext: 	'img/next.gif',
		containerResizeSpeed: 300,
		txtImage: '',
		txtOf: ''
	});
	
});

// FAQ
function abreResp(id, thiis) {
	block = document.getElementById(id);
	if (block.style.display == 'block' ){
		thiis.className='';
		block.style.display='none';
	}else{
		thiis.className='tema1';;
		block.style.display='block';
	}
}

function hide(id){
	$(id).hide(100);
}


// INTERESSE
function funcaoInteresse(flag){
	if(flag){
		$.ajax({
			type: "POST",
			url: "lib/acao_interesse.php",
			data: 
			"id=" 		+ $('#id_galeria').val() 		+ "&" + 
			"nome=" 	+ $('#nome_interesse').val() 	+ "&" + 
			"email=" 	+ $('#email_interesse').val() 	+ "&" + 
			"",
			beforeSend: function() {
			},
			success: function(txt) {
				alert(txt);
				$('#form-interesse').hide(1000);
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}


// Validar formulário
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {
        
        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');
				
		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if(!expressao.test(document.getElementById(form).elements[i].value)){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].style.backgroundColor = "#FEFFD5";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].style.backgroundColor = "#FEFFD5";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}

// Validar contato
function validarContato() {
	if(validaForm('formContato')) {	
		$.ajax( {
			type: "POST",
			url: "lib/acao_contato.php",
			data: "con_nome=" + $("#con_nome").val() + "&con_email=" + $("#con_email").val() + "&con_msg=" + $("#con_msg").val() + "&curriculo=" + $("#curriculo").val(),
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("formContato").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

// Validar indique
function validarIndique() {
	if(validaForm('frmIndique')) {	
		$.ajax( {
			type: "POST",
			url: "lib/acao_indique.php",
			data: "seu_nome=" + $("#seu_nome").val() + "&seu_email=" + $("#seu_email").val() + "&dest_nome=" + $("#dest_nome").val() + "&dest_email=" + $("#dest_email").val() + "&dest_empree=" + $("#dest_empree").val(),
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("frmIndique").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

// Validar interesse
function validarInteresse() {
	if(validaForm('frmInteresse')) {	
		$.ajax( {
			type: "POST",
			url: "lib/acao_interesse.php",
			data: "inte_nome=" + $("#inte_nome").val() + "&inte_email=" + $("#inte_email").val() + "&inte_empree=" + $("#inte_empree").val(),
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("frmInteresse").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

// Validar cadastre
function validarCadastre() {
	if(validaForm('formCadastre')) {	
		$.ajax( {
			type: "POST",
			url: "lib/acao_cadastre.php",
			data: "con_area=" + $("#con_area").val() + "&con_frente=" + $("#con_frente").val() + "&con_fundo=" + $("#con_fundo").val() + "&con_lat_dir=" + $("#con_lat_dir").val() + "&con_lat_esq=" + $("#con_lat_esq").val() + "&con_zoneamento=" + $("#con_zoneamento").val() + "&con_localizacao=" + $("#con_localizacao").val() + "&con_valor=" + $("#con_valor").val() + "&con_nome=" + $("#con_nome").val() + "&con_cidade=" + $("#con_cidade").val() + "&con_fone=" + $("#con_fone").val() + "&con_email=" + $("#con_email").val() + "&con_msg=" + $("#con_msg").val(),
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("formCadastre").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

// Validar venda
function validarVenda() {
	if(validaForm('formVenda')) {	
		$.ajax( {
			type: "POST",
			url: "lib/acao_venda.php",
			data: "con_nome=" + $("#con_nome").val() + "&con_email=" + $("#con_email").val() + "&con_endereco=" + $("#con_endereco").val() + "&con_cidade=" + $("#con_cidade").val() + "&con_cep=" + $("#con_cep").val() + "&con_fone=" + $("#con_fone").val() + "&con_como=" + $("#con_como").val() + "&con_inte=" + $("#con_inte").val() + "&con_msg=" + $("#con_msg").val() ,
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("formVenda").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

// Validar assistencia tecnica
function validarAssistencia() {
	if(validaForm('formAssistencia')) {	
		var str = $('#formAssistencia').serialize();
		$.ajax( {
			type: "POST",
			url: "lib/acao_assistencia.php",
			data: str,
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("formAssistencia").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

