google.load("maps", "2.x");
      
     	var sites = [
     	['22 Acre Site', '', 40.863838,-81.752754, 'site_22acre.php'], 
     	['4.65 Acre Site', ' ', 40.861663,-81.753591, 'site_4point65acre.php']
     	 
     	];
     	
     	var pop2 = '<div id="site_pop2" >&raquo;&nbsp;<a class="site-link" href="#">Click to View Profile</a></div>';

     	 $(document).ready(function(){
          
          var map = new GMap2(document.getElementById('building-map'));
          map.addControl(new GLargeMapControl());
          var startloc = new GLatLng(40.85646,-81.766702);
          
          map.setCenter(startloc, 14);
          
          var bounds = map.getBounds();
				var southWest = bounds.getSouthWest();
				var northEast = bounds.getNorthEast();
				var lngSpan = northEast.lng() - southWest.lng();
				var latSpan = northEast.lat() - southWest.lat();
				var markers = [];
				
				for (var i = 0; i < sites.length; i++) {
				    var point = new GLatLng(sites[i][2], sites[i][3]);
					marker = new GMarker(point);
					map.addOverlay(marker);
					markers[i] = marker;
				}
				
				$(markers).each(function(i,marker){
					
					$("<li />")
						.html("<a href='javascript:void();'>" + sites[i][0] + "</a>")
						.click(function(){
						
							displayPoint(marker, i);
							
							//$(this).append(pop2);
						})
						.appendTo("#site-list").attr("id", "site-item"+i);
					
					
					GEvent.addListener(marker, "click", function(){
						displayPoint(marker, i);
						
					});
				});
				
				$("#site-pop").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
				
				function displayPoint(marker, index){
					$("#site-pop").hide();
					$("#site_pop2").remove();
					
					$("#site-item"+index).append(pop2);
					$(".site-link").attr("href",sites[index][4]);
					
					var moveEnd = GEvent.addListener(map, "moveend", function(){
						var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
						$("#site-pop")
							.fadeIn()
							.css({ top:markerOffset.y, left:markerOffset.x });
						
						$(".site-name").html(sites[index][0]);
						$(".site-address").html(sites[index][1]);
						
						GEvent.removeListener(moveEnd);
					});
					map.panTo(marker.getLatLng());
				}
				
				
     	 });