var paginaImagens = false;
var is_ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6.0') > -1;

var windowWidth = window.innerWidth !== undefined ? window.innerWidth : document.documentElement.offsetWidth;
var windowHeight = window.innerHeight !== undefined ? window.innerHeight : document.documentElement.offsetHeight;

function manageJingle(mp3)
{
	var container = jQuery("div.holder-player");
	
	var url = "";
	url += '<object height="1" width="1" id="musicplayer" data="_swf/player_jingle.swf?caminho='+mp3+'&amp;startPlaying=true" type="application/x-shockwave-flash">';
	url += '<param value="_swf/player_jingle.swf?caminho='+mp3+'&amp;startPlaying=true" name="movie">';
	url += '<param value="high" name="quality">';
	url += '<param value="#ffffff" name="bgcolor">';
	url += '<param value="false" name="autoplay">';
	url += '<param value="true" name="loop">';
	url += '<param value="transparent" name="wmode">';
	url += '<param value="showall" name="scale">';
	url += '<param value="true" name="menu">';
	url += '<param value="false" name="devicefont">';
	url += '<param value="" name="salign">';
	url += '<param value="sameDomain" name="allowScriptAccess">';
	url += '</object>';
	
	if(container.hasClass('inativo'))
	{
		container.html(url);
		container.removeClass('inativo');
	}
	else
	{
		container.html('');
		container.addClass('inativo');
	}
}

function atualizaParamBreadcrump(coringa,valor){
	jQuery('.breadcrumb ul li a').each(function() {
		var href = jQuery(this).attr('href');
		var hrefNovo = href.replace(coringa,valor);
		jQuery(this).attr('href',hrefNovo);
	});
}
	
function openSuperTroca() {
	var url = "lightbox-supertroca.php?width=509&amp;height=300&amp;&amp;modal=false&amp;TB_iframe=true";
	if(is_ie6)
		popup("/"+url, 520, 450);
	else
		tb_show(false, url, null);
}

function novoClientePortal() {
	tb_show(false,"portalcliente/cadastro.php?TB_iframe=true&amp;width=520&amp;height=570&amp;modal=false&amp;margem=especial",null);
}

function telefoneClientePortal() {
	tb_show(false,"portalcliente/telefones.php?TB_iframe=true&amp;width=520&amp;height=570&amp;modal=false&amp;margem=especial",null);
}

function esqueciSenhaPortal() {
	tb_show(false,"portalcliente/senha.php?TB_iframe=true&amp;width=520&amp;height=570&amp;modal=false&amp;margem=especial",null);
}

function openImagemPortalcliente(indice, pc)
{
	var back = "";
	if(pc) back = "../";
	tb_show(false, back+"imagem_detalhe.php?indice="+indice+"&amp;width=810&amp;height=570&amp;modal=false&amp;margem=especial",null);
}

function openImagemEventoPortalcliente(indice, evento, pc)
{        
	var back = "";
	if(pc) back = "../";
	tb_show(false, back+"imagem-evento.php?indice="+indice+"&idEvento="+evento+"&width=810&height=650&modal=false&margem=especial",null);
}

function openImagem(indice, pc)
{
	var html = '';
	html += '<div class="holder-galeria">';
	html += 		'<img src="_images/loader.gif" class="loader" id="image-loader" />';
	html += 		'<div class="titulo-galeria">';
	html += 			'<p></p>';
	html += 			'<img src="_images/fechar-galeria-full.jpg" id="sairSlideShow" />';
	html += 		'</div>';
	html += 		'<img src="_images/left-nav-fullscreen.png" class="left-nav-img" id="light-navLeft" />';
	html += 		'<div class="imagem-galeria">';
	html +=	 		'<img id="pic" src="../_images/white.gif" />';
	html += 		'</div>';
	html += 		'<img src="_images/right-nav-fullscreen.png" class="right-nav-img" id="light-navRight" />';
	html += 		'<div class="footer-galeria">';
	html += 			'<p class="counter" id="lbl-contador"></p>';
	html += 			'<div class="controles">';
	html += 				'<span id="textoiniciaslide">Ver SlideShow</span>';
	html += 				'<img src="_images/slideshow-stop.jpg" class="pararSlideShow" />';
	html += 				'<img src="_images/slideshow-play.jpg" class="pausaSlideShow" />';
	html += 			'</div>';
	html += 			'<div class="print btImprimir" onclick="window.open(\'../imagem-print.php?idImagemEmpreendimento=\'+idImagemEmpreendimento);">';
	html += 				'<span>Imprimir imagem</span>';
	html += 				'<img src="_images/btn-print-galeria.jpg" class="btn-print" />';
	html += 			'</div>';
	html += 		'</div>';
	html += 	'</div>';
	
	$('body').append(html);
	LightGallery.init();
	LightGallery.setItem(indice);
	
	var topoHeight = $(".titulo-galeria").height();
	var footerHeight = $(".footer-galeria").height();
	var holderImgHeight = $(".holder-galeria").height() - footerHeight - topoHeight;
	$(".imagem-galeria").height(holderImgHeight);
	$(".imagem-galeria > img").height($(".imagem-galeria").height());
	$(".imagem-galeria").width($(".imagem-galeria > img").width());
	jQuery(".imagem-galeria").css("margin", "0 auto");
		
	$(".pausaSlideShow").click(function(){				
		LightGallery.slideShow();
		$(".pararSlideShow").css('display','block');
		$(this).css('display','none');
		$("#textoiniciaslide").html('Parar SlideShow');
	});
	
	$(".pararSlideShow").click(function(){			
		LightGallery.stopSlideShow();
		$(".pausaSlideShow").css('display','block');
		$(this).css('display','none');	
		$("#textoiniciaslide").html('Ver SlideShow');		 
	});
	
	$("#sairSlideShow").click(function(){
		$('.holder-galeria').remove();
		LightGallery.stopSlideShow();
	});
	
	$("#textoiniciaslide").click(function(){
		if($(".pausaSlideShow").is(":visible"))
		{				
			$(".pausaSlideShow").hide();
			$(".pararSlideShow").show();
			$("#textoiniciaslide").html('Parar SlideShow');	
			LightGallery.slideShow();
		}
		else
		{
			$(".pausaSlideShow").show();
			$(".pararSlideShow").hide();
			$("#textoiniciaslide").html('Ver SlideShow');	
			LightGallery.stopSlideShow();
		}
	});
	/*
	var back = "";
	if(pc) back = "../";
	tb_show(false, back+"galeria_fullscreen.php?indice="+indice+"&amp;width="+windowWidth+"&amp;height="+windowHeight+"&amp;modal=true&amp;margem=especial",null);
	*/
}

function openVideo(indice, pc)
{
	var back = "";
	if(pc) back = "../";
	tb_show(false, back+"video_detalhe.php?indice="+indice+"&amp;width=810&amp;height=540&amp;modal=false&amp;margem=especial",null);
}

function openTourComum(nomeArquivo,indice)
{
	//alert('nomeArquivo: '+nomeArquivo);
	
	pageTracker._trackPageview('tourVirtual-'+nomeArquivo);
	tb_show(false,"tour/"+nomeArquivo+".php?idEmpreendimento="+indice+"&amp;width=810&amp;height=540&amp;modal=false&amp;margem=especial",null);
	//tb_show(null,"maps.php?width=804&amp;height=680&amp;endereco="+indice+"&amp;modal=true&amp;TB_iframe=true");
	//tb_show(false,"imagem_detalhe.php?indice="+indice+"&amp;width=820&&amp;height=540&amp;modal=false&amp;TB_iframe=true&amp;margem=especial",null);
	//tb_show(false,"imagem_detalhe.php?indice="+indice+"&amp;width=820&amp;height=540&amp;modal=false&amp;margem=especial",null);	
}

function openTourNovo(nome, path)
{
	pageTracker._trackPageview('tourVirtual-'+nome);
	tb_show(false,"tour/html_base_tour.php?path="+path+"&amp;width=810&amp;height=540&amp;modal=false&amp;margem=especial",null);
}


function open3D(file)
{
	tb_show(false,"3d.php?3d="+file+"TB_iframe=true&amp;width=600&amp;height=500&amp;modal=false&amp;margem=especial",null);
}
function openFolderdigital(file)
{
	tb_show(false,"folderdigital.php?source="+file+"TB_iframe=true&amp;width=980&amp;height=570&amp;modal=false&amp;margem=especial",null);
}


function openMap(endereco)
{
	tb_show(null,"maps.php?width=804&amp;height=455&amp;endereco="+endereco+"&amp;modal=true&amp;TB_iframe=true");
}

function iniciar_at()
{
	tb_show(false,"http://interacoes.grupoagre.com.br/atendimento-online-novo.php?TB_iframe=true;width=525&amp;height=470&amp;modal=false",null);
}

function superTroca(nome, idAgre, localidade)
{
	//tb_show(null,"http://fess-xseries/agre-portal/lightbox-supertroca.php?produto=" + nome + "&amp;localidade=" + localidade + "&amp;idAgre=" + idAgre + "&amp;TB_iframe=true&amp;width=510&amp;height=360&amp;modal=true&amp;supertroca=true");
	tb_show(null,"http://www.grupoagre.com.br/lightbox-supertroca.php?produto=" + nome + "&amp;localidade=" + localidade + "&amp;idAgre=" + idAgre + "&amp;TB_iframe=true;width=510&amp;height=360&amp;modal=true&supertroca=true");
}

function procuraImagem(src)
{
	var indice = 0;
	for(cont=0; cont<arImages.length; cont++){
		if (arImages[cont] == src) indice = cont;
	}
	openImagem(indice);
}

function doBusca(idEtapa){
	var idEstado 	= jQuery('#uf-filter').val();
	var sigla 		= '';
	
	jQuery('#uf-filter option').each(function() {
		if( jQuery(this).val() == idEstado )
		{
			sigla = jQuery(this).text();
		}
	});
}

var externalCdt = '';
var utm_source = '';
var utm_medium = '';
var utm_content = '';
var utm_campaign = '';
var externalProduto 			= '';
var externalTipo 				= '';
var externalTamMinimo 			= '';
var externalTamMaximo 			= '';
var externalQtdDormitorios 		= '';
var externalFase 				= '';
var externalBairro 				= '';
var externalIdEmpreendimento	= '';
var externalIdAntigo 			= '';
var externalLocalidade 			= '';
var externalCidade 				= '';
var externalEstado 				= '';
var externalIdRegiao			= '';
var externalRegiaoHypnobox 		= '';
var externalEmpresaOrigem 		= '';
var externalTime 				= '';

function openInteracao(tipo, produto, idEmpreendimento, localidade, cidade, estado, extra)
{
	
	
    var idAntigo = idEmpreendimento;
	var idRegiao = externalIdRegiao;
	var regiaoHypnobox = externalRegiaoHypnobox;
	var empresaOrigem = externalEmpresaOrigem;
	
	if (produto 			== '' && externalProduto != '')				produto 			= externalProduto;
    if (idEmpreendimento 	== '' && externalIdEmpreendimento != '') 	idEmpreendimento 	= externalIdEmpreendimento;
    if (externalIdAntigo != '') 										idAntigo 			= externalIdAntigo;
    if (localidade 			== '' && externalLocalidade != '') 			localidade 			= externalLocalidade;
	if (cidade	 			== '' && externalCidade != '') 				cidade	 			= externalCidade;
	if (estado 				== '' && externalEstado != '') 				estado 				= externalEstado;	
	
	var extraParam = '';
	if (extra != ''){
		extraParam 	= extra.split('|');
		extra 		= extraParam[0] != "" ? extraParam[0] : "";
		extraParam 	= extraParam[1];
	}
	
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
	
	
	/*
    if ((is_chrome == true || is_safari == true) && tipo == 'interacaocomcorretor'){
		tipo = 'informacoesporemail';
		alert("Esta ferramenta não oferece suporte para o seu navegador de internet. Por favor, entre em contato através do nosso atendimento por e-mail.");
	}
	*/
	
	var w_ie6 = 0;
	var h_ie6 = 0;
	
	
	var url = 'http://interacoes2-teste.tempsite.ws/'+tipo+'.php?time='+externalTime+'&origemSite=pdg.com.br&produto='+produto+'&localidade='+localidade+'&idEmpreendimento='+idEmpreendimento+'&idAntigo='+idAntigo+'&cidade='+cidade+'&estado='+estado+'&idregiao='+idRegiao+'&regiaoHypnobox='+regiaoHypnobox+'&empresaOrigem='+empresaOrigem+extraParam;
	//var url = 'http://fess-xseries/pdg-interacoes/'+tipo+'.php?time='+externalTime+'&origemSite=pdg.com.br&produto='+produto+'&localidade='+localidade+'&idEmpreendimento='+idEmpreendimento+'&idAntigo='+idAntigo+'&cidade='+cidade+'&estado='+estado+'&idregiao='+idRegiao+'&regiaoHypnobox='+regiaoHypnobox+'&empresaOrigem='+empresaOrigem+extraParam;
	
	url += '&amp;idcdt='+externalCdt;
	
	url += '&amp;utm_source='+utm_source;
	url += '&amp;utm_medium='+utm_medium;
	url += '&amp;utm_content='+utm_content;
	url += '&amp;utm_campaign='+utm_campaign;

	//if (jQuery.url.param("campanha") != undefined) url += '&amp;campanha='+jQuery.url.param("campanha");

	if (extra != '') url += extra.replace('&','&amp;');
	
	if (externalTipo != '') url += '&amp;externalTipo='+externalTipo;
	if (externalTamMinimo != '') url += '&amp;externalTamMinimo='+externalTamMinimo;
	if (externalTamMaximo != '') url += '&amp;externalTamMaximo='+externalTamMaximo;
	if (externalQtdDormitorios != '') url += '&amp;externalQtdDormitorios='+externalQtdDormitorios;
	if (externalFase != '') url += '&amp;externalFase='+externalFase;
	if (externalBairro != '') url += '&amp;externalBairro='+externalBairro;
	if (externalCidade != '') url += '&amp;externalCidade='+externalCidade;
	if (externalEstado != '') url += '&amp;externalEstado='+externalEstado;

	if (tipo == 'interacaocomcorretor')
    {
        if(navigator.appName=='Microsoft Internet Explorer')
        {
            url += '&amp;width=525&amp;height=555&amp;unidadenegocio='+extra;
			w_ie6 = 555;
			h_ie6 = 555;
        }
        else
        {           
			url += '&amp;width=525&amp;height=555&amp;unidadenegocio='+extra;
        }
		
    }
		
	if (tipo == 'simuleofinanciamento'){
		url += '&amp;width=622&amp;height=500&amp;' + extra;
		w_ie6 = 667;
		h_ie6 = 500;
	}
        
	if (tipo == 'ligamospravoce')
    {
		if(navigator.appName=='Microsoft Internet Explorer')
        {
			url += '&amp;width=525&amp;height=600';
			w_ie6 = 538;
			h_ie6 = 530;
        }
        else
        {
			url += '&amp;width=525&amp;height=610';
		}
		
    }
    
	if (tipo == 'informacoesporemail')
    {
        if(navigator.appName=='Microsoft Internet Explorer')
        {
            url += '&amp;width=519&amp;height=605';
			w_ie6 = 542;
			h_ie6 = 515;
        }
		
        else
        {
			if(is_chrome == true)
			{
			  url += '&amp;width=514&amp;height=625';
			}else{
				url += '&amp;width=514&amp;height=598';
				
			}
		}
		
    }
	
    if (tipo == 'atendimento-online')
    {
        if(navigator.appName=='Microsoft Internet Explorer')
        {
            url += '&amp;width=525&amp;height=580';
			w_ie6 = 560;
			h_ie6 = 580;
        }
        else
        {
            url += '&amp;width=525&amp;height=540';
        }
    }
    
	if (tipo == 'simuleofinanciamento')
    {
		url += '&amp;width=525&amp;height=520';
		w_ie6 = 545;
		h_ie6 = 430;
    }
    
	if (tipo == 'agendevisita')
    {
        if(navigator.appName=='Microsoft Internet Explorer'){
            url += '&amp;width=525&amp;height=580';
			w_ie6 = 550;
			h_ie6 = 520;
		}
		
        else
        {
			if(is_chrome == true)
			{
			  url += '&amp;width=525&amp;height=595';
			}else{
				url += '&amp;width=525&amp;height=575';
				
			}
		}
    }
    
	if (tipo == 'enviarproposta')
    {
        if(navigator.appName=='Microsoft Internet Explorer')
        {
            url += '&amp;width=525&amp;height=500';
			w_ie6 = 550;
			h_ie6 = 450;
        }
        else
        {
            url += '&amp;width=525&amp;height=500';
		}
    }
    
	if (tipo == 'mapadelocalizacao'){
		url += '&amp;width=705&amp;height=500';
		w_ie6 = 710;
		h_ie6 = 500;
	}

	url += '&amp;modal=true&amp;TB_iframe=true';
	
	//alert(url);

	if(is_ie6 == true)
		popup(url, w_ie6, h_ie6);
	else
		tb_show(null, url);
	
	
}

function popup(pagina,w,h,s)
{
	if (self.screen)
	{
		sw = screen.width;
		sh = screen.height;
		cx = (.5*sw) - (w*.5);
		cy = (.5*sh) - (h*.5);
		var  dimentions_and_such = 'width='+w+','+'height='+h+',' + 'screenX=' +cx+','+'screenY='+cy+','+'left='+cx+','+'top='+cy+',scrollbars='+s;
	}
	Pop=window.open(pagina,"popagre",dimentions_and_such);
}

function openMapa()
{
	tb_show(false,"imagem.html?width=670&amp;height=500&amp;modal=false",null);
}

/* Ajax pra excluir os últimos visitados */
function removeAjax( id, idRegiao )
{
    idEmpreendimentoRemove      =   id;
    
    jQuery.ajax
    (
        {
            url:    '_services/AJAX-remove.php',
            cache:  false,
            type:   'POST',
            data:
            {
                idEmpreendimentoRemove:  idEmpreendimentoRemove
            },
            dataType: 'html',
            error: function()
            {
                alert('Ocorreu um erro ao tentar excluir o item visitado. Tente novamente.');
            },
            success:
            function(data)
            {
                $(".list-last-visited").find('ul').html("");
                insereVisitados(idRegiao);   
            }
        }
    )            
}

function mapanchor(link,teste){
	
	location.href = link;
	
	if(teste == 'true')
	{
		
		$("#informacoes-gerais > li > a").each(function(){
			if( $(this).attr('href') == "#financie" )
			{
				$(this).trigger("click");
			}
		});
		
	}
	
}


jQuery('document').ready(function()
{
	var assinaturaContent = '<object height="13" width="65" id="musicplayer" data="_swf/signFess.swf" type="application/x-shockwave-flash">';
	assinaturaContent += '<param value="_swf/signFess.swf" name="movie">';
	assinaturaContent += '<param value="high" name="quality">';
	assinaturaContent += '<param value="#ffffff" name="bgcolor">';
	assinaturaContent += '<param value="false" name="autoplay">';
	assinaturaContent += '<param value="true" name="loop">';
	assinaturaContent += '<param value="transparent" name="wmode">';
	assinaturaContent += '<param value="showall" name="scale">';
	assinaturaContent += '<param value="true" name="menu">';
	assinaturaContent += '<param value="false" name="devicefont">';
	assinaturaContent += '<param value="" name="salign">';
	assinaturaContent += '<param value="sameDomain" name="allowScriptAccess">';
	assinaturaContent += '</object>';
	
	jQuery('.fess-logo').html(assinaturaContent);
	
	if (isCorretoronline == 1){
		openInteracao('interacaocomcorretor','','','','','','');
	}
	if (isInformacoesporemail == 1){
		openInteracao('informacoesporemail','','','','','','');
	}
	/* Compartilhe */
	$('div.email, div.celular').hide();
	
	$('a#email').click(function(){
		$('div.celular').hide();
		$('div.email').show();
		
		var elementoPosition = $(this).parent().position().left;
		
		$('.indicadorAzul').animate({
			 marginLeft: elementoPosition -5
		},500);
		
		$('.fechaElemento').css({marginLeft: elementoPosition - 4});
		$('.fechaElemento').click(function(){$('div.email').fadeOut();});
	});
	
	$('a#celular').click(function(){
		$('div.email').hide();
		$('div.celular').show();
		
		var elementoPosition = $(this).parent().position().left;
		
		$('.indicadorAzul').animate({
			 marginLeft: elementoPosition -4
		},500);
		
		$('.fechaElemento').css({marginLeft: elementoPosition - 4});
		$('.fechaElemento').click(function(){$('div.celular').fadeOut();});
	});
	
	/* fim */
	
    /* Ajax para envio de tweets */
    $("#enviar-tweet-emp").bind("click",function(){
       
        var loginTwitter        = "";
        var passTwitter         = "";
        var idEmpTwitter        = 0;
       
        loginTwitter =  $("#input-nome-twitter").val();
        passTwitter  =  $("#input-senha-twitter").val();
        idEmpTwitter =  $("#idEmpreendimentoForm").val();
       
        jQuery.ajax
        (
            {
                url:    '_services/envio_twitter.php',
                cache:  false,
                type:   'POST',
                data:
                {
                    login:  loginTwitter,
                    senha:  passTwitter,
                    id:     idEmpTwitter
                },
                dataType: 'json',
                error: function()
                {
                    alert('Não foi possível completar essa ação. Verifique a sua conexão.');
                },
                success:
                function(data)
                {		
                    if( data.ok == "true" )
                    {
                      alert('Sua mensagem foi enviada com sucesso.')
                    }
                    else
                    {
                      alert('Ocorreu um erro. Tente novamente.')
                    }
                }
            }
        )
       
    });

    /* Ajax para envio de emails */
    $("#enviar-email-emp").bind("click",function(){
        var nomeEnvioEmail      = "";
        var emailEnvioEmail     = "";
        var idEmpEmail          = 0;
        
        nomeEnvioEmail  = $("#input-nome-email").val();
        emailEnvioEmail = $("#input-email-email").val();
        idEmpEmail      =  $("#idEmpreendimentoForm").val();
        
        jQuery.ajax
        (
            {
                url:    '_services/envio_email.php',
                cache:  false,
                type:   'POST',
                data:
                {
                    nome:   nomeEnvioEmail,
                    email:  emailEnvioEmail,
                    id:     idEmpEmail
                },
                dataType: 'json',
                error: function()
                {
                    alert('Não foi possível completar essa ação. Verifique a sua conexão.');
                },
                success:
                function(data)
                {
					
                    if( data.ok == "true" )
                    {
                      alert('Dados enviados para o e-mail')
                    }
                    else
                    {
                      alert('Ocorreu um erro. Tente novamente.')
                    }
                }
            }
        )
    })
	
	
    //OVER DOS BOTÕES DE CARROSSEL DA HOME
	if (jQuery('ul.abas-etapas > li').eq(0).hasClass('lancamento')){
		jQuery('ul.abas-etapas > li').eq(0).addClass('ativo');
		jQuery('.carrossel-home').eq(1).show();	
	}
	if (jQuery('ul.abas-etapas > li').eq(1).hasClass('lancamento')){
		jQuery('ul.abas-etapas > li').eq(1).addClass('ativo');
		jQuery('.carrossel-home').eq(1).show();	
	}
	
	
	jQuery('ul.abas-etapas > li > a').click(function(){
		jQuery('ul.abas-etapas > li > a').each(function(i){
			jQuery(this).parent().removeClass('ativo');
		});
		
		var idVisivel = jQuery(this).parent().attr("class");
		jQuery('.carrossel-home').each(function(){
			jQuery(this).hide();
		});
		jQuery('#'+idVisivel).show();
		jQuery(this).parent().addClass('ativo');
		return false;
	});
	
	
	//OVER DOS BOTÕES DE CARROSSEL DE IMAGENS DA INTERNA
	jQuery('ul.abas-imagens-imovel > li').eq(0).addClass('ativo');
	jQuery('.carrossel-imovel').eq(0).show();
	
	jQuery('ul.abas-imagens-imovel > li > a').click(function(){
		if(jQuery(this).attr('id') != "3d-nav" && jQuery(this).attr('id') != "folderdigital-nav")
		{
			jQuery('ul.abas-imagens-imovel > li').each(function(i){
				jQuery(this).removeClass('ativo');
			});	
			jQuery(this).parent().addClass('ativo');
			jQuery('.carrossel-imovel').each(function(){
				jQuery(this).hide();
			});
			var hrefAba = jQuery(this).attr("href");
			jQuery(hrefAba).show();
			return false;
		}
	});
	
	
	//OVER DOS BOTÕES DE CARROSSEL DE IMAGENS DA INTERNA
	jQuery('ul.abas-outros-imovel > li').eq(0).addClass('ativo');
	jQuery('.outros-content').eq(0).show(); 
	jQuery('ul.abas-outros-imovel > li > a').click(function(){
		jQuery('ul.abas-outros-imovel > li').each(function(i){
			jQuery(this).removeClass('ativo');
		});	
		jQuery(this).parent().addClass('ativo');
		jQuery('.outros-content').each(function(){
			jQuery(this).hide();
		});
		var hrefAba = jQuery(this).attr("href");
		jQuery(hrefAba).show();
		return false;
	});
	
	
	
	/*mostra mapa do site*/
	jQuery('.map-content').hide();
	jQuery('.open-mapa').click(function()
	{
		if( $(".map-content").is(":visible") )
		{
			jQuery('.open-mapa').find('img').attr('src', '_images/mapa-site-inativo.png');
		}
		else
		{
			jQuery('.open-mapa').find('img').attr('src', '_images/mapa-site-ativo.png');
			$('html, body').animate({scrollTop: $(document).height()},1000);
		}
		$('.map-content').slideToggle('600');
	});
	
	
	/*apaga bt*/
	jQuery('div.bank-flags').hide();
	jQuery('#bt-desapair').click(function(){
		jQuery(this).fadeOut('fast', function(){
			jQuery('.texto-simule').css('background-color', "#FFF");
			jQuery('div.bank-flags').fadeIn('fast');
		});
	});

	/*jQuery('table.progress-phase div.fill-progress').each(function(i){
		jQuery('.value-progress').eq(i).text(jQuery(this).css('width') );
	});*/

	/*ABAS SOCIAL MEDIA*/
	//jQuery('.abas-social-media').children().hide();
	jQuery('a.bt-voltar-social').click(function(){
		jQuery('a.bt-voltar-social').css('visibility',"hidden");
		jQuery('.abas-social-media').children().fadeOut('normal');
		jQuery('.textos-abas').text('');
	});
	
	/*jQuery('#envie-celular').click(function(){
		jQuery('.abas-social-media').css("visibility","visible");
		jQuery("#celular").fadeIn('normal');
		jQuery('.bt-voltar-social').css("visibility","visible");
	});*/
	
	
	jQuery('.social-media-list li a').each(function(){
        if(jQuery(this).attr('class') != 'rss'){
            jQuery(this).click(function(){
                //jQuery('.abas-social-media').css("visibility","visible");
                jQuery(jQuery('.abas-social-media').children()).fadeOut('slow');
                jQuery(jQuery(this).attr('href')).fadeIn('normal');
                
                if(jQuery(this).attr('href') != "#RSS")			
                    jQuery('.bt-voltar-social').css("visibility","visible");
                    
                return false;
            });
        }
	});
	
	var textoativo = '';
	var separa = '';
    
    $('.social-media-list li a').each
    (
        function()
        {
            if($(this).attr("class") == 'email')
            {
				this.ativo = true;
				$(this).css("border","1px solid #c7c6c6");
			    $(this).css("background-color","white");
				$(this).css("border-bottom","2px solid white");
            }
        }
            
    )
    
	$('.social-media-list li a').bind
    (
        'click',
        function()
        {
            jQuery('.social-media-list li a').each(function()
            {
                $(this).css("border","0");
				$(this).css("background-color","transparent");
                this.ativo = false;
            });
            this.ativo = true;
            $(this).css("border","1px solid #c7c6c6");
				 $(this).css("border-bottom","2px solid white");
				 $(this).css("background-color","white");
            separa = $(this).attr('href').split("#");
            textoativo = separa[1];
        }
    );
	
	$('.social-media-list li a').bind('mouseover',function(){
	
	});
	
	$('.social-media-list li a').bind
    (
        'mouseleave',function()
        {
            if( this.ativo == true )
                $(this).css("background-position","center center");
            else
            {
              
                jQuery('.textos-abas').text(textoativo);
            }
        }
    );
	
	jQuery('.social-media-list li a').each(function(){
		//var legendaMedia = jQuery(this).text();
		jQuery(this).mouseover(function(){	
			jQuery('.textos-abas').text(legendaMedia);
		});
		jQuery(this).mouseleave(function(){
			//jQuery('.textos-abas').text();
		});
	});


	jQuery('table.table-imoveis tbody tr.item').each(function(){
		jQuery(this).find('td').addClass('rule-bottom');
	});
	jQuery('table.table-imoveis tbody tr.item:last').each(function(){
		jQuery(this).find('td').removeClass('rule-bottom');
	})
	
	/*TABELA DE FICHA TÉCNICA*/
	jQuery(jQuery('table.ficha-tecnica tbody tr:nth-child(odd)')).each(function(){
		jQuery(this).find('td').addClass('oddLine');
	});
	jQuery('table.ficha-tecnica tbody tr td:nth-child(odd)').addClass('title-ficha-tecnica');

	/*FAZ O LINK DO MENU FICAR ATIVO QUANDO A PÁGINA FOR CARREGADA*/
	paginaAtual = window.location+"";
	paginaAtual = paginaAtual.split("/").pop();
	if(paginaAtual != ""){
		jQuery('li.teste a[href="'+paginaAtual+'"]').addClass('ativo');
		jQuery('li.teste a[href="'+paginaAtual+'"]').siblings('ul').removeClass('recolheSubItem');
		jQuery('li.teste a[href="'+paginaAtual+'"]').parents('ul').removeClass('recolheSubItem').siblings('a').addClass('ativo');
	}   
});

var Main = 
{
	manageFavorite: function(idEmpreendimento, mode, postAction)
	{
		 jQuery.post
		 (
		  	CFG_URL + '_services/set_imovel_favorito.php',
			{idEmpreendimento: idEmpreendimento, action: mode},
			postAction
		 );
	},
	setFlashPoint: function(id, objRef)
	{
		jQuery('#navega-itens a').removeClass('active');
		jQuery(objRef).addClass('active');
		
		var target = navigator.appName.indexOf("Microsoft") != -1 ? window['flashImplantacaoMovie'] : document['flashImplantacaoMovie'];
		try{target.change(id);}catch(e){}
		return false;
	}
};

/* lightbox gallery */
var LightGallery =
{
	pick	    : null,
	index	    : 0,
    intervalo   : null,
	intervaloGal: null,
	
	init	: function()		
	{		
		jQuery('#light-navLeft').click(
			function() {
				LightGallery.prev();
			}
		)
		jQuery('#light-navRight').click(
			function() {
				LightGallery.next();
			}
		)
		LightGallery.index = 0;
	},
	setItem	: function(intIndex) {
		//alert(1);
		jQuery('#image-loader').animate({
			"opacity"	: "1"
		}, 100);
					
		jQuery('#pic').fadeOut();
		jQuery('#pic').hide();
		
		if (arIdImages != false) idImagemEmpreendimento = arIdImages[intIndex];
	
		LightGallery.index = intIndex;
		
		if(intIndex == 0) {
			jQuery('#light-navLeft').hide();
		}
		
		if( intIndex == (arImages.length-1) ) {
			jQuery('#light-navRight').hide();
		}
		
		jQuery('#image-loader').animate({
			"opacity"	: "0"
		}, 200);
		jQuery('#pic').attr('src', arImages[LightGallery.index]).load(LightGallery.loadComplete());
	},
	 
	loadComplete : function(a)
	{
		if(swfobject.hasFlashPlayerVersion("9") == false){
			$('html, body').animate({scrollTop: 0},2000);
		}
		
		clearInterval(LightGallery.intervaloGal);
		LightGallery.intervaloGal = setInterval('LightGallery.alinhaImagem()', 700);
		
        var arTipos = new Array();
        arTipos[1] = "Projeto";
        arTipos[2] = "Plantas";
        arTipos[3] = "Bairro";
        arTipos[4] = "Obras";
        arTipos[5] = "Lazer";
		jQuery('.lbl').html(arSubTitles[LightGallery.index]);
		jQuery('#lbl-contador').html('Imagem '+(LightGallery.index+1)+' de '+arSubTitles.length);
        //jQuery('.titulo-galeria > p').html(arTipos[arSubTitlesarea[LightGallery.index]]);
		jQuery('.titulo-galeria > p').html(arSubTitles[LightGallery.index]);
	},
	
	alinhaImagem : function(){
		if(arImages[LightGallery.index] == jQuery('#pic').attr("src")){
			var topoHeight = $(".titulo-galeria").height();
			var footerHeight = $(".footer-galeria").height();
			var holderImgHeight = $(".holder-galeria").height() - footerHeight - topoHeight;
			$(".imagem-galeria").height(holderImgHeight);
			$(".imagem-galeria > img").height($(".imagem-galeria").height());
			$(".imagem-galeria").width($(".imagem-galeria > img").width());
			jQuery(".imagem-galeria").css("margin", "0 auto");
			jQuery('#pic').fadeIn();
			
			clearInterval(LightGallery.intervaloGal);
		}
	},

	onError	: function(error)
	{
		tb_remove();
	},
	
	prev	: function()
	{
		if(LightGallery.index > 0) {
			LightGallery.setItem(LightGallery.index - 1);
			jQuery('#light-navRight').show();
		}
	},
	next	: function() {
		if(LightGallery.index < (arImages.length - 1)) {
			LightGallery.setItem(parseInt(LightGallery.index) + 1);
		}
		jQuery('#light-navLeft').show();
	},
    nextSlideShow	: function() {
        if(LightGallery.index < arImages.length - 1)
        {
            LightGallery.next();
        }
        else
        {
            LightGallery.setItem(0);  
        }
	},
	slideShow : function() {
        slideIniciado = true;
        LightGallery.intervalo = setInterval
        (
           'LightGallery.nextSlideShow()',
            3000
        );
	},
    stopSlideShow : function()
    {
		$(".holder-galeria").remove();
        clearInterval(LightGallery.intervaloGal);
		clearInterval(LightGallery.intervalo);
    }
}

var VideoGallery =
{
	pick	    : null,
	index	    : 0,
    intervalo   : null,
	init	: function( indexInicial )		
	{
		jQuery('#light-navLeft').bind(
			'click',
			function()
			{
				VideoGallery.prev();
			}
		)
		jQuery('#light-navRight').bind(
			'click',
			function()
			{
				VideoGallery.next();
			}
		)
		VideoGallery.index = indexInicial;
		
		if(VideoGallery.index == 0)
		{
			jQuery('#light-navLeft').hide();
		}
		
		if( VideoGallery.index == (arVideos.length-1) )
		{
			jQuery('#light-navRight').hide();
		}
		
	},
	setItem	: function(intIndex)
	{
		VideoGallery.index = intIndex;
		
		$("#legenda_imagem").html( arVideosLeg[ VideoGallery.index ] );	
		$(".troca-video").fadeOut();
		$(".troca-video").html('');
		
		var embedaSwf = '';
		embedaSwf += '<object width="560" height="405">';
		embedaSwf += 	'<param id="youtube" name="movie" value="http://www.youtube.com/v/' + arVideos[VideoGallery.index] + '?fs=1&amp;hl=pt_BR"></param>';
		embedaSwf += 	'<param name="allowFullScreen" value="true"></param>';
		embedaSwf += 	'<param name="allowscriptaccess" value="always"></param>';
		embedaSwf += 	'<param name="wmode" value="transparent"></param>';
		embedaSwf += 	'<embed id="youtubeIE" src="http://www.youtube.com/v/' + arVideos[VideoGallery.index] + '?fs=1&amp;hl=pt_BR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" wmode="transparent" height="405"></embed>';
		embedaSwf += '</object>';
		
		$(".troca-video").fadeIn();
		$(".troca-video").html(embedaSwf);
		
		if(VideoGallery.index == 0)
		{
			jQuery('#light-navLeft').hide();
		}
		
		if( VideoGallery.index == (arVideos.length-1) )
		{
			jQuery('#light-navRight').hide();
		}
		
		
	},
	loadComplete	: function()
	{
		jQuery('#image-loader').animate({
			"opacity"	: "0"
		}, 100);
				
		jQuery('#pic').attr('src', VideoGallery.pick['src']);
		jQuery('#pic').animate({
			"opacity"	: "1"
		}, 500);
		
        var arTipos = new Array();
        arTipos[1] = "Projeto";
        arTipos[2] = "Plantas";
        arTipos[3] = "Bairro";
        arTipos[4] = "Obras";
        arTipos[5] = "Lazer";
        
		jQuery('.lbl').html(arSubTitles[VideoGallery.index]);
		jQuery('.lbl-contador').html((VideoGallery.index+1)+' de '+arSubTitles.length);
        jQuery('.legenda-area > p').html(  arTipos[arSubTitlesarea[VideoGallery.index]] );
	},
	onError	: function(error)
	{
		tb_remove();
	},
	prev	: function()
	{
		if(VideoGallery.index > 0)
		{
			VideoGallery.setItem(VideoGallery.index - 1);
			jQuery('#light-navRight').show();
		}
	},
	next	: function()
	{
		if(VideoGallery.index < (arVideos.length - 1))
		{
			VideoGallery.setItem(parseInt(VideoGallery.index) + 1);
		}
		jQuery('#light-navLeft').show();
	}
}
