﻿var grid=false;


function initializeMap(elemID) {

    var lat=53.54112347161045; //start map in edmonton
    var lng=-113.49288940429688;      
    
    if (GBrowserIsCompatible()) {
    
        if (grid) {
            var mapcontainer = document.getElementById(elemID);
            mapcontainer.style.position="absolute";
            mapcontainer.style.top="0px";
            mapcontainer.style.left="0px";
            mapcontainer.style.width="100%";
            mapcontainer.style.height="100%";
        }
        //restrict zoom options...
        var mapTypes = G_DEFAULT_MAP_TYPES;
        for(var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMaximumResolution = function(latlng){ return 15;};
            mapTypes[i].getMinimumResolution = function(latlng){ return 8;};
        }
        //init map
        var map = new GMap2(document.getElementById(elemID));
        map.setCenter(new GLatLng(lat, lng), 10);            
        map.setMapType(G_PHYSICAL_MAP );
        
        
        //UI Options
        var customUI = map.getDefaultUI();
        customUI.maptypes.physical=true;
        customUI.maptypes.normal=true;
        customUI.maptypes.satellite=true;
        customUI.maptypes.hybrid=true;
        
        map.setUI(customUI);
        
        //custom overlays
        
        
        var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
        tilelayer.getTileUrl = function(tile, zoom) {
            if (grid) {
                return "http://maps.csg.ca/tiles/GridTile.ashx?x="+tile.x+"&y="+tile.y+"&s="+zoom;
                
            } else {                
                return "http://maps.csg.ca/tiles/overlay/"+tile.x+"-"+tile.y+"-"+zoom+".png";
            }
               
        };
        //tilelayer.getOpacity = function() {return 0.5;}
        map.addOverlay(new GTileLayerOverlay(tilelayer));

        map.enableContinuousZoom();       
        return map;
    } else {
        return null;
    }
}

/*
function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
	    x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
*/