var map;function resetMap() {
    map.setZoom(5);
    map.setCenter(new GLatLng(53.39643, -2.307128));
    map.setMapType(G_NORMAL_MAP);
    document.getElementById('address').innerHTML = ('&nbsp;');
}
function goToBridgwater() {
    map.setZoom(15);
    map.panTo(new GLatLng(51.11277966, -2.99389604));
}
function goToBarnsley() {
    map.setZoom(15);
    map.panTo(new GLatLng(53.548136, -1.531380));
}
function goToExpressPark() {
    map.setZoom(15);
    map.panTo(new GLatLng(51.14904027634864, -2.99227237701416));
}
function goToLiverpool() {
    map.setZoom(15);
    map.panTo(new GLatLng(53.45948422, -2.86263149));
}
function goToDover() {
    map.setZoom(15);
    map.panTo(new GLatLng(51.14792372, 1.28659942));
}
function goToRedditch() {
    map.setZoom(15);
    map.panTo(new GLatLng(52.28520834, -1.89384744));
}
function goToPeterborough() {
    map.setZoom(15);
    map.panTo(new GLatLng(52.55051000, -0.26331000));
}
function goToGlasgow() {
    map.setZoom(15);
    map.panTo(new GLatLng(55.86771, -4.349380));
}
function goToLuton() {
    map.setZoom(15);
    map.panTo(new GLatLng(51.88873367, -0.48278505));
}
function returnToMap() {
    map.setZoom(5);
    map.setCenter(new GLatLng(53.39643, -2.307128));
}
function setMapSat() {
    map.setMapType(G_SATELLITE_MAP);
}
function setMapNor() {
    map.setMapType(G_NORMAL_MAP);
}
function initialize() {
  if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        //map.addControl(new GMapTypeControl());
        //map.addControl(new GSmallZoomControl());
        map.setCenter(new GLatLng(53.39643, -2.307128), 5);
        GDownloadUrl("depotlist.json", function( data, responseCode ){ parseJson(data); });
        map.setMapType(G_NORMAL_MAP);
	map.disableDragging();

        function makeIcon (image) {
        var icon = new GIcon();
        icon.image = image;
        icon.iconSize = new GSize(27, 27);
        icon.shadowSize = new GSize(24, 16);
        icon.iconAnchor = new GPoint(13, 13);
        icon.infoShadowAnchor = new GPoint(0, 0);
        icon.infoWindowAnchor = new GPoint(8, 1);
        return icon;
        }

        function createMarker(input) { 
              var marker = new PdMarker(input.point, makeIcon(input.icon) );
              marker.setTooltip( input.depotName );


     //  GEvent.addListener(marker, "click", function() {
     //
     //  if (marker.getMouseOutEnabled())
     //   {
     //           marker.setMouseOutEnabled(false);
     //           map.setCenter((input.point), 17);
     //          document.getElementById('address').innerHTML = (input.address);
     //   }
     //   else
     //   {
     //          marker.setMouseOutEnabled(true); 
     //          map.setCenter(new GLatLng(52.28164125024719, -1.3841164112091064), 6);
     //          document.getElementById('address').innerHTML = ('&nbsp;');
     //   }
     //   });




//GEvent.addListener(marker, "mouseover", function() {
//	document.getElementById('address').innerHTML = (input.address);
//	}); 

//GEvent.addListener(marker, "mouseout", function() {
//	document.getElementById('address').innerHTML = ('&nbsp;');
//	});


	return marker;


        }

        function parseJson (doc) {
              var jsonData = eval("(" + doc + ")");
                for (var i = 0; i< jsonData.depots.length; i++) {
                var marker = createMarker(jsonData.depots[i]);
        map.addOverlay(marker); }
        }


  }

}

window.onload = initialize;
window.onunload = GUnload;

