

function initMap (){


}


function presentFancyBox (id_publication){
	//alert(id_publication);
	  	$.fancybox({
	  			'href'				: '?action=Propiedad&id='+id_publication,
				'width'				: 889,

				'padding'			: 1,
				'height'			: 533,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'

			});
	
}


function getJsonMapSearchFromURL () {
	if ($('#map').val()==undefined) return true; // si existen publicaciones no mnostramos el mapa
	var centerCoord = new google.maps.LatLng(19.69950, -101.20028);  // Morelia, Mich., Mx.
	
	var map;
	var arrMarkers = [];
	var arrInfoWindows = [];

	var mapOptions = {
			zoom: 13,
			center: centerCoord,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		
		
	map = new google.maps.Map(document.getElementById("map"), mapOptions);
	
	
	$.getJSON("index.php?actionajax=getPropiedades", function(data){
		$.each(data.publications, function(i, item){
			var marker = new google.maps.Marker({
				position: new google.maps.LatLng(item.latitude, item.longitude),
				map: map,
				title: item.title,
				icon: 'img/zonau_trimmed.png'
			});
						
			arrMarkers[i] = marker;
			
			
			// check if the publication belongs to a real estate office.
			if (item.user_thumbnail == null){
				
				var htmlContentString = $("#googleMapInfoWindowCode_oneImage").html();
				htmlContentString = htmlContentString.replace("[=publication.title=]", item.title);
				htmlContentString = htmlContentString.replace("[=publication.description=]", item.description);
				if (item.images == null) {
					htmlContentString = htmlContentString.replace("[=publication.thumbnail=]","./img/zonau_90x90_color.png");
				}
				else {
					htmlContentString = htmlContentString.replace("[=publication.thumbnail=]","./"+item.images);
				}
				//htmlContentString = htmlContentString.replace("[=publication.url=]","<a style=\"color:#269D2F; font-size:13px;\" onClick=\"javascript:presentFancyBox("+item.id_publication+");\">Ver detalles</a>");
				htmlContentString = htmlContentString.replace("[=publication.url=]","<a class=\"map_infowindow_link\" style=\"color:#000; font-size:13px;\" onClick=\"javascript:presentFancyBox("+item.id_publication+");\">Ver detalles</a>");
				
				var infowindow = new google.maps.InfoWindow({
					maxWidth: 800,
					content:htmlContentString
				});
			} else {
				var htmlContentString = $("#googleMapInfoWindowCode_twoImages").html();
				htmlContentString = htmlContentString.replace("[=publication.title=]", item.title);
				htmlContentString = htmlContentString.replace("[=publication.description=]", item.description);
				if (item.images == null)
					htmlContentString = htmlContentString.replace("[=publication.thumbnail=]","./img/zonau_90x90_color.png");
				else
					htmlContentString = htmlContentString.replace("[=publication.thumbnail=]","./"+item.images);
				htmlContentString = htmlContentString.replace("[user.real_estate_thumbnail]","./"+item.user_thumbnail);
				htmlContentString = htmlContentString.replace("[=publication.url=]","<a class=\"map_infowindow_link\" style=\"color:#000; font-size:13px;\" onClick=\"javascript:presentFancyBox("+item.id_publication+");\">Ver detalles</a>");
				var infowindow = new google.maps.InfoWindow({
					maxWidth: 800,
					content:htmlContentString
				});	
			}

			
			
			
			arrInfoWindows[i] = infowindow;
			google.maps.event.addListener(marker, 'click', function() {
				for(x=0; x < arrInfoWindows.length; x++){ arrInfoWindows[x].close(); }
				infowindow.open(map, marker);
			});
		});
	});

  


	
}




