$(document).ready(function() {
	
	$.getScript("inc/js/fav.js");
	
	//animacao
	if ($("#animacao").length>0) {
		$('#animacao').loopedSlider({
			autoStart: 4000,
			restart: 5000,
			slidespeed: 1000, 
			containerClick: false,
			addPagination: true
		});
	}
	
	//tooltips
	if ($(".tooltip").length>0) {
		$(".tooltip").tooltip({ 
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: " - ", 
			fade: 250 
		});
	}

	//fotos do imovel
	if ($("#fotos").length>0) {
		$('#fotos .items a').lightBox();
		$("#fotos div.scrollArea").scrollable({
			loop: true, 
			speed: 1200,
			size: 3
		});
	}

	//enviar por email
	if ($("#enviar-por-email").length>0) {
		$("#enviar-por-email").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 140,
			modal: true,
			width: 330,
			resizable: false
		});
		$(".icones .email, .label .email").click(function(){
			$("#enviar-por-email").dialog('open');
			return false;
		});
	}

	//ligamos para voce
	if (("#ligamos").length>0) {
		$("#ligamos").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 140,
			modal: true,
			width: 330,
			resizable: false
		});
		$("#header .ligue").click(function(){
			$("#ligamos").dialog('open');
			return false;
		});
	}
	
	//enviar por email
	if (("#enviar-por-email").length>0) {
		$("#enviar-por-email").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 140,
			modal: true,
			width: 330,
			resizable: false
		});
		$(".abre_enviar").click(function(){
			$("#enviar-por-email").dialog('open');
			return false;
		});
	}		
	
	//busca
	if ($("#fbusca").length>0) {
		//$("#busca input[name=cidade]").change(function(){
		//	$("#busca").submit();
		//});
		$("#fbusca select").each(function(){
			$(this).change(function(){
				$("#fbusca").submit();
			});
		});		
	}	
	
	$('.voltar').click(function(){
		history.go(-1);
	});		
	
});

function mapa_imovel(l1,l2,tipo,controles,mapid) {
	if ( tipo === undefined ) tipo = 'ponto';
	if ( controles === undefined ) controles = true;
	if ( mapid === undefined ) mapid = "map";
	if ($("#"+mapid).length>0) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById(mapid));
			map.setCenter(new GLatLng(l1,l2), 15);
			var latlng = new GLatLng(l1,l2);
			if (controles) {
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
			}
			if (tipo=='circulo') {
				var marcador = GPolygon.Circle(latlng, 500,"#900",3,1,"#000",0.2)
				map.addOverlay(marcador);
			} else {
				var icone = new GIcon(G_DEFAULT_ICON);
				icone.image = "img/design/gmaps_icon.png";
				icone.iconSize = new GSize(21, 31);
				markerOptions = { icon:icone };
				map.addOverlay(new GMarker(latlng, markerOptions));
			}
		}
	}
}


