function gmap(lat,long) {
	if (GBrowserIsCompatible()) {
		$("#mapa").show();
				
				var circle = null;
				var circleRadius = 1; // Miles
			    var map = null;
				
				// Create Map
				map = new GMap2(document.getElementById("map"));
				map.setCenter(new GLatLng(lat,long), 13);
	
				// Add controls
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				
				// Create and add the circle
				circle = new CircleOverlay(map.getCenter(), circleRadius, "#336699", 1, 1, '#336699', 0.25);
				map.addOverlay(circle);
		
		$("#mapa").hide();
		
		$(".abremapa").click(function(){
			if ($("#mapa").is(":visible")) {
				$("#mapa").slideUp("slow");
			} else {
				$("#mapa").slideDown("slow",function(){
					map.checkResize();
				});
			}
			return false;
		});
		
	}
}

/*function gmap(lat,long) {
	if (GBrowserIsCompatible()) {
		$("#mapa").show();
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(lat,long), 15);
		var latlng = new GLatLng(lat,long);
		map.addOverlay(new GMarker(latlng));
		$("#mapa").hide();
		
		$(".abremapa").click(function(){
			if ($("#mapa").is(":visible")) {
				$("#mapa").slideUp("slow");
			} else {
				$("#mapa").slideDown("slow",function(){
					map.checkResize();
				});
			}
			return false;
		});
		
	}
}*/

$(document).ready(function() {
	
	//busca
	if ($('#busca').length>0) {
		
		var txtcod = $("#busca .codigo").val();
		$("#busca .codigo").focus(function(){
			if ($(this).val()==txtcod) $(this).val("");
		});
		$("#busca .codigo").blur(function(){
			if ($(this).val()=="") $(this).val(txtcod);
		});
	}
	
	//submit busca
	$("#fbusca").submit(function(){
		var livre = $.trim($("#codigo").val());
		if(livre!='Palavra-chave ou código') {
			if (isNaN(livre)) { $("#fbusca").attr('action','imoveis.php'); }
			else 			  { $("#fbusca").attr('action','detalhes.php'); }	 
		}
	});		

	//newsletter
	if ($("#newsletter").length>0) {
		var nnome = $("#newsletter .nnome").val();
		var nemail = $("#newsletter .nemail").val();
		$("#newsletter .nnome").focus(function(){
			if ($(this).val()==nnome) $(this).val("");
		});
		$("#newsletter .nnome").blur(function(){
			if ($(this).val()=="") $(this).val(nnome);
		});
		var nemail = $("#newsletter .nemail").val();
		$("#newsletter .nemail").focus(function(){
			if ($(this).val()==nemail) $(this).val("");
		});
		$("#newsletter .nemail").blur(function(){
			if ($(this).val()=="") $(this).val(nemail);
		});
	}
	
	//animacao da home
	if ($('#animacao').length>0) {
		$('#animacao').Horinaja({
			capture: 'animacao',
			delai: 0.3,
			duree: 4,
			pagination: true,
			nCell: 100
		});
	}
	
	
	//link total nos imoveis
	if ($("#leftContent .imoveis").length>0) {
		$("#leftContent .imoveis .imovel").mouseover(function(){
			$(this).addClass("ovr");
		});
		$("#leftContent .imoveis .imovel").mouseout(function(){
			$(this).removeClass("ovr");
		});
		$("#leftContent .imoveis .imovel").click(function(){
			lnk = $(this).find(".foto a").attr("href");
			if (lnk!='' && lnk!=undefined)
			window.location = lnk;
		});
	}
	
	//tooltips
	if ($(".tooltip").length>0) {
		$(".tooltip").tooltip({ 
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: " - ", 
			fade: 250 
		});
	}
	
	//fotos do imovel
	if ($("#fotos").length>0) {
		$('#fotos li a').lightBox();
	}
	
	//modal
	if ($("#liberar").length>0) {
		$("#liberar").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 140,
			modal: true,
			width: 330,
			resizable: false,
			closeOnEscape: false,
			open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
		});
	}
	if ($("#bloqueado").length>0) {
		$("#liberar").dialog('open');
	}	
	
});

