var barr = [ ] ;
  function initialize() {
    var latlng = new google.maps.LatLng(34.597042, 1.757813);
    var myOptions = {
      zoom: 1,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
     setMarkers(map, locations);  
  }
  
  var locations = [
  	['UK',53.667299,-2.663541,1,"<div><b>Rhino Board UK</b></div><div>CBTC Euxton Lane</div><div>Chorley PR7 6TE</div><div>+ 44 1257 248482</div>"],
	['Germany',51.211327, 6.466516,2,"<div><b>Rhino Board Germany</b></div><div>Innomax AG</div><div>Krefelder Straße 249</div><div>D-41066 Mönchengladbach</div><div>Contact: Dipl.-Math. Ralf Winzen</div><div>Tel: + 49 2161 57541-0 (-63)</div><div>Mob: + 49 163 2030251</div><div>E-mail r.winzen@innomaxag.de</div>"],
	['Norway',60.354623, 5.190047,3,"<div><b>Rhino Board Norway</b></div><div>Alvøen AS</div><div>Alvøveien 130</div><div>5179 GODVIK</div><div>Contact: Hendrik Fasmer</div><div>Tel: + 47 5550 6630</div><div>E-mail: hendrik@alvoen.no</div>"],
	['Australasia',-41.04097, 145.849677,4,"<div><b>Rhino Board Australasia</b></div><div>Performance Management Pty. Ltd.</div><div>33 Besser Crescent</div><div>Camdale</div><div>TAS 7322</div><div>Contact: Lester Selby</div><div>Tel: + 61 3 6432 1700</div><div>E-mail: info@performancesales.com.au</div>"],
    ['Germany',48.860378, 12.588135,5,"<div><b>Rhino Board Straubing Germany</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Austria',48.2597405, 16.4179639,6,"<div><b>Rhino Board Vienna Austria</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Bulgaria',42.696164, 23.322876,7,"<div><b>Rhino Board Sofia Bulgaria</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Czech Republic',50.069833, 14.431641,8,"<div><b>Rhino Board Prague Czech Republic</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Hungary',47.469692, 19.107422,9,"<div><b>Rhino Board Budapest Hungary</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Poland',52.225108, 21.041016,10,"<div><b>Rhino Board Warsaw Poland</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Romania',44.471423, 26.077148,11,"<div><b>Rhino Board Bucharest Romania</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Zurich Switzerland',47.314993, 8.520996,12,"<div><b>Rhino Board Zurich Switzerland</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['Geneva Switzerland',46.182873, 6.117187,13,"<div><b>Rhino Board Geneva Switzerland</b></div><div>aQuaPRO GmbH</div><div>Europaring 4</div><div>94315 Straubing</div><div>Tel.: +49 (0) 9421/785-480</div><div>Fax: +49 (0) 9421/785-485</div><div>E-mail: office@ap-waterjet.com</div>"],
    ['France',48.775741, 5.156982,14,"<div><b>Rhino Board LSDA France</b></div><div>LDSA French Head Office</div><div>ZI de POPEY</div><div>55000 BAR-LE-DUC FRANCE</div><div>Tél. +33 (0)3 29 77 12 12</div><div>Fax. +33 (0)3 29 79 68 41</div><div>E-mail: contact@ldsa-france.com</div>"],
  ];
  var locationsred = [
  	['Albuquerque NM',35.055125,-106.642043,15,"<div><b>Rhino Board US</b></div><div>2711 Karsten Court SE</div><div>Albuquerque, NM 87102</div><div>(505) 842-5100</div>"],
	['Intervracht Nederland BV',51.96723447496111, 6.013984680175781,16,"<div><b>Rhino Board European Warehouse</b></div><div>c/o Intervracht Nederland BV</div><div>Segment 7</div><div>6921 RC Duiven</div><div>Contact: Rob Collins</div><div>Tel: + 44 78 86 75 74 84</div><div>Email: rcollins@rhinoboardwj.com</div>"]
	
  ];
  
  function setMarkers(map, locations) {
  	var image = new google.maps.MarkerImage('images/pin.png',
	      // This marker is 20 pixels wide by 32 pixels tall.
	      new google.maps.Size(20, 32),
	      // 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(0, 32));
	  var shape = {
	      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
	      type: 'poly'
	  };
	  var imagered = new google.maps.MarkerImage('images/redpin.png',
	      // This marker is 20 pixels wide by 32 pixels tall.
	      new google.maps.Size(20, 32),
	      // 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(0, 32));
	  var shape = {
	      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
	      type: 'poly'
	  };
	  for (var i = 0; i < locations.length; i++) {
	    var dist = locations[i];
	    var myLatLng = new google.maps.LatLng(dist[1], dist[2]);
	    var marker = new google.maps.Marker({
	        position: myLatLng,
	        map: map,
	        icon: image,
	        shape: shape,
	        title: dist[0],
	        zIndex: dist[3]
	    });
		//if (i == 5) {alert(myLatLng)}
	  
	  	barr[i] = new Object;
	
	  	barr[i].marker = marker ;
	    barr[i].html = dist[4] ; //"This is content for infoWindow";
	 
	    // Create the infoWindow...
	    barr[i].infoWindow = new google.maps.InfoWindow({
	     content: barr[i].html
	    });
	 
	    // Create the listener with a closure...
	    barr[i].listener = makeClosure(i, barr[i].marker) ;
		 
	  }
	  for (var i = 0; i < locationsred.length; i++) {
	    var dist = locationsred[i];
	    var myLatLng = new google.maps.LatLng(dist[1], dist[2]);
	    var marker = new google.maps.Marker({
	        position: myLatLng,
	        map: map,
	        icon: imagered,
	        shape: shape,
	        title: dist[0],
	        zIndex: dist[3]
	    });
	  	var j = i + locations.length;
	  	barr[j] = new Object;
	
	  	barr[j].marker = marker ;
	    barr[j].html = dist[4] ; //"This is content for infoWindow";
	 
	    // Create the infoWindow...
	    barr[j].infoWindow = new google.maps.InfoWindow({
	     content: barr[j].html
	    });
	 
	    // Create the listener with a closure...
	    barr[j].listener = makeClosure(j, barr[j].marker) ;
		 
	  }
	 
	   // Make a simple closure with the listener...
	  function makeClosure( i, marker )
	  {
	   var listener = google.maps.event.addListener(marker, 'click', function() {
	    openInfoWindow(i) ;		// <-- this is the key to making it work
	   });
	   return listener ;
	  }
	 
	  // Open the infoWindow - called from the closure...
	  function openInfoWindow(i)
	  {
	   if ( typeof(lastI) == 'number' && typeof(barr[lastI].infoWindow) == 'object' )
	   { 
	    barr[lastI].infoWindow.close() ;
	   }
	   lastI = i ;    
	   barr[i].infoWindow.open(map,barr[i].marker) ;    
	  }
  }
