                var geocoder;
                var map;
                var latlngbounds;
                var _marker_IDS;
                var _marker_latlocations;
                var _marker_lnglocations;
                var _siteroot;
                var _city;
                var _previous_zoomlevel = 0;
                var _location_project_IDS;
                var _zoomlevel;

                var _icon;
                function createIcon(iconFileName) {
                   var icon = new GIcon();
                   if (iconFileName) {
                      icon.image = iconFileName;
                   }
                   icon.iconSize = new GSize(32,37);
                   icon.iconAnchor = new GPoint(16, 37);
                   icon.infoWindowAnchor = new GPoint(5, 1);
                   return icon;
                }

                function initMap(id) {
                  map = new GMap2(document.getElementById(id));
                  map.addMapType(G_NORMAL_MAP);
                  map.setMapType(G_NORMAL_MAP);
                  var mapControl = new GSmallMapControl();
                  map.addControl(mapControl);
                  placeProjects();
                  centerMap();
                }

                function centerLoc(response) {
                  var point;
                  if (!response || response.Status.code != 200) {
                    point = new GLatLng(52.126744,5.372314);
                  } else {
                    place = response.Placemark[0];
                    point = new GLatLng(place.Point.coordinates[1],
                                place.Point.coordinates[0]);
                  }
                  var zoomlevel = 14;
                  if (_zoomlevel) {
                      zoomlevel = _zoomlevel;
                  } 
                  map.setCenter(point, zoomlevel);
                }

                function centerMap() {
                  var SW = latlngbounds.getSouthWest();
                  var NE = latlngbounds.getNorthEast();
                  var height = NE.lat() - SW.lat();
                  var width = NE.lng() - SW.lng();
                  // Set a 3% margin for left, right, and bottom, but 5% margin for top as markers are tall and need extra space
                  var marginBounds = new GLatLngBounds(new GLatLng(SW.lat() - 0.05*height, SW.lng() - 0.03*width), new GLatLng(NE.lat() + 0.05*height, NE.lng() + 0.03*width) );
                  var zoomlevel = map.getBoundsZoomLevel(marginBounds);
                  if (_marker_latlocations.length == 1) {
                     map.setCenter(marginBounds.getCenter(),15);
                     return;
                  } else if (_marker_latlocations.length < 1) {
                     geocoder.getLocations(_city+', The netherlands', centerLoc);
                     return;
                  }
                  if (_zoomlevel && zoomlevel != _previous_zoomlevel) {
                     geocoder.getLocations(_city+', The netherlands', centerLoc);
                     return;
                  } else if (zoomlevel != _previous_zoomlevel) {
                     _previous_zoomlevel = zoomlevel;
                     map.setCenter(marginBounds.getCenter(),zoomlevel);
                  }
                }

               function placeProjects() {
                    for(x=0;x<_marker_latlocations.length;x++){ 
                        placeProjectMarker(_marker_latlocations[x], _marker_lnglocations[x],_marker_IDS[x], _location_project_IDS[_marker_IDS[x]]); 
                     }
               }

               function createMarker(ID,point, project_IDS){
//                  var markerOptions = new GMarkerOptions();
                  markerOptions = { icon:_icon, title:$('maplocation-item-'+ID).innerHTML };
                  var marker = new GMarker(point, markerOptions);
                  var markerID = $(_tagIdName+'-list-'+ID);
                  GEvent.addListener(marker, "mouseover", function() {
                     marker.setImage(_siteroot+'img/gmapicoon2.png'); 
                     var proj_elements = $$('li[id*="project-list-"]');
                     for (var i=0;i<proj_elements.length;i++) {
                        proj_elements[i].removeClassName('active');
                     }; 
                     for(var i = 0; i < project_IDS.length ; i++){
                        var proj_element = $('project-list-'+project_IDS[i]);
                        if (proj_element) {
                           proj_element.addClassName('active');
                        }
                     }
                  });
                  GEvent.addListener(marker, "mouseout", function() { marker.setImage(_siteroot+'img/gmapicoon.png'); });
                  return marker;
               }

               function placeProjectMarker(latlocation, lnglocation, ID, project_IDS) {
                  point = new GLatLng(latlocation, lnglocation);
                  latlngbounds.extend(point);  
                  var marker = createMarker(ID ,point, project_IDS);
                  map.addOverlay(marker);
                  for(var i = 0; i < project_IDS.length ; i++){
                     var proj_element = $('project-list-'+project_IDS[i]);
                     if (proj_element) {
                        var id = 'project-list-'+project_IDS[i];
                        GEvent.addDomListener($(id), 'mouseout',function(){
                           marker.setImage('/img/gmapicoon.png'); 
                           this.removeClassName('active');
                        });
                        GEvent.addDomListener($(id), 'mouseover',function(){ 
                           marker.setImage('/img/gmapicoon2.png'); 
                           var proj_elements = $$('li[id*="project-list-"]');
                           for (var i=0;i<proj_elements.length;i++) {
                              proj_elements[i].removeClassName('active');
                           }; 
                           this.addClassName('active');
                        });
                     }
                  }
               }

               function initGMapPage(city, tagIdName, marker_IDS, marker_latlocations, marker_lnglocations, siteroot, location_project_IDS, zoomlevel, id){
                  id = typeof(id) != 'undefined' ? id : 'googlemap';
                  _tagIdName = tagIdName;
                  _zoomlevel = zoomlevel;
                  _marker_IDS = marker_IDS;
                  _marker_lnglocations = marker_lnglocations;
                  _marker_latlocations = marker_latlocations;
                  _location_project_IDS = location_project_IDS;
                  _siteroot = siteroot;
                  _city = city;
                  if(!$(id)) return;
                  if (GBrowserIsCompatible()) {
                     geocoder = new GClientGeocoder();
                     latlngbounds = new GLatLngBounds( );
                     initMap(id);
                  }
               }



