$(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=1,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')]);
        }
															
    });
	
    var mascaraTelefone = false;
    $("#telefone").click(function(){
        if(!mascaraTelefone){
            $(this).mask("(99) 9999-9999? / 9999-9999");  
            mascaraTelefone = true;
        }
    })
    var mascaraCEP = false;
    $("#cep").click(function(){
        if(!mascaraCEP){
            $(this).mask("99999-999");  
            mascaraCEP = true;
        }
    })
    jQuery.validator.addMethod("defaultInvalid", function(value, element) {
        return value != element.defaultValue;
    }, "");
    $("#form_trabalhe, #form_alugue, #form_contato, #form_gostei_imovel").validate({
        rules: {
            nome: {
                required: true,	
                defaultInvalid: true
            },
            email: {
                required: true,	
                email: true,
                defaultInvalid: true
            },
            telefone: {
                required: true,	
                defaultInvalid: true
            },
            mensagem: {
                required: true,	
                defaultInvalid: true
            }			
        },
        messages: {
            nome: "Favor informar o Nome!",
            email: {
                required:"Favor informar um E-mail válido!",
                email:"Favor informar um E-mail válido!"
            },			
            telefone: "Favor informar o Telefone!",
            mensagem: "Favor informar a Mensagem!"
        }	
    });

    $('.lightbox a').lightBox({
        fixedNavigation:false
    });
	
    $('.menu ul li').hover(function(){
        $('ul:first',this).stop(false,true).toggle();
    },function(){
        $('ul:first',this).stop(false,true).toggle();
    });
	
    $('.linha-produtos').each(function(i){ 
        $('.jcarousel-skin-tango',this).jcarousel({
            scroll: 4,
            animation: 'slow',
            wrap: 'circular'
        });
    });
	
    $('.banner ul').after('<div id="nav" class="nav">').cycle({
        fx: 'fade',
        pager:  '#nav'
    });

    $('a.modal').click(function(){
	
        var div = document.createElement("div");
        div.title = $(this).attr("title");
        div = $(div);
        div.attr('id','modal'+$(this).attr("href"));		
        $.ajax({
            url: $(this).attr("href")+".php",
            async: false,
            cache: false,
            contentType: "application/json; charset=utf-8",
            success: function(resposta) {
                div.append(resposta);
            },
            error: function(resposta) {
                div.append(resposta);
            }
        });   
        div.dialog({
            modal:true,
            resizable:false,
            width: 800,
            position: ['auto','auto'],
            close:function(){
                div.dialog("destroy");
                div.remove();    
            },
            buttons: {
                Fechar:function(){
                    div.dialog("close");   
                }
            }
        });    
        return false;
    });




});
