function mapa_imovel(l1,l2) {
	if ($("#map").length>0) {
		if (GBrowserIsCompatible()) {
			
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(l1,l2), 15);
			var icone = new GIcon(G_DEFAULT_ICON);
			icone.image = "img/design/icon_gmap.png";
			icone.iconSize = new GSize(23, 33);
			markerOptions = { icon:icone };
			var latlng = new GLatLng(l1,l2);
			map.addOverlay(new GMarker(latlng, markerOptions));
			if ($("#localizacao").length>0) {
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				map.addMapType(G_SATELLITE_3D_MAP);
				var mapControl = new GMapTypeControl();
				map.addControl(mapControl);
			}
		}
		if ($("#localizacao").length>0) {
			$("#localizacao").dialog({
				autoOpen: false,
				bgiframe: true,
				minHeight: 140,
				modal: true,
				width: 934,
				resizable: false
			});
			$(".abre_mapa").click(function(){
				$("#localizacao").dialog('open');
				map.checkResize() 
				return false;
			});
		}
	}
}


function carregaBairros() {
	var cidade = $('#busca_cidade').val();

	$("#listabairros").html('<div id="listabairros">Carregando...</div>');

	if(cidade!=''){
		 $.get("inc/lib/fnc_load-busca.php?act=bairros", {cidade: cidade},
			function(data){
				$("#listabairros").html(data);
			})			
	}
}	

$(document).ready(function() {
	
	//animação home
	if ($('#animacao').length>0) {
		$('#animacao').Horinaja({
			capture: 'animacao',
			delai: 0.3,
			duree: 4,
			pagination: true,
			nCell: 100
		});
	}
	
	//bairros busca
	carregaBairros();
	$("#busca_cidade").change(function(){ carregaBairros(); });		
	
	//submit busca
	$("#fbusca").submit(function(){
		var livre = $.trim($("#codigo").val());
		if(livre!='') {
			if (isNaN(livre)) { $("#fbusca").attr('action','imoveis.php'); }
			else 			  { $("#fbusca").attr('action','detalhes.php'); }	 
		}
	});	

	//hover no campo codigo na busca
	if ($('#busca').length>0) {
		$('#busca .codigo').focus(function(){
			v = $(this).val();
			if (v=='Codigo') $(this).val("");
		});
		$('#busca .codigo').blur(function(){
			v = $(this).val();
			if (v=='') $(this).val("Codigo");
		});
	}

	
	//fotos do imovel
	if ($("#imovel-fotos").length>0) {
		$('#imovel-fotos .items a').lightBox();
		$("div.scrollArea").scrollable({
			//next: 'div.btnRight', 
			//prev: 'div.btnLeft',
			loop: true, 
		    size: 7,
			speed: 1000
		});
	}

	//icones do imovel
	$("#detalhes .icones li a").hover(function(){
		alt = $(this).find("img").attr("alt");
		$("#detalhes .icones li.legenda").html(alt);
	},function(){
		$("#detalhes .icones li.legenda").html("");
	});

	//enviar por email
	if ($("#newsletter").length>0) {
		$("#newsletter").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 140,
			modal: true,
			width: 330,
			resizable: false
		});
		$(".bn_newsletter").click(function(){
			$("#newsletter").dialog('open');
			return false;
		});
	}

	//youtube
	if ($("#video").length>0) {
		$("#video").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 340,
			modal: true,
			width: 560,
			resizable: false
		});
		$(".abre_youtube").click(function(){
			$("#video").dialog('open');
			return false;
		});
	}
	


});
