/*
	## Googlemaps.js
	
	Auteur:		Harm Jan Luth
	Bedrijf:	TDC Lighthouse
	Klant:		Bibliotheek Utrecht
	Functie:	Laad de map waarop vestigingen te zien zijn

*/	

// try this (add http:// if needed)
if (GBrowserIsCompatible()) {
//<![CDATA[
		var markers = [];
		
		var title1 = "";
		var content1 = "";
		var title2 = "";
		var content2 = "";
	    
		var map = new GMap2(document.getElementById("googleMap"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.setCenter(new GLatLng(52.08741761408255, 5.1258087158203125), 11, G_SATELLITE_MAP);
			
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.shadow = "";
		baseIcon.iconSize = new GSize(38, 35);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(50, 50);
		baseIcon.infoWindowAnchor = new GPoint(28, 34);
		
		//get host for url custom icon in graphics folder
		var url = window.location.href;
		var nohttp = url.split('//')[1];
		var host = nohttp.split('/')[0]
		
		// Creates a marker whose info window displays the letter corresponding
		// to the given index.
		function createMarker(point,type) {
		  // Create a lettered icon for this point using our icon class
		  var customIcon = new GIcon(baseIcon);
		  
		  if(type == "gray") {
			  customIcon.image = "http://"+host+"/html/bibliotheekutrecht/graphics/icoon-bu-gray.png";
		  }
		  else {
			  customIcon.image = "http://"+host+"/html/bibliotheekutrecht/graphics/icoon-bu.png";
		  }
		  // Set up our GMarkerOptions object
		  markerOptions = { icon:customIcon };
		  var marker = new GMarker(point, markerOptions);
		  
		  var tabs = [];
		  tabs.push(new GInfoWindowTab(unescape(title1), unescape(content1)));
		  
		  if(title2 != "") {
		  	tabs.push(new GInfoWindowTab(unescape(title2), unescape(content2)));
		  }
		  
		  GEvent.addListener(marker, "click", function() {
		    marker.openInfoWindowHtml(tabs);
		  });
		  return marker;
		}
		

		// Random markers test for layout
		//var bounds = map.getBounds();
		//var southWest = bounds.getSouthWest();
		//var northEast = bounds.getNorthEast();
		//var lngSpan = northEast.lng() - southWest.lng();
		//var latSpan = northEast.lat() - southWest.lat();
		//for (var i = 0; i < 10; i++) {
		//  var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
		//                          southWest.lng() + lngSpan * Math.random());
		//  map.addOverlay(createMarker(point, i));
		//}

	
	
}
//]]>