$(function(){
	$('a[href=""]').click(function(){
		return false;
	});


// codigo novo

	function abrirJanela(width, height, nome,barra) {
		var top; var left; 
		if (barra == "") {
			barra = 0;
		}
		top = ( (screen.height/2) - (height/2) )
		left = ( (screen.width/2) - (width/2) )
		window.open(nome, "","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=1,width="+width+",height="+height+",left="+left+",top="+top);
	}
	var valores = new Array;
	$('input[type=text],textarea').each(function(){
			valores[$(this).attr('name')] = $(this).attr('value');
	});
	$('input[type=text],textarea').focus(function(){
	
		if ($(this).attr('value') == valores[$(this).attr('name')]){
			$(this).val('');
		}
															
	}); 
	$('input[type=text],textarea').blur(function(){
	
		if ($(this).attr('value') == ""){
			$(this).val(valores[$(this).attr('name')]);
		}
															
	});
	
	

	$('.multi_check label:odd').addClass('par');
	$('.multi_check label:even').addClass('impar');
	$('.multi_check label').hover(function(){
			$(this).toggleClass('hover');
	});

	$("#telefone").mask("(99) 9999-9999? / 9999-9999");
	$("#form_contato, #form_gostei_imovel").validate({
		rules: {
			nome: "required",
			email: {
				required: true,	
				email: true
			},
			telefone: "required",
			mensagem: "required"			
		},
		messages: {
			nome: "Favor informar o Nome!",
			email: {
				required:"Favor informar um E-mail valido!",
				email:"Favor informar um E-mail valido!"
			},			
			telefone: "Favor informar o Telefone!",
			mensagem: "Favor informar a Mensagem!"
		}	
	});

	// Busca pelo código
	$('#formBusca').submit(function(){
		if($('#formBusca #codigo').val() != '' && $('#formBusca #codigo').val() != 'Busca por código'){
			abrirJanela(802,590,$('#formBusca').attr('action')+'/'+$('#formBusca #codigo').val()+'/popup');
		} else {
			alert('Favor informar o código!');	
			$('#formBusca #codigo').focus();
		}
		return false;
	});
	
	// Abrir detalhes do imóvel no PopUp
	$('a.linkImovel').click(function(){
		abrirJanela(802,590,$(this).attr('href')+'/popup');
		return false;
	});

	$("#vlrini").maskMoney({showSymbol:false,decimal:",",thousands:"."});
	$("#vlrfin").maskMoney({showSymbol:false,decimal:",",thousands:"."});
	$("#quaini").mask("?99");
	$("#quafin").mask("?99");	

	$('#fotos_emp a').lightBox({fixedNavigation:true});
	$('#imagens_emp a').lightBox({fixedNavigation:true});

	$('.banner ul li').cycle({
		fx: 'fade'
	});	
	$('.t-abas ul li').click(function(){
		var aba = $(this).attr('id');
		if(aba == 'busca_completa'){
			$('#formBusca').css('display','none');
			$('#formPesquisa').css('display','');
			$('#busca_codigo').removeClass('ativo');
			$('#busca_completa').addClass('ativo');		
		} else if (aba == 'busca_codigo') {
			$('#formPesquisa').css('display','none');
			$('#formBusca').css('display','');
			$('#busca_completa').removeClass('ativo');
			$('#busca_codigo').addClass('ativo');		
		}
	});
	$('#tipo').multiSelect({
		selectAll: false,
		oneOrMoreSelected: " % Tipo(s)",
		noneSelected: " Selecione o tipo..."
	});
	$('#bairro').multiSelect({
		selectAll: false,
		oneOrMoreSelected: " % Bairro(s)",
		noneSelected: " Selecione o bairro..."
	});
	$('#tipo_div INPUT:checkbox').click( function() {
		ajaxBairro();
	});
	$("#cidade").change( function() { 			
		ajaxTipo();
	});
	$("#estado").change( function() { 			
		ajaxCidade();
	});
	$('.add').click(function(){
		ajaxFavoritos($(this).attr('id'));
	});
	$('.excluir').click(function(){
		ajaxExcluirFavoritos($(this).attr('id'));
	});
	$('.direita').jCarouselLite({
		start: 1,
		auto: 50,
	    speed: 10000,
		scroll: 3,
	    vertical: true
	});
	$('.direita').css('height','550px');
	$('#bt_ok').click(function(){
            if($('#codigo').val() != '' && $('#codigo').val() != 'Busca por código'){
		abrirJanela(802,590,'imovel/'+$('#codigo').val()+'/popup');
            } else {
		alert('Favor informar o código!');	
		$('#codigo').focus();
            }
            return false;
	});
        $("#codigo").keypress(function(event) {
               if ( event.which == 13 ) {
                   $('#bt_ok').click();
                   return false;
                }
        });
});
