 // this variable will collect the html which will eventually be placed in the side_bar
var sidebarhtml = "";
	  
    
// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = new Array();
var i = 0;
var map;
var bounds;

 //zoom to all points
	  function fitMap(map, g2markers) {
		   alert(g2markers.lengt);
		   
}

 
 function initMap()
 {
 if (GBrowserIsCompatible()) {
      
      // create the map
      map = new GMap2(document.getElementById('map'));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(56.242023, 12.847276), 10);
	  

     var j = 0;
	 bounds = new GLatLngBounds();
	 
	  for (j=0;j<markers.length;j=j+1)
		{
			var preLoadImage = new Image();
   			preLoadImage.src = markers[j].img;

			//alert('name: ' + allPlaces[i].name;);
			var name = markers[j].name;
			var desc = markers[j].description;
			var point = new GLatLng(markers[j].lat, markers[j].long);
			var imgSrc = markers[j].img;
			var href = markers[j].href;
			var obs = markers[j].obs;
			
			var marker = createMarker(point, name, desc, imgSrc, href, obs);
			
			tmpGmark = new GLatLng(markers[j].lat, markers[j].long, true);
			bounds.extend(tmpGmark);
			
			map.addOverlay(marker);
		}
	  
      //put the assembled side_bar_html contents into the side_bar div
      document.getElementById('sidebar').innerHTML = sidebarhtml;

		map.setZoom(map.getBoundsZoomLevel(bounds));
		map.setCenter(bounds.getCenter());
      
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
	
	

    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm

    //]]>
	

}

	
	
	
	// A function to create the marker and set up the event window
      function createMarker(point,name,html, img, href, obs) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          infoHtml = '<div class="markerDiv">'
		  				+ '<h1>' + name + '</h1>'
						+ '<img class="markerImg" src="' + img +'" />'
						+ '<br />' 
						+ html 
						+ '<br />'
						+ '<img src="../bilder/closedgul.gif">' + '&nbsp;<a href="' + href + '" target="_blank" >L&auml;s mer</a>'
						+ '<br />'
						+ '<img src="../bilder/closedgul.gif">' + '&nbsp;<a href="' + obs + '" target="_blank" >Senaste rapporterna</a> - h&auml;mtas fr&acirc;n Svalan'
						+ '</div>';
		  marker.openInfoWindowHtml(infoHtml);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        // add a line to the side_bar html
        sidebarhtml += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br></div>';
        i++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }
	  
	  
	 

	  

