// sggmaps.js

var map,custommap,site_id;

function j_SDGMapsLoad (siteid)
{
    is_sg = true;
	site_id = siteid;

    if (!GBrowserIsCompatible())
        return false;

    if (is_sg)
        copymsg = "SledGPS &copy; 2005-10 US TrailMaps Inc";
    else
        copymsg = "SledGPS &copy; 2005-10 Mountain Dynamics Inc";

    map = new GMap2(document.getElementById("mapdiv"),{draggableCursor:"pointer"});
    map.enableScrollWheelZoom();

    var copyCollection = new GCopyrightCollection();
    var copyright = new GCopyright(1,new GLatLngBounds(new GLatLng(-90, -180),
                                                       new GLatLng(90, 180)),
                                   0,copymsg);
    copyCollection.addCopyright(copyright);

    var tilelayers = new Array();
    tilelayers[0] = G_NORMAL_MAP.getTileLayers()[0];
    tilelayers[1] = new GTileLayer(copyCollection, 5, 12);
    tilelayers[1].getTileUrl = GetTileUrlSSide
    tilelayers[1].getOpacity = function () {return 1.0;};//of the non transparent part
    tilelayers[1].isPng = function() {return true;};

    var GMapTypeOptions = new Object();
    GMapTypeOptions.minResolution = 5;//9;
    GMapTypeOptions.maxResolution = 12;
    GMapTypeOptions.errorMessage = "No map data available";

    custommap = new GMapType(tilelayers, new GMercatorProjection(22), "SledGPS", GMapTypeOptions);
    custommap.getTextColor = function() {return "#000000";};
    map.addMapType(custommap);

    map.addControl(new GSmallMapControl());
//    map.addControl(new GLargeMapControl());
//    map.addControl(new GMapTypeControl());

    GEvent.addListener(map, 'zoomend', function(oldZoomLevel, newZoomLevel) {
//    alert( oldZoomLevel+'-'+newZoomLevel+' to '+Math.min(oldZoomLevel, 12));
       if(newZoomLevel > 12) {
         map.setZoom(Math.min(oldZoomLevel, 12));
       }
    });


    return true;
}

function GetTileUrlSSide (a,b)
{
    return "sgmt.php?s="+site_id+"&t=" + b + "_" + a.y + "_" + a.x;
}
