$(function(){
	$('a[href=""]').click(function(){
		return false;
	});
	function mycarousel_initCallback(carousel){
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	 
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	 
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	}

// 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() != '' && escape($('#formBusca #codigo').val()) != 'Busca%20por%20c%F3digo'){
			abrirJanela(802,590,$('#formBusca').attr('action')+'/'+$('#formBusca #codigo').val()+'/popup');
		} else {
			alert('Favor informar o codigo!');	
			$('#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});
	$('#formPesquisa input:radio[name=situacao]').click(function(){
		ajaxCidade();
	});
	$("#cidade").change( function() { 			
		ajaxTipo();
	});
	$('#div_tipo').change(function(){ 			
		ajaxBairro();		   
	});	
	$('.add').click(function(){
		ajaxFavoritos($(this).attr('id'));
	});
	$('.excluir').click(function(){
		ajaxExcluirFavoritos($(this).attr('id'));
	});
	$('#barra_imoveis').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 2,
		wrap: 'circular',
		initCallback: mycarousel_initCallback
	});
	$('.linha-destaques').each(function(i){ 
		$('.jcarousel-skin-tango',this).jcarousel({
			scroll: 3,
			auto: 0,
			wrap: 'circular',
			initCallback: mycarousel_initCallback
		});
	});
	$('#banner').cjFlashySlideShow({ xBlocks: 5, yBlocks: 10, minBlockSize: 25, delay: 2500, direction: 'random', translucent: true, sloppy: true });
});
