$(document).ready(function(){

		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		
		map.setCenter(new GLatLng(37.4419, -122.1419), 1);
			
	    map.enableScrollWheelZoom();

		$.getJSON(url, function(data){

		var latitude = null;
		var longitude = null;

		var focused = data.focused;
		var points = data.points;
		
		
		
		latitude = null;
		longitude = null;
		
		$.each(points, function(i, point){

			if (point.item_type == 'latitude')
				latitude = point.value;

			if (point.item_type == 'longitude')
				longitude = point.value;

			if (latitude != undefined && longitude != undefined){
				
				var marker = new GMarker(new GLatLng(latitude, longitude));

				 GEvent.addListener(marker, "click", function() {
				        marker.openInfoWindowHtml('<a href="' + siteUrl('question/') + point.collective_id + '/' + point.url_title + '">' + point.title + '</a>');
				 });
								
				map.addOverlay(marker);	
				latitude = null;
				longitude = null;
			}					
			
		});

		if (focused != undefined){
			
			$.each(focused, function(i, focal){

				if (focal.item_type == 'latitude')
					latitude = focal.value;

				if (focal.item_type == 'longitude')
					longitude = focal.value;

				if (latitude != undefined && longitude != undefined){

						var marker = new GMarker(new GLatLng(latitude, longitude));
						
						 GEvent.addListener(marker, "click", function() {
						        marker.openInfoWindowHtml('<a href="' +  siteUrl('question/') + focal.collective_id + '/' + focal.url_title + '">' + focal.title + '</a>');
						 });

						 map.addOverlay(marker);
						 map.setCenter(new GLatLng(latitude, longitude), 5);
						 
						 GEvent.trigger(marker, "click");
						 
				}
			});
			}

	
	});
		
	});
