$j = jQuery.noConflict();


function inicio(pg){
	//esconde o formulário de intenção de compra
	if(pg == "" || pg == "detalheimv" ){
		if(pg == "detalheimv"){
				$j("#proposta").hide();	
		}
		$j("#setadireita").hide();
		$j("#setaesquerda").hide();
		leftpacotes();
	}
	if(pg == "paraiba"){
		animGallery();
	}
}
function animGallery(){

	for(i = 1; i <= 8; i++){
		$j("#t"+ i).fadeTo("slow", 0.33);
		$j("#f"+ i).hide();
	}

	animaF1();
//	$j("#f1").fadeIn(500,function()
}
function onMouseOver(id){
	$j("#"+ id).stop();
	$j("#"+ id).fadeTo(100, 1);
}
function onMouseOut(id){
	$j("#"+ id).stop();
	$j("#"+ id).fadeTo(500, 0.33);
}
function apagaThumbs(func){
	for(i = 1; i <= 8; i++){
		$j("#t"+ i).stop();
		$j("#t"+ i).fadeTo("slow", 0.33);
	}
	for(i = 1; i <= 8; i++){
		$j("#f"+ i).stop();
	}
	for(i = 1; i <= 8; i++){
		$j("#f"+ i).hide();
	}
	switch(func){
		case "f1":
			animaF1();
		break;
		case "f2":
			animaF2();
		break;
		case "f3":
			animaF3();
		break;
		case "f4":
			animaF4();
		break;
		case "f5":
			animaF5();
		break;
		case "f6":
			animaF6();
		break;
		case "f7":
			animaF7();
		break;
		case "f8":
			animaF8();
		break;
	}
}
function animaF1(){
	$j("#t1").fadeTo("slow", 1);
	$j("#f1").fadeIn(5000,function(){
		$j("#f1").fadeOut(5000,function(){
			$j("#t1").fadeTo("slow", 0.33);
			animaF2();							
		});
	});
}
function animaF2(){
	$j("#t2").fadeTo("slow", 1);
	$j("#f2").fadeIn(5000,function(){
		$j("#f2").fadeOut(5000,function(){
			$j("#t2").fadeTo("slow", 0.33);
			animaF3();							
		});
	});
}
function animaF3(){
	$j("#t3").fadeTo("slow", 1);
	$j("#f3").fadeIn(5000,function(){
		$j("#f3").fadeOut(5000,function(){
			$j("#t3").fadeTo("slow", 0.33);
			animaF4();							
		});
	});
}
function animaF4(){
	$j("#t4").fadeTo("slow", 1);
	$j("#f4").fadeIn(5000,function(){
		$j("#f4").fadeOut(5000,function(){
			$j("#t4").fadeTo("slow", 0.33);
			animaF5();							
		});
	});
}
function animaF5(){
	$j("#t5").fadeTo("slow", 1);
	$j("#f5").fadeIn(5000,function(){
		$j("#f5").fadeOut(5000,function(){
			$j("#t5").fadeTo("slow", 0.33);
			animaF6();							
		});
	});
}
function animaF6(){
	$j("#t6").fadeTo("slow", 1);
	$j("#f6").fadeIn(5000,function(){
		$j("#f6").fadeOut(5000,function(){
			$j("#t6").fadeTo("slow", 0.33);
			animaF7();							
		});
	});
}
function animaF7(){
	$j("#t7").fadeTo("slow", 1);
	$j("#f7").fadeIn(5000,function(){
		$j("#f7").fadeOut(5000,function(){
			$j("#t7").fadeTo("slow", 0.33);
			animaF8();							
		});
	});
}
function animaF8(){
	$j("#t8").fadeTo("slow", 1);
	$j("#f8").fadeIn(5000,function(){
		$j("#f8").fadeOut(5000,function(){
			$j("#t8").fadeTo("slow", 0.33);
			animaF1();							
		});
	});
}
$j(function(){
	$j(".click, .language, .rapido, .principal, .estados, #pacotes, .clickbtn").click(function() {
		//$j("#mapa").animate({"height": "-=300px"}, 500,"linear");
		$j("#pacotes").stop();
	});
});
	
function aumentaMapa(){
	$j("#mapa").animate({"height": "+=100px"}, 500,"linear");
}
//LIGA E DESLIGA SETAS
function ligarSeta(id){
	$j("#"+id).fadeIn(1000);
}
function desligaSeta(id){
	$j("#"+id).fadeOut(1000);
}
//LIGA E DESLIGA SETAS

function leftpacotes(){
	$j("#pacotes").animate({"left": "-=1155px"}, 25000,"linear",zerapacotes);
}
function left2pacotes(){
//	$j("#pacotes").toggle();
	$j("#pacotes").stop();
	$j("#pacotes").fadeOut();
	$j("#pacotes").fadeIn(2000);
	document.getElementById("pacotes").style.left = "0px";
	leftpacotes();
	//$j("#pacotes").animate({"right": "+=500px"}, 20000,"linear",zera2);
}
function rightpacotes(){
//	$j("#pacotes").toggle();
	$j("#pacotes").stop();
	$j("#pacotes").fadeOut();
	$j("#pacotes").fadeIn(2000);
	document.getElementById("pacotes").style.left = "-1155px";
	right2pacotes();
	//$j("#pacotes").animate({"right": "+=500px"}, 20000,"linear",zera2);
}
function right2pacotes(){
	$j("#pacotes").animate({"left": "+=1155px"}, 25000,"linear",zera2pacotes);
}
function zerapacotes(){
	document.getElementById("pacotes").style.left = "0px";
	leftpacotes();
}
function zera2pacotes(){
	document.getElementById("pacotes").style.left = "-1155px";
	right2pacotes();
}


function timedados(){
	setInterval("valor()", 100);	
}
function valor(){
	$j("#lef").html($j("#pacotes").position().left);	
}

function carregaCidade() {
	
	var regiao = $j("#regiao").val();
	$j("#cidade").fadeOut(500,function(){
		
		$j.ajax({
			type: "GET",
			url: "inc/pesquisa.php",
			data: "acao=carregaCidade&ufCodigo="+regiao,
			cache: false,
			success: function(result) {
				$j("#carregaCidade").fadeIn(500).html(result);
			}
		});
	
	});
	
	
};

function carregaBairro() {
	
	var cidade = $j("#cidade").val();
	$j("#bairro").fadeOut(500,function(){
		$j.ajax({
			type: "GET",
			url: "inc/pesquisa.php",
			data: "acao=carregaBairro&cidCodigo="+cidade,
			cache: false,
			success: function(result) {
				$j("#carregaBairro").fadeIn(500).html(result);
			}
		});
	});
	
};

function converteMoeda(valorimv,moeda) {
	$j("#resultvalor").fadeOut(250,function(){
		$j("#resultvalor").fadeIn(100).html('<img align="left" src="img/loading.gif" />');
		$j.ajax({
			type: "GET",
			url: "inc/pesquisa.php",
			data: "acao=converteMoeda&valorimv="+valorimv+"&moeda="+moeda,
			cache: false,
			success: function(result) {
				$j("#resultvalor").fadeIn(100).html(result);
			}
		});
	
	});
};

function quero() {
	$j("#frmProposta").show(1000);
};

function fecharProposta() {
	$j("#frmProposta").hide();
};

function pesquisarImoveis(linguaCodigo) {
	var regiao = $j("#regiao").val();
	var cidade = $j("#cidade").val();
	var bairro = $j("#bairro").val();
	var tipo = $j("#tipo").val();
	var valor = $j("#valor").val();
	$j("#resultbusca").fadeOut(250,function(){
		
		$j.ajax({
			type: "GET",
			url: "inc/pesquisa.php",
			data: "acao=&valor="+valor+"&tipo="+tipo+"&bairro="+bairro+"&cidade="+cidade+"&regiao="+regiao+"&acao1=pesquisarImoveis&linguaCodigo="+linguaCodigo,
			cache: false,
			success: function(result) {
				$j("#resultbusca").fadeIn(100).html(result);
			}
		});
	
	});
};
function carregaPaginacao(pag,linguaCodigo) {
	var regiao = $j("#regiao").val();
	var cidade = $j("#cidade").val();
	var bairro = $j("#bairro").val();
	var tipo = $j("#tipo").val();
	var valor = $j("#valor").val();
	$j("#resultbusca").fadeOut(250,function(){
		
		$j.ajax({
			type: "GET",
			url: "inc/pesquisa.php",
			data: "acao=&valor="+valor+"&tipo="+tipo+"&bairro="+bairro+"&cidade="+cidade+"&regiao="+regiao+"&acao1=pesquisarImoveis&linguaCodigo="+ linguaCodigo +"&pag="+pag,
			cache: false,
			success: function(result) {
				$j("#resultbusca").fadeIn(100).html(result);
				$j.scrollTo( 0, 800 );
			}
		});
	
	});
};
function navparaiba1() {
	$j.scrollTo( 720, 800 );
};
function navparaiba2() {
	$j.scrollTo( 1510, 800 );
};
function navparaiba3() {
	$j.scrollTo( 2050, 1000 );
};
function navparaiba4() {
	$j.scrollTo( 2240, 1200 );
};
function navparaiba5() {
	$j.scrollTo( 2900, 1200 );
};

	$j(function(){
		var options = {
			target: "#resultajax",
			beforeSubmit: showRequest,
			secess: showResponse,
			clearForm: false
		};
		
		$j("#form_busca").validate({
		
			submitHandler: function(form) {
				$j(form).ajaxSubmit(options);
			}
		
		});
	
	});

function showRequest(formData, jqForm, options){
	return true;
}

function showResponse(responseText, statusText){
	
	$j("#resultajax").fadeOut(1000);
	if(responseText != ""){
		$j("#resultajax").fadeIn(1000).html(responseText);
	}
}

$j(function() {
		$j("#campos2").hide();
		$j("#esconder").hide();
	});

function showForm() {
		$j("#campos").show('slow');
		$j("#campos2").hide('slow');
		$j("#esconder").show();
	}
function showForm2() {
		$j("#campos").show('slow');
		$j("#campos2").hide('slow');
		$j("#esconder").hide();
	}
function showForm3() {
		$j("#campos").hide('slow');
		$j("#campos2").show('slow');
	}
	
        	
			$j(function() {
			
				
				var options = {
					target: "#aviso1",
					beforeSubmit: showRequest1,
					success: showResponse1,
					clearForm: true
				};
				
				$j("#frm2").validate({
					rules: {
						nome: "required",
						fone: "required",
						email: {
							required: true,
							email: true
							
						}
					},
					messages: {
						nome: "&nbsp;*",
						fone: "&nbsp;*",
						mens: "&nbsp;digite o Mensagem",
						email: {
							required: "&nbsp;digite o Email",
							email: "&nbsp;formato inválido"
							
						}
					},
					errorElement: "em",
					errorClass: "error",
					highlight: function(element, errorClass) {
						$j(element).addClass(errorClass);
					},
					submitHandler: function(form) {
						$j(form).ajaxSubmit(options);
					}
				});
				
			});
						
			function showRequest1(formData, jqForm, options) {
				return true;
			}
			
			function showResponse1(responseText, statusText) {
				$j("#aviso1").fadeOut(1000);
				if(responseText != ""){
					$j("#aviso1").fadeIn(1000).html(responseText);
				}
			}
			
        	
			$j(function() {
			
				
				var options = {
					target: "#aviso1",
					beforeSubmit: showRequest3,
					success: showResponse3,
					clearForm: true
				};
				
				$j("#frm3").validate({
					rules: {
						nome: "required",
						fone: "required",
						emailamigo: {
							required: false,
							email: true
							
						}
					},
					messages: {
						nome: "&nbsp;digite o Nome",
						fone: "&nbsp;digite o Fone",
						mens: "&nbsp;digite o Mensagem",
						emailamigo: {
							required: "&nbsp;digite o Email",
							email: "&nbsp;formato inválido"
							
						}
					},
					errorElement: "em",
					errorClass: "error",
					highlight: function(element, errorClass) {
						$j(element).addClass(errorClass);
					},
					submitHandler: function(form) {
						$j(form).ajaxSubmit(options);
					}
				});
				
			});
						
			function showRequest3(formData, jqForm, options) {
				return true;
			}
			
			function showResponse3(responseText, statusText) {
				$j("#aviso1").fadeOut(1000);
				if(responseText != ""){
					$j("#aviso1").fadeIn(1000).html(responseText);
				}
			}
			

$j(function(){
		var options = {
			target: "#resultajax",
			beforeSubmit: showRequest4,
			secess: showResponse4,
			clearForm: false
		};
		
		$j("#form_buscapag").validate({
		
			submitHandler: function(form) {
				$j(form).ajaxSubmit(options);
			}
		
		});
	
	});

function showRequest4(formData, jqForm, options){
	return true;
}

function showResponse4(responseText, statusText){

	
	$j("#resultajax").fadeOut(1000);
	if(responseText != ""){
		$j("#resultajax").fadeIn(1000).html(responseText);
	}
}

function chamaPaginacao(limit,acao,div,linguaCodigo,scrol) {
	
	$j(div).fadeOut(250);
	$j.ajax({
		type: "GET",
		url: "inc/pesquisa.php",
		data: "limit="+limit +"&acao="+ acao +"&linguaCodigo="+ linguaCodigo,
		cache: false,
		success: function(result) {
			$j(div).empty();
			$j(div).html(result).slideDown(500);
			if(scrol == 1){
				$j.scrollTo( 100, 800 );
			}else if(scrol == 2){
				$j.scrollTo( 750, 800 );
			}
		}
	});
	
}
