$(function(){
    $('a[href=""]').click(function(){
	return false;
    });
    
    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 mascaraTelefone = false;
   $("#telefone").click(function(){
     if(!mascaraTelefone){
        $(this).mask("(99) 9999-9999? / 9999-9999");  
        mascaraTelefone = true;
       }
   })
   
   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')]);
	}

    });

    
    $("#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!"
	}
    });

    $('.lightbox').each(function(){
	$('a',$(this)).lightBox({
	    fixedNavigation:false
	});
    });

    $('.mycarousel').jcarousel({
	vertical: true,
        scroll: 6,
	animation: 2000
    });
	$('#formEnquete').submit( function(){
		var resposta = $('input:radio[name=resposta]:checked').val();
		var enquete = $('input:hidden[name=enquete]').val();
		var comentario = escape($('textarea[name=comentario]').val());
		if(resposta == undefined){
			$('input:radio[name=resposta]').focus();
			alert('Selecione uma resposta!');
		} else {
			abrirJanela(350,300,'votar-enquete.php?enquete='+enquete+'&resposta='+resposta+'&comentario='+comentario);
		}
		return false;
	});
});
