// JavaScript Document


$(document).ready(function() {

if(jQuery("#map_canvas").length != 0)
{
		var map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
		// Create a base icon for all of our markers that specifies the
//		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.image = "/seeandact.nl/img/beachflag.png";
		baseIcon.shadow = "/seeandact.nl.nl/img/beachflag_shadow.png";
		baseIcon.iconSize = new GSize(79, 44);
		baseIcon.shadowSize = new GSize(48, 19);
		baseIcon.iconAnchor = new GPoint(20, 24);
		baseIcon.iconWindowAnchor = new GPoint(20, 2);
		
		
		
		
		var geocoder = new GClientGeocoder();
		var address = 'Aan vijftien 15, Nederweert';
		
		geocoder.getLatLng(address,
		    	function(point) 
		    	{
		      		if (!point) 
		      		{
		        		alert(address + " not found");
		      		} 
		      		else 
		      		{
		        		map.setCenter(point, 13);
		        	//	var marker = new GMarker(point);
		        		//map.addOverlay(marker);
		        		baseIcon.infoWindowAnchor = new GPoint(9, 2);
//		        		var bounds = map.getBounds();
//						var southWest = bounds.getSouthWest();
//						var northEast = bounds.getNorthEast();
//						var lngSpan = northEast.lng() - southWest.lng();
//						var latSpan = northEast.lat() - southWest.lat();
		        		map.addOverlay(createMarker(point, 0));
//		        		marker.openInfoWindowHtml(address);
		      		}
		    	}
		  	);
		
		
//		map.setCenter(new GLatLng(37.4419, -122.1419), 13);
//		
//		baseIcon.infoWindowAnchor = new GPoint(9, 2);
//		
//   	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 point = new GLatLng(southWest.lat() + latSpan * Math.random(),
//		                          southWest.lng() + lngSpan * Math.random());
//		  map.addOverlay(createMarker(point, 0));
		
}


// Creates a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, index) 
{
  	// Create a lettered icon for this point using our icon class
  	var letter = String.fromCharCode("A".charCodeAt(0) + index);
  	var letteredIcon = new GIcon(baseIcon);
  	
  	// Set up our GMarkerOptions object
  	markerOptions = { icon:letteredIcon };
  		var marker = new GMarker(point, markerOptions);

  	GEvent.addListener(marker, "click", function() 
  	{
 	   marker.openInfoWindowHtml("See & Act");
  	});
  return marker;
}
	
	function codeAddress() 
	{
	    var address = 'Aan vijftien 15, Nederweert';
	    var image = new google.maps.MarkerImage('/seeandact.nl/img/beachflag.png',
	      // This marker is 20 pixels wide by 32 pixels tall.
	      new google.maps.Size(40, 46),
	      // The origin for this image is 0,0.
	      new google.maps.Point(0,0),
	      // The anchor for this image is the base of the flagpole at 0,32.
	      new google.maps.Point(48, 19));
	      var shadow = new google.maps.MarkerImage('/seeandact.nl/img/beachflag_shadow.png',
	      // The shadow image is larger in the horizontal dimension
	      // while the position and offset are the same as for the main image.
	      new google.maps.Size(33, 17),
	      new google.maps.Point(0,0),
	      new google.maps.Point(0, 25));	      
	
	    
	    if (geocoder) 
	    {
	      	geocoder.geocode( { 'address': address}, function(results, status) 
	      	{
	        	if (status == google.maps.GeocoderStatus.OK) 
	        	{
	          		map.setCenter(results[0].geometry.location);
	          		var marker = new google.maps.Marker({
	              		map: map, 
	              		position: results[0].geometry.location,
	              		shadow: shadow,
	              		icon: image
	          		});
	          		
	          		GEvent.addListener(marker, "click", function() {
					    marker.openInfoWindowHtml("Marker <b>GetNotced</b>");
					});

	        	} 
	        	else 
	        	{
	          		alert("Geocode was not successful for the following reason: " + status);
	        	}
	      	});
	    }
	}
						   
});

