﻿    var mapdiv;
    var map = null;
    var geocoder = null;
    // this variable will collect the html which will eventualkly be placed in the side_bar
    //var side_bar_html = "Show: ";
    var gmarkers = [];
    var htmls = [];
    // ===== Start with an empty GLatLngBounds object =====     
    var bounds = new GLatLngBounds();

    function setMultipleMarkers(lats, lons, info) {
	    document.getElementById("map").style.display="";
	    map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
	    for (var i = 0; i<lons.length; ++i) {
		    createMarker(i, lats[i], lons[i], info[i]);
	    };
		
		
        // put the assembled side_bar_html contents into the side_bar div
        //document.getElementById("side_bar").innerHTML = side_bar_html;
      
        // ===== determine the zoom level from the bounds =====
        map.setZoom(map.getBoundsZoomLevel(bounds));
        //map.setZoom(13);

        // ===== determine the centre from the bounds ======
        var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
        var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
        map.setCenter(new GLatLng(clat,clng));
        //map.setCenter(new GLatLng(40, -80));
    }
    


    function createMarker(num, lat, lon, info) {
		var point = new GLatLng(lat,lon);
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(info);
			});
        // ==== Each time a point is found, extent the bounds ato include it =====
            bounds.extend(point);        
        
        // save the info we need to use later for the side_bar
        gmarkers[num] = marker;
        htmls[num] = info;
        // add to the show list
        //if (side_bar_html != "Show: ") {
		//	side_bar_html += ", "
		//	}
        //side_bar_html += '<a href="javascript:myclick(' + num + ')">#' + (num+1) + '</a>';
       
        map.addOverlay(marker);
    }
    
    function setOfficeMarkers(lats, lons, info) {
	    for (var i = 0; i<lons.length; ++i) {
			createOfficeMarker(lats[i], lons[i], info[i]);
		};
    }   
    
    function createOfficeMarker(lat, lon, info) {
        var officeIcon = new GIcon(G_DEFAULT_ICON);
        officeIcon.image = "http://74.53.32.235/images/markerblue.png";
        //officeIcon.iconSize = GSize(50, 50);
        //officeIcon.iconAnchor = new GPoint(24, 43);
		markerOptions = { icon:officeIcon };
        
		var point = new GLatLng(lat,lon);
        var marker = new GMarker(point, markerOptions);
        GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(info);
			});  
	    map.addOverlay(marker);
    }
    
    function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
    }
