/* Javascript página principal */
$(document).ready(function(){
  
    //jCarouselLite
    $(".anyClass").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        auto: 1200,
        speed: 2000,
        visible: 3
    });

    try {
        var arDadosImovel = new Array();

        $("#destaquesImoveis li.imovel").each(function(index) {
            arDadosImovel[index] = new Array();

            var titulo = $(this).attr("rel");

            // pega as imagens
            $(this).find("ul li").each(function(index2) {
                arDadosImovel[index][index2] = new Array();
                arDadosImovel[index][index2]["src"] = $(this).text();
                
                if(index == 0) {
                	arDadosImovel[index][index2]["from"] = "top center 1x";
                	arDadosImovel[index][index2]["to"] = "bottom center";
                } else if (index == 1) {
                	arDadosImovel[index][index2]["from"] = "top center 1x";
                	arDadosImovel[index][index2]["to"] = "bottom center";
                } else if (index == 2) {
                	arDadosImovel[index][index2]["from"] = "top center 1x";
                	arDadosImovel[index][index2]["to"] = "bottom center";
                }
                
                arDadosImovel[index][index2]["time"] = 4;
                arDadosImovel[index][index2]["legenda"] = "<a href='"+ $(this).attr("rel") +"'><p>" + titulo + "</p></a>";
                arDadosImovel[index][index2]["href"] = $(this).attr("rel");
            });
            
             $("#destaque" + (index +1)).crossSlide({
                    fade: 3
            }, arDadosImovel[index]);
        });
        
    } catch(e) {alert("Não foi possível carregar as imagens de destaque: " + e);}

    // newsletter
    $("#enviar").click(function() {
        try {
            ajax_loading("#frmNewsletter");

            $.post(UrlSite + "/newsletter.html", $("#frmNewsletter").serialize(), function(data) {

                if(data[0] == 1)
                {
                    data = data.substr(1);
                    $("#frmNewsletter input[name='email']").val("Digite seu e-mail:");
                }

                $("#frmNewsletter").unblock();

                $("#frmNewsletter").block({
                    message: "<div id=\"mensagem_ajax\"><p>" + data + "</p><br /><a href=\"#boletim\" onclick=\"ajax_loading_close('#frmNewsletter');\">[Fechar]</a></div>",
                    css : {
                        margin: 0,
                        padding: 0,
                        border: 'none',
                        width: '300px',
                        background: 'none'
                    },
                    overlayCSS: {
                        background:'#000',
                        opacity: '0.5'
                    }
                });
            });
        } catch(e) {
            alert(e);
        }

        return false;
    });


});


