function _make4326Map(url, minZ, maxZ, label, copyright, layer, style, maxDirectZoom) {

var degM = 131072;
var tilesize = 512;

    function floor(x) { return Math.floor(x); }

    function pow(x, y) { return Math.pow(x, y); }

    function EPSG4326Projection() {
    }

    EPSG4326Projection.prototype = new GProjection();

    EPSG4326Projection.prototype.fromLatLngToPixel=function(a,b) {
        return new GPoint(floor((a.lng() + 180) * degM / pow(2, 17 - b)), -floor((a.lat() - 90) * degM / pow(2, 17 - b)));
    }

    EPSG4326Projection.prototype.fromPixelToLatLng=function(a,s,c) {
        var ll =  new GLatLng(-a.y * pow(2, 17 - s) / degM + 90, a.x * pow(2, 17 - s) / degM - 180, c)
        return ll;
    }

    EPSG4326Projection.prototype.tileCheckRange=function(a,b,c) {
        return true
    }

    EPSG4326Projection.prototype.getWrapWidth=function(zoom) {
        return 360 * degM / pow(2, 17 - zoom);
    }

    var copycoll = new GCopyrightCollection(copyright + " &copy; ");

    copycoll.addCopyright(new GCopyright(1, new GLatLngBounds(new GLatLng(-90, -180), new GLatLng(90, 180)), 0, "NASA/JPL"));

    var tilelayers = [new GTileLayer(copycoll,minZ,maxZ)];

    var myproj = new EPSG4326Projection();

    tilelayers[0].getTileUrl = function (a,zoom) {
        var tl = myproj.fromPixelToLatLng(new GPoint(a.x * tilesize, a.y * tilesize), zoom, 0);
        var br = myproj.fromPixelToLatLng(new GPoint((a.x + 1) * tilesize, (a.y + 1) * tilesize), zoom, 0);
        var url = this.baseURL + "request=GetMap&layers=" + layer + "&srs=EPSG:4326&format=image/jpeg&styles=" + style + "&width=" + tilesize + "&height=" + tilesize + "&bbox=" + tl.lng() + "," + br.lat() + "," + br.lng() + "," + tl.lat();

        var srvid = 0;

        if (a.x & 1) srvid += 2;
        if (a.y & 1) srvid += 1;

        if (zoom > maxDirectZoom) {
            url = "http://server" + srvid + ".gladstonefamily.net/landsat?layer=" + layer + "&style=" + style + "&width=" + tilesize + "&height=" + tilesize + "&bbox=" + tl.lng() + "," + br.lat() + "," + br.lng() + "," + tl.lat();
        } else {
            //url = url.replace(/\.gov\//, ".gov." + srvid + ".i.spf.gladstonefamily.net/");
        }
        return url
    } ;

    tilelayers[0].baseURL = url
    return new GMapType(tilelayers, myproj, label, {errorMessage:"No Data Available", tileSize:tilesize});

}

function LandsatMap(label) {
     return _make4326Map("http://wms.jpl.nasa.gov/wms.cgi?", 5, 15, label, "Imagery", "global_mosaic", "", 13)
}

function LandsatDailyMap(label, date) {
    var timearg = '';

    if (date) {
        timearg = "&time=" + date;
    }
    return _make4326Map("http://wms.jpl.nasa.gov/wms.cgi?", 5, 10, label, "Imagery", "daily_aqua_721", timearg, 10)
}


