    window.onload = load;
    window.onunload = GUnload;
    
		var map;		

    function load() 
    {
			if (GBrowserIsCompatible()) 
			{				
				map = new GMap2(document.getElementById("map"));
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				//map.setCenter(new GLatLng(53.3857, -1.4666), 11); 
								
								
				// ============================================================
	      // ====== Create a copyright entry =====
	      var copyright = new GCopyright(1,
	          new GLatLngBounds(new GLatLng(53.48018,-1.611214),new GLatLng(53.246625,-1.162148) ),
	          17, "Sheffield 1935");
	          
				// ============================================================
	      // ====== Create a copyright collection =====
	      // ====== and add the copyright to it   =====
	      var copyrightCollection = new GCopyrightCollection('Map Data:');
	      copyrightCollection.addCopyright(copyright);					
								
				// ============================================================
	      // == Write our own getTileUrl function ========
	      // In this case the tiles are names like  8053_5274_3.jpg      
	      CustomGetTileUrl=function(a,b){ 
																        var c=Math.pow(2,b);
																        var d=a.x;
																        var e=a.y;
																        var f="t";
																          for(var g=0;g<b;g++){
																            c=c/2;
																            if(e<c){
																              if(d<c){
																                f+="q"
																              }
																              else{
																                f+="r";
																                d-=c
																              }
																            }
																          else{
																            if(d<c){
																              f+="t";
																              e-=c
																            }
																            else{
																              f+="s";
																              d-=c;
																              e-=c
																            }
																          }
																        }
																		var tileid = f;
																		var tileLen = tileid.length;
																		
																		var i = 0;
																		var tilePath = "";
																		while(i+3 < tileLen) {
																			tilePath += tileid.substr(i,3);
																			tilePath += '/';
																			i += 3;
																		}
																		tilePath += tileid.substr(i);
																		tilePath += '.jpg';
																		
																		var tileDir = 18 - tileLen;
																        if (tileDir < 10) {
																			tileDir = '0' + tileDir;
																		}
																        return "http://www.snaffle.me.uk/" + 'shf1935tiles/' + tileDir
																+ '/'  + tilePath;
																}
																
				// ============================================================
	      // ===== Create the GTileLayer =====
	      // ===== adn apply the CustomGetTileUrl to it
	      var tilelayers = [new GTileLayer(copyrightCollection,1,17)];
	      tilelayers[0].getTileUrl = CustomGetTileUrl;								
								
								
				// ============================================================
	      // ===== Create the GMapType =====
	      // ===== and add it to the map =====
	      var custommap = new GMapType(tilelayers, new GMercatorProjection(18), "1935",{errorMessage:"Data Not Available"});
	      map.addMapType(custommap);
								
								
				//capture the clicks for info window show			
				//GEvent.addListener(map, 'moveend', getMoveEnd);			
				
				doSetUp();			
				
			}        
			else // display a warning if the browser was not compatible
			{
				alert("Sorry, the Google Maps API is not compatible with this browser");
			}						      
		}		
		
		
		
    function getIcon(colour)
    {
        var icon = new GIcon(); 
        icon.image = "/images/icons/mm_20_" + colour + ".png" ;
        icon.iconAnchor = new GPoint(16, 16); 
        icon.infoWindowAnchor = new GPoint(16, 0); 
        icon.iconSize = new GSize(12, 20); 
        icon.shadow = "/images/icons/mm_20_shadow.png";

        return icon;     	
    }		
		