var map;
var geoXml;
var ahtml=new Array();

   
    var toggleState = 1;

function initialize() {
  	  if (GBrowserIsCompatible()) {
  	    geoXml = new GGeoXml("http://api.flickr.com/services/feeds/geo/?g=322338@N20&lang=en-us&format=feed-georss");
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(49.496675,-102.65625), 3); 
        map.addControl(new GLargeMapControl());
        map.addControl(new GLargeMapControl());
        map.addOverlay(geoXml);
  	  }
	} 

function onLoadMaps(pc,nr) {
	//alert("!");
  if (GBrowserIsCompatible()) {
	  //alert("?");
	  //var opts = new Object();
	   //opts.mapTypes="G_SATELLITE_MAP";
    map = new GMap2(document.getElementById("googlemap")); 
    map.addControl(new GLargeMapControl());
	map.setCenter(new GLatLng(52.1266107,5.0832806), 7); //,G_NORMAL_MAP 
    map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	
	
	//alert("/includes/maps.php");
	//alert("postcode_cijfer="+pc+";postcode_letter="+nr);
	if(pc!="") {
		if(document.getElementById("googlemap")) {
			document.getElementById("googlemap").style.display="block";
		}
	//http://preview.xenonstore.com/includes/maps.php?selection=3543ae&allnumbers=3543ae
	//alert("mapper1");
	xmlophalen( "/includes/maps.php?selection="+pc+"&allnumbers="+pc+"", mapper );
	//window.open("/includes/maps.php?selection="+pc+"&allnumbers="+pc+"");
	//xmlophalenp( "/includes/maps.php", callbackMaps,"postcode_cijfer="+pc+";postcode_letter="+nr );
	} else {
			document.getElementById("googlemap").style.display="none";
	}
	//
  }
} 

function xmlophalen2(pagina,oproepnaam, callback,dat){
	//alert(pagina);
  // XMLHTTPObject = createHTTPHandler();
   try{
		// Opera 8.0+, Firefox, Safari
		//XMLHTTPObject = new XMLHttpRequest();
		XMLHTTPObject = createXMLHTTPObject();
	} catch (e){
		// Internet Explorer Browsers
		try{
			XMLHTTPObject = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				XMLHTTPObject = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				try{
					XMLHTTPObject = new XMLHttpRequest();
				} catch (e){
					alert("Your browser broke! (2)");
					return false;
				}
			}
		}
	}
	if(XMLHTTPObject) {
		returntxt="";
		
			XMLHTTPObject.onreadystatechange=function() {
				//alert(XMLHTTPObject.readyState);
				if (XMLHTTPObject.readyState==4) {
					if (XMLHTTPObject.status != 200 && XMLHTTPObject.status != 304) {
						alert('HTTP error ' + XMLHTTPObject.status);
					
					} else {
						callback( XMLHTTPObject.responseXML,dat );
					}
				}
			} 
			XMLHTTPObject.open('GET', pagina, true);
		//XMLHTTPObject.onload = checkData;
		XMLHTTPObject.setRequestHeader("Cache-Control", "no-cache");
		//XMLHTTPObject.setRequestHeader("X_USERAGENT", oproepnaam);
		XMLHTTPObject.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		//XMLHTTPObject.setRequestHeader("Content-length", data.length);
		XMLHTTPObject.setRequestHeader("Connection", "close");
		//XMLHTTPObject.onload = checkData;
		XMLHTTPObject.send(null);
	} else {
		alert("Er is een fout opgetreden!");	
	}
}

function onLoad() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("googlemap")); 
    map.addControl(new GLargeMapControl());
    map.setCenter(new GLatLng(49.496675,-102.65625), 3); 
    map.addControl(new GLargeMapControl());
	geoXml = new GGeoXml("http://api.flickr.com/services/feeds/groups_pool.gne?id=322338@N20&format=rss_200&georss=1");
    
    map.addOverlay(geoXml);
  }
} 

function createMarker(point, desc) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "mouseover", function() {
	var opts = new Object();
	//opts.pixelOffset = new GSize(32,5);
	opts.maxWidth = 400; 
    marker.openInfoWindowHtml(desc,opts);
  });
  return marker;
}

function callbackMaps1(responseText,dat) {
	 xmlophalen2( "/includes/maps.php", 'maps',callbackMaps,dat );	
}

function callbackMaps4(responseText,dat) {
	 xmlophalen2( "/includes/maps.php", 'maps',callbackMaps5,dat );	
}

function callbackMaps2(responseText,dat) {
	 xmlophalen2( "/includes/maps.php", 'maps',callbackMaps,dat );	
}

function mapper( responseText ) {
	//alert("mapper2");
	
	//data=dat["data"];
	
	
	keys=new Array();
	
	content="";
	content3="";
	aantal=responseText.getElementsByTagName("item").length;
	//document.getElementById("response").innerHTML="<code>"+aantal+"<br/>"+responseText2+"</code>";
	//alert("aantal:"+aantal);
	//alert(responseText.length+"\n"+responseText2.length);
	//responseText=responseText2;
	shtml=new Array();
	var selectpoint="";
	var selecthtml="";
	selected=0;
	for(a=0; a<aantal; a++) {
			
			e="title";
			title=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			//content+=""+e+"="+id+"<br/>\n";
		//
			e="description";
			desc=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			//content+=""+e+"="+id+"<br/>\n";
			
			e="geolat";
			lat=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			//content+=""+e+"="+id+"<br/>\n";
			
			e="geolong";
			long2=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			
			e="title";
			address=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			e="link";
			thelink="";
			//thelink=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			
			//alert(lat+"-"+long);
			//content+=""+e+"="+id+"<br/>\n";
		 
       // point = new GLatLng(long,lat);
        //marker = new GMarker(point);
        //map.addOverlay(marker);
		
       // marker.openInfoWindowHtml("beschrijving uit rss feed");
	   	//findLocation2(address);
		//52.113906,5.038878
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		//alert(lat+"-"+long);
		//content+=lat+"-"+long+"<br/>";
			var point = new GLatLng(lat,long2);
		/*als meerdere op zelfde coord. zit
		var infoTabs = [
		  new GInfoWindowTab("Tab #1", "This is tab #1 content"),
		  new GInfoWindowTab("Tab #2", "This is tab #2 content")
		];
		*/
		html="<h2 class=\"vac\"><a href=\""+thelink+"\">"+title+"</a></h2><br/>"+desc;
		//alert("new:"+a+"="+title);
		ahtml[a]=html;
			map.addOverlay(createMarker(point, html));
		if(selected==a) {
				selectpoint=point;
				selecthtml=html;
		}
	}
	//alert(selected+" geselecteerd");
	if(selected>-1 && selected!=null && selected!="" && selectpoint!="" && selecthtml!="") {
			//alert("!");
				var opts = new Object();
				opts.maxWidth = 400; 
				
				map.openInfoWindow(selectpoint,  html,  opts);
		}
	//document.getElementById("response").innerHTML=content;
}

function callbackMaps5( responseText,dat ) {
	//data=dat["data"];
	ids=dat["id"];
	keys=new Array();
	//alert(responseText2);
	
	content="";
	content3="";
	aantal=responseText.getElementsByTagName("item").length;
	//document.getElementById("response").innerHTML="<code>"+aantal+"<br/>"+responseText2+"</code>";
	//alert(aantal);
	//alert(responseText.length+"\n"+responseText2.length);
	//responseText=responseText2;
	shtml=new Array();
	for(a=0; a<aantal; a++) {
			
			e="title";
			title=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			//content+=""+e+"="+id+"<br/>\n";
		//
			e="description";
			desc=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			//content+=""+e+"="+id+"<br/>\n";
			
			e="geolat";
			lat=responseText.getElementsByTagName("item")[a].getElementsByTagName("geoPoint")[0].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			//content+=""+e+"="+id+"<br/>\n";
			
			e="geolong";
			long2=responseText.getElementsByTagName("item")[a].getElementsByTagName("geoPoint")[0].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			
			e="title";
			address=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			e="link";
			thelink=responseText.getElementsByTagName("item")[a].getElementsByTagName(e)[0].childNodes.item(0).nodeValue;
			
			//alert(lat+"-"+long);
			//content+=""+e+"="+id+"<br/>\n";
		 
       // point = new GLatLng(long,lat);
        //marker = new GMarker(point);
        //map.addOverlay(marker);
		
       // marker.openInfoWindowHtml("beschrijving uit rss feed");
	   	//findLocation2(address);
		//52.113906,5.038878
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		//alert(lat+"-"+long);
		//content+=lat+"-"+long+"<br/>";
			var point = new GLatLng(lat,long2);
		/*als meerdere op zelfde coord. zit
		var infoTabs = [
		  new GInfoWindowTab("Tab #1", "This is tab #1 content"),
		  new GInfoWindowTab("Tab #2", "This is tab #2 content")
		];
		*/
		//desc=desc.substr(0,150)+"...";
		html="<h2 class=\"vac\"><a href=\""+thelink+"\">"+title+"</a></h2><br/>"+desc;
		ahtml[a]=html;
			map.addOverlay(createMarker5(point, html));
		

	}
	//document.getElementById("response").innerHTML=content;
}

function pointto(lat,long2,title,desc) {
	 if (GBrowserIsCompatible()) {
	  //alert("?");
	  //var opts = new Object();
	   //opts.mapTypes="G_SATELLITE_MAP";
    map = new GMap2(document.getElementById("googlemap")); 
    map.addControl(new GLargeMapControl());
	map.setCenter(new GLatLng(20,30), 2,G_NORMAL_MAP); 
    map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	
	//map.setMapType('satellite');
	//geoXml = new GGeoXml("http://api.flickr.com/services/feeds/groups_pool.gne?id=322338@N20&format=rss_200&georss=1");
	//geoXml = new GGeoXml("http://www.twovisionspreview.nl/home/maps");
	//geoXml = new GGeoXml("http://api.flickr.com/services/feeds/groups_pool.gne?id=322338@N20&format=rss_200&georss=1");
	
	//map.addOverlay(geoXml);
      geocoder = new GClientGeocoder();
	 // geoXml = new GGeoXml("http://www.twovisionspreview.nl/home/maps");
	 var dat=new Array();
	dat["id"]="!";
	//alert('/home/vacature.xml');
	//onLoadMaps();??
	 xmlophalen2( "/includes/maps.php", 'vacatures',callbackMaps2,dat );
  }
  var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var lngSpan = northEast.lng() - southWest.lng();
	var latSpan = northEast.lat() - southWest.lat();
	//alert(lat+"-"+long);
	//content+=lat+"-"+long+"<br/>";
		var point = new GLatLng(lat,long2);
		map.addOverlay(createMarker(point, "<h2 class=\"vac\"><a href=\"#\">"+title+"</a></h2>"+desc));
		
		
		html="<h2 class=\"vac\"><a href=\"#\">"+title+"</a></h2>"+desc;
		/*als meerdere op zelfde coord. zit
		var infoTabs = [
		  new GInfoWindowTab("Tab #1", "This is tab #1 content"),
		  new GInfoWindowTab("Tab #2", "This is tab #2 content")
		];
		*/

				var opts = new Object();
				opts.maxWidth = 400; 
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(html,opts);
			

		 //var marker = new GMarker(point);
		  
			//var opts = new Object();
			//opts.maxWidth = 400; 
	//map.addOverlay(marker.openInfoWindowHtml("<strong>"+title+"</strong><br/><br/>"+desc,opts));
}
function getAddress(overlay, latlng) {
  if (latlng != null) {
    address = latlng;
    geocoder.getLocations(latlng, showAddress);
  }
}
//via php->http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=xml&key=abcdefg

function showAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[0] + "," + place.Point.coordinates[1] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}
function mapto(lat,long2,z,geo,content) {
	 if (GBrowserIsCompatible()) {
	  //alert("?");
	  //var opts = new Object();
	   //opts.mapTypes="G_SATELLITE_MAP";
    map = new GMap2(document.getElementById("detailmap")); 
    map.addControl(new GLargeMapControl());
	map.setCenter(new GLatLng(20,30), 2,G_NORMAL_MAP); 
    map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	
	//map.setMapType('satellite');
	//geoXml = new GGeoXml("http://api.flickr.com/services/feeds/groups_pool.gne?id=322338@N20&format=rss_200&georss=1");
	//geoXml = new GGeoXml("http://www.twovisionspreview.nl/home/maps");
	//geoXml = new GGeoXml("http://api.flickr.com/services/feeds/groups_pool.gne?id=322338@N20&format=rss_200&georss=1");
	
	//map.addOverlay(geoXml);
      geocoder = new GClientGeocoder();
	 // geoXml = new GGeoXml("http://www.twovisionspreview.nl/home/maps");
	 var dat=new Array();
	dat["id"]="!";
	//alert('/home/vacature.xml');
	//onLoadMaps();??
	 xmlophalen2( "/includes/maps.php", 'vacatures',callbackMaps4,dat );
  }
  hoogte=z;
  if(hoogte=="" || hoogte==null || hoogte<1) {
	  hoogte=3;
  }
  hoogte=hoogte*1;
  //var welke=welke.split(',');
   map.panTo(new GLatLng(lat,long2));
	  map.setZoom(hoogte);
	  var point = new GLatLng(lat,long2);
	  map.setCenter(point, hoogte);
		
		var opts = new Object();
		opts.maxWidth = 200; 
	//content=content.substr(0,200)+"...";
		map.openInfoWindow(point,  content,  opts);
  
}
function createMarker5(point, desc) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
	var opts = new Object();
	//opts.pixelOffset = new GSize(32,5);
	opts.maxWidth = 200; 
	//desc=desc.substr(0,200)+"...";
    marker.openInfoWindowHtml(desc,opts);
  });
  return marker;
}

function toggleMyKml() {
  if (toggleState == 1) {
    map.removeOverlay(geoXml);
    toggleState = 0;
  } else {
    map.addOverlay(geoXml);
    toggleState = 1;
  }
}
var t="";
var u="";
function ganaar(welke) {
  //welke
  if(t!="") {
  	clearTimeout(t);
  }
   if(u!="") {
  	clearTimeout(u);
  }
  switch(welke) {
	  case 1: map.setCenter(new GLatLng(37.4419, -122.1419), 13); break;
	  case 2: map.panTo(new GLatLng(37.4569, -122.1569)); break;
	  case 3: map.panTo(new GLatLng(37.4419, -122.1419)); break;
	  case 4: map.panTo(new GLatLng(43.127697,-77.573776), 3); break;
	  case 5: map.panTo(new GLatLng(37.4419, -122.1419), 13); break;
	  case 6: map.setCenter(new GLatLng(43.127697,-77.573776), 3); break;
	  case 7: gotox(1); break;
  }
}

function gotop(q) {
	qs=q.split(",");
	gotoxy(qs[0]+','+qs[1],qs[2],qs[3],qs[4]);
}

function gotoxy(welke,hoogte,address,id) {
	//alert(id);
  //welke
  if(hoogte=="" || hoogte==null || hoogte<1) {
	  hoogte=3;
  }
  hoogte=hoogte*1;
  var welke=welke.split(',');
   map.panTo(new GLatLng(welke[1],welke[0]));
	//map.setZoom(hoogte);
	//map.setCenter(new GLatLng(welke[1],welke[0]), hoogte);
	 //geocoder.getLocations(address, addAddressToMap2);
	//var t=setTimeout("zoonto("+hoogte+")",1);
	  map.setZoom(hoogte);
	  var point = new GLatLng(welke[1],welke[0]);
	  map.setCenter(point, hoogte);
		//var marker = new GMarker(point);
		//map.addOverlay(marker);
		htmla=ahtml[id];
		//alert(htmla);
		var opts = new Object();
		opts.maxWidth = 400; 
		//marker.openInfoWindowHtml(htmla,opts);
		//alert("["+htmla+"]");
		if (htmla=="" || htmla=="undefined" || htmla==null || !htmla) {
			//alert("doorzoek opnieuw het xml bestand...");
			onLoadMaps(id);
		}
		
		if(htmla!="" && htmla!=null && htmla!="undefined") {
			//alert(htmla);
			map.openInfoWindow(point,  htmla,  opts);
		}
		/*map.openInfoWindow(map.getCenter(),document.createTextNode("Hello, world"));*/
		
		//map.showMapBlowup(opts) ????
		
		//createMarker(point, htmla);
				//var marker = new GMarker(point);
				//map.addOverlay(marker);
				//marker.openInfoWindowHtml(address);
	//var point = new GLatLng(welke[1],welke[0]);
	//map.addOverlay(createMarker(point, "<strong>"+title+"</strong><br/><br/>"+desc));
}

function zoonto(hoogte) {
	//if(t!="") {
		//clearTimeout(u);
	 // }
	  nu=map.getZoom();
	   map.setZoom(hoogte);
	  //alert(nu);
	 /* if(nu>hoogte) {
		  hoogte2=nu-1;
	 	 map.setZoom(hoogte2);
		  var t=setTimeout("zoonto("+hoogte+")",1000);
	  } else if(nu<hoogte) {
		  hoogte2=nu+1;
	 	 map.setZoom(hoogte2);
		  var t=setTimeout("zoonto("+hoogte+")",1000);
	  }*/
}

function gotox(a) {
	 if(u!="") {
		clearTimeout(u);
	  }
	a++;
	x=37.4569;
	y=-122.1569;
	switch(a) {
		case 0: x=37.4569;  y=-122.1569; break;
		case 1: x=40.127697;  y=-100.0000; break;
		case 2: x=43.127697;  y=-77.573776; break;
		case 3: x=52.469397;  y=5.509644; break;
		case 4: x=52.113906;  y=5.038878; break;
		default: a=0; x=37.4569; y=-122.1569; break;
	}
	//alert(a+": "+x+"-"+y);
	  map.panTo(new GLatLng(x, y));
	var t=setTimeout("gotoy("+a+")",1000);
}

function gotoy(a) {
	 if(t!="") {
		clearTimeout(t);
	  }
	a++;
	x=37.4569;
	y=-122.1569;
	switch(a) {
		case 0: x=37.4569;  y=-122.1569; break;
		case 1: x=40.127697;  y=-100.0000; break;
		case 2: x=43.127697;  y=-77.573776; break;
		case 3: x=52.469397;  y=5.509644; break;
		case 4: x=52.113906;  y=5.038878; break;
		default: a=0; x=37.4569; y=-122.1569; break;
	}
	//alert(a+": "+x+"-"+y);
	  map.panTo(new GLatLng(x, y));
	
	var u=setTimeout("gotox("+a+")",1000);
	//window.setTimeout(gotox(a), 5000);
}

function info() {
	map.getInfoWindow();
	//show()
}
function addAddressToMap2(response) {
     // map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
		
        var opts = new Object();
				opts.maxWidth = 400; 
				marker.openInfoWindowHtml("beschrijving uit rss feed",opts);
      }
}
	
function addAddressToMap(response) {
      //map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        var opts = new Object();
				opts.maxWidth = 400; 
				marker.openInfoWindowHtml(place.address + '<br>' +
          '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode,opts);
      }
    }

    function showLocation() {
      var address = document.forms[1].q.value;
      geocoder.getLocations(address, addAddressToMap);
    }

    function findLocation(address) {
      document.forms[1].q.value = address;
      showLocation();
    }
	
	function findLocation2(address) {
      geocoder.getLocations(address, addAddressToMap2);
    }
	
	var map, route;
var points = [];
var gmarkers = [];
var count =0;
var stopClick = false;


function addIcon(icon) { // Add icon attributes

 icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
 icon.iconSize = new GSize(32, 32);
 icon.shadowSize = new GSize(37, 34);
 icon.iconAnchor = new GPoint(15, 34);
 icon.infoWindowAnchor = new GPoint(19, 2);
 icon.infoShadowAnchor = new GPoint(18, 25);
}

	
	function addClickevent(marker) { // Add a click listener to the markers

 GEvent.addListener(marker, "click", function() {
  marker.openInfoWindowHtml(marker.content);
  /* Change count to continue from the last manually clicked marker
  *  Better syntax since Javascript 1.6 - Unfortunately not implemented in IE.
  *  count = gmarkers.indexOf(marker);
  */
  count = marker.nr;
  stopClick = true;
 });
 return marker;
}
function buildMap() {

 if(GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map"));
  map.setCenter(new GLatLng(52.1266107,5.0832806), 7);
  // map.setCenter(new GLatLng(54.503143, 11.229228), 8);
  //52.1266107,5.0832806), 7
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());

  // Light blue marker icons
  var icon = new GIcon();
  icon.image = "http://www.google.com/intl/en_de/mapfiles/ms/icons/ltblue-dot.png";
  addIcon(icon);
	x1=0;
	x2=0;
	y1=0;
	y2=0;
  for(var i = 0; i < data.length; i++) {
	  	
	   points[i] = new GLatLng(parseFloat(data[i].lat), parseFloat(data[i].lng));
	   gmarkers[i] = new GMarker(points[i], icon);
	
	   // Store data attributes as property of gmarkers
	   var html ="<div class='infowindow'>" +
	   "<strong>"+ data[i].name + "<\/strong><p>" +
	   data[i].date + "<\/p><\/div>";
	   gmarkers[i].content = html;
	   gmarkers[i].nr = i;
	   addClickevent(gmarkers[i]);
	   map.addOverlay(gmarkers[i]);
	   lt=data[i].lat;
	   lt=lt*1;
	   ln=data[i].lng;
	   ln=ln*1;
		if(x1==0) {
			x1=lt;
		} else if(lt<x1) {
			x1=lt;
		}
		if(x2==0) {
			x2=lt;
		} else if(lt>x2) {
			x2=lt;
		}
		if(y1==0) {
			y1=ln;
		} else if(ln<y1) {
			y1=ln;
		}
		if(y2==0) {
			y2=ln;
		} else if(ln>y2) {
			y2=ln;
		}
  }
  x=((x1+x2)/2);
  y=((y1+y2)/2);
  //alert(x+"/"+y)
   //map.setCenter(bounds.getCenter());
var rectObj = new GLatLngBounds(new GLatLng(x1,y1), new GLatLng(x2,y2));
var zm = map.getBoundsZoomLevel(rectObj);

  if(x>0 && y>0) {
  	map.setCenter(new GLatLng(x,y), (zm-1));
  }
   /*var bounds = new GLatLngBounds;
  for (var i=0; i<gmarkers.length; i++) {
    bounds.extend(gmarkers[i].point);
  }
  map.setZoom(map.getBoundsZoomLevel(bounds));

mySpace = new GLatLngBounds();

// then when i have all markers on the map:

var newZoom = map.getBoundsZoomLevel(mySpace);
var newCenter = mySpace.getCenter();
map.setCenter(newCenter,newZoom ); 
  */
  // Draw polylines between marker points
  //var poly= new GPolyline(points, "#003355", 3, .5);
  //map.addOverlay(poly);

  // Open infowindow of first marker
  //gmarkers[0].openInfoWindowHtml( gmarkers[0].content);

  //route =setTimeout("anim()", 3600);
 }
} 

