﻿var map;
var thisImage; //Debug variable
var thisSchemeName;
var thisTechnologyName;
var mgr;
var techID = 0;
var schemeID = 0;
//The path to the tile store - enusre this is set to the actual path at go live
var tilePath = "/MappingApp/TileStructure";
//Path to the case study images images
var casestudyImagePath = "/MappingApp/images/casestudyImages/";
// The allowed region which the whole map must be within
var allowedBounds = new GLatLngBounds(new GLatLng(49, -12), new GLatLng(59.6, 2.5));
var startCentrePoint = new GLatLng(54.9, -6.8167)

//Layers
var N_CLEAN_MAP;
var N_PA_MAP;
var N_RAINFALL_MAP;
var N_RAINFALLPA_MAP;
var N_SOLAR_MAP;
var N_SOLARPA_MAP;
var N_TIDAL_MAP;
var N_TIDALPA_MAP;
var N_WIND_MAP;
var N_WINDPA_MAP;
var N_WAVE_MAP;
var N_WAVEPA_MAP;


//Triggered when the document is ready
$(document).ready(function() {

    configureMap();

    setUpChangeEvents();

    loadPushpins();

});

function configureMap() {

    map = new GMap2($("#map").get(0), { backgroundColor: "#b0beda", mapTypes: [cleanMapTiles()
                                                                                , paMapTiles()
                                                                                , rainfallMapTiles()
                                                                                , rainfallPaMapTiles()
                                                                                , solarMapTiles()
                                                                                , solarPaMapTiles()
                                                                                , tidalMapTiles()
                                                                                , tidalPaMapTiles()
                                                                                , waveMapTiles()
                                                                                , wavePaMapTiles()
                                                                                , windMapTiles()
                                                                                ,windPaMapTiles()] });
    map.setCenter(startCentrePoint, 6);

    //This enables the paning controls as well as the zoom options
    //If you only want the zoom options then use GSmallZoomControl()
    //map.addControl(new GSmallMapControl());
    map.addControl(new GSmallZoomControl()); 
    map.enableScrollWheelZoom();

    mgr = new MarkerManager(map);

    if (map.isLoaded()) {
        map.setMapType(N_CLEAN_MAP);
        /*
        This setion removed - positioning is the job of CSS, not javascript - Ash.
        
        //POSITIONING OF DASHBOARD
        
        var pos = $("#map").offset();
        var eWidth = $("#map").outerWidth();
        var mWidth = $("#dashboard").outerWidth();
        var left = (pos.left + 20) + "px";
        var top = 20 + pos.top + "px";
        //show the menu directly over the placeholder
        $("#dashboard").css({ left: left, top: top });
        */
    }

    

}

function setUpChangeEvents() {

    //Events which load push pins when a checkbox is checked
    $(".technologyBoxes").click(function() {
        loadPushpins();
    });
    $(".schemeBoxes").click(function() {
        loadPushpins();
    });

    // These events check if the map has gone beyond its boundary
    GEvent.addListener(map, "dragend", function() {
        checkBounds();
    });
    
    GEvent.addListener(map, "zoomend", function() {
        checkBounds();
    });

    GEvent.addListener(map, "infowindowclose", function() {
        checkBounds();
    });

    //Toggling events

    $("#techToggle").toggle(function() {
    $(this).addClass("closedToggle");
    }, function() {
    $(this).removeClass("closedToggle");
    });

    $("#schemeToggle").toggle(function() {
        $(this).addClass("closedToggle");
    }, function() {
        $(this).removeClass("closedToggle");
    });

    $("#resourceToggle").toggle(function() {
        $(this).addClass("closedToggle");
    }, function() {
        $(this).removeClass("closedToggle");
    });

    $("#keyToggle").toggle(function() {
        $(this).addClass("closedToggle");
    }, function() {
        $(this).removeClass("closedToggle");
    });


    $("#techToggle").click(function() {
        $('#Technologies').toggle();
        return false;
    });

    $("#schemeToggle").click(function() {
        $('#Schemes').toggle();
        return false;
    });

    $("#resourceToggle").click(function() {
    $('#Resources').toggle();
        return false;
    });

    $("#keyToggle").click(function() {
        $('#key').toggle();
        return false;
    });

}

// If the map position is out of range, move it back
function checkBounds() {

        
    // Perform the check and return if OK
    if (allowedBounds.containsBounds(map.getBounds())) {
        return;
    } else {

    if (map.getZoom() == 6) {
        map.setCenter(startCentrePoint);
        return;
    } else {

        var bounds = map.getBounds();
        var SW = bounds.getSouthWest();
        var NE = bounds.getNorthEast();

        var N = NE.lat();
        var E = NE.lng();
        var S = SW.lat();
        var W = SW.lng();

        var maxE = allowedBounds.getNorthEast().lng();
        var maxN = allowedBounds.getNorthEast().lat();
        var maxW = allowedBounds.getSouthWest().lng();
        var maxS = allowedBounds.getSouthWest().lat();

        // It`s not OK, so find the nearest allowed point and move there
        var C = map.getCenter();
        var X = C.lng();
        var Y = C.lat();

        if (N > maxN) {
            Y = Y - (N - maxN);
        }
        if (E > maxE) {
            X = X - (E - maxE);
        }
        if (S < maxS) {
            Y = Y + (maxS - S);
        }
        if (W < maxW) {
            X = X + (maxW - W);
        }

        map.setCenter(new GLatLng(Y, X));
    }
    }    
    
}

function loadPushpins() {

    techID = '';
    schemeID = '';

    //Get the type we want to return
    $(".technologyBoxes").each(function() {
        if (this.checked == true) {
            if (techID == '') {
                techID += $(this).val();
            } else {
                techID += "," + $(this).val();
            }
        }
    });

    //Get the type we want to return
    $(".schemeBoxes").each(function() {
        if (this.checked == true) {
            if (schemeID == '') {
                schemeID += $(this).val();
            } else {
                schemeID += "," + $(this).val();
            }
        }
    });

    if (techID != '' || schemeID != '') {

        if (schemeID == '') {
            schemeID = 0;
        } else if (techID == '') {
            techID = 0;
        }
        
        addMarkers(techID, schemeID)

    } else {
        mgr.clearMarkers();
    }

}

//Makes AJAX call to get point data
function addMarkers(techID, schemeID) {
    $.getJSON('/MappingApp/Points.ashx?TechID=' + techID + '&schemeID=' + schemeID, function(points) {
        mgr.clearMarkers();
        mgr.addMarkers(getMarkers(points, "markers_dots"), 3, 6);
        mgr.addMarkers(getMarkers(points, "markers_tailSmall"), 7, 9);
        mgr.addMarkers(getMarkers(points, "markers_tailLarge"), 10, 13);
        mgr.refresh();
    });
}

//Loops through the point data adds the makrers
function getMarkers(points, folder) {
    var batch = [];

    $.each(points, function() {
        var point = new GLatLng(this["latitude"], this["longitude"]);
        batch.push(createMarker(point, this["siteName"], this["technology"], this["scheme"], this["id"], folder));
    });
    return batch;
}

function createMarker(point, title, technology, scheme, id, folder)
{
    var marker = new GMarker(point, { title: title, icon: getIconObject(scheme, technology, folder) })

    GEvent.addListener(marker, 'click', function() {
    CreateHtml(point,id);
    });

    return marker;

}

function CreateHtml(point,id) {

    var html;


    $.getJSON('/MappingApp/CaseStudy.ashx?CaseStudyID=' + id, function(points) {
        $.each(points, function() {
            html = getHtml(this["technology"], this["scheme"], this["schemeName"], this["siteName"], this["technologyName"], this["generators"], this["size"], this["generation"], this["customers"], this["CO2saving"], this["information"], this["imagepath"], this["hyperlink"]);
            map.openInfoWindowHtml(point, html);
            
            //Debug variables
            thisImage = this["imagepath"];
            thisSchemeName = this["schemeName"];
            thisTechnologyName = this["technologyName"];
        });
    });    

}

function getIconObject(scheme, technology, folder) {
    var iconImage = new GIcon();
    if (folder == "markers_dots") {
        iconImage.image = "/MappingApp/images/" + folder + "/" + (scheme) + ".png";
        iconImage.iconSize = new GSize(15, 15);
        iconImage.iconAnchor = new GPoint(7, 7);
    } else if (folder == "markers_tailSmall") {
    iconImage.image = "/MappingApp/images/" + folder + "/" + (scheme) + "" + (technology) + ".png";
        iconImage.iconSize = new GSize(20, 26);
        iconImage.iconAnchor = new GPoint(10, 26);
    } else {
    iconImage.image = "/MappingApp/images/" + folder + "/" + (scheme) + "" + (technology) + ".png";
        iconImage.iconSize = new GSize(23, 32);
        iconImage.iconAnchor = new GPoint(11, 32);
    }
    
    return iconImage;
}

function getHtml(technology, scheme, schemeName, siteName, technologyName, generators, size, generation, customers, CO2saving, information, imagepath, hyperlink)
{
    var html;

    html = '<div class="infoContainer">'
    html += '<div class="infoTitleContainer">'
    html += '<h1 class="headingScheme' + scheme + '"><img src="/MappingApp/images/windowIcons/' + technologyName + '-' + schemeName + '.png"/>' + schemeName + '</h1>'
    html += '<h2 class="headingSite">' + siteName + '</h2>'
    html += '</div>'
    html += '<div class="dataImageContainer">'
    html += '<ul class="siteData">'
    html += '<li>'
    html += '<label>Technology</label>'
    html += '<span>'+technologyName+'</span>'
    html += '</li>'
    html += '<li>'
    html += '<label>Generators</label>'
    html += '<span>' + generators + '</span>'
    html += '</li>'
    html += '<li>'
    html += '<label>Size (kW)</label>'
    html += '<span>' + size.toFixed(1) + '</span>'
    html += '</li>'
    html += '<li>'
    html += '<label>Generation (MWh/Yr)</label>'
    html += '<span>' + generation.toFixed(1) + '</span>'
    html += '</li>'
    html += '<li>'
    html += '<label>Customer Equivalents</label>'
    html += '<span>' + customers + '</span>'
    html += '</li>'
    html += '<li class="noBorderBottom">'
    html += '<label>CO2 Saved (l)</label>'
    html += '<span>' + CO2saving.toFixed(1) + '</span>'
    html += '</li>'
    html += '</ul>'
    html += '<div class="imageContainer">'
    //This section builds up the correct image to display in the case of Private schemes or where there is
    //no respective target image
    if ((imagepath == "") || (siteName == "Private")) 
    {
        html += '<img class="siteImage" alt="' + siteName + '" title="' + siteName + '" src="' + casestudyImagePath + technologyName + '-' + schemeName + '.png' + '"/>'      
    }
    else 
    {
        html += '<img class="siteImage" alt="' + siteName + '" title="' + siteName + '" src="' + casestudyImagePath + imagepath + '"/>'
    }
   
    html += '</div>'
    html += '</div>'
    html += '<div class="siteInformationContainer">'
    html += '<p class="siteInformation">' + information + '</p>'
    if (hyperlink != '') {
        html += '<p class="siteMoreInfo"><a href="' + hyperlink + '" class="moreInfoLink">Read more</a></p>'
    }
    html += '</div>'
    html += '</div>'
    return html;
}

var lastResource = '';

function changeMap(checkedbox) {

    checkboxID = checkedbox.id;

    if ($("#PA").is(":checked") == true) {
        
        if (checkedbox.id == "Rainfall") {
            if ($("#Rainfall").is(":checked") == true) {
                map.setMapType(N_RAINFALLPA_MAP);
            } else {
                map.setMapType(N_PA_MAP);
            }
        }
        if (checkedbox.id == "SolarRadiation") {
            if ($("#SolarRadiation").is(":checked") == true) {
                map.setMapType(N_SOLARPA_MAP);
            } else {
                map.setMapType(N_PA_MAP);
            }
        }
        if (checkedbox.id == "TidalEnergy") {
            if ($("#TidalEnergy").is(":checked") == true) {
                map.setMapType(N_TIDALPA_MAP);
            } else {
                map.setMapType(N_PA_MAP);
            }
        }
        if (checkedbox.id == "WaveEnergy") {
            if ($("#WaveEnergy").is(":checked") == true) {
                map.setMapType(N_WAVEPA_MAP);
            } else {
                map.setMapType(N_PA_MAP);
            }
        }
        if (checkedbox.id == "WindSpeed") {
            if ($("#WindSpeed").is(":checked") == true) {
                map.setMapType(N_WINDPA_MAP);
            } else {
                map.setMapType(N_PA_MAP);
            }
        }
        if (checkedbox.id == "PA") {
            if ($("#Rainfall").is(":checked") == true) {
                map.setMapType(N_RAINFALLPA_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#Rainfall").attr('checked', true);
            } else if ($("#SolarRadiation").is(":checked") == true) {
                map.setMapType(N_SOLARPA_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#SolarRadiation").attr('checked', true);
            } else if ($("#TidalEnergy").is(":checked") == true) {
                map.setMapType(N_TIDALPA_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#TidalEnergy").attr('checked', true);
            } else if ($("#WaveEnergy").is(":checked") == true) {
                map.setMapType(N_WAVEPA_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#WaveEnergy").attr('checked', true);
            }else if ($("#WindSpeed").is(":checked") == true) {
                map.setMapType(N_WINDPA_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#WindSpeed").attr('checked', true);
            } else {
                map.setMapType(N_PA_MAP);
            }
        }

        if ($("#" + checkedbox.id).is(":checked") == true) {
            $(".resourceBoxes").attr('checked', false);
            $("#" + checkedbox.id).attr('checked', true);
        }
        
        $("#PA").attr('checked', true);
        
    } else {

        if (checkedbox.id == "Rainfall") {
            if ($("#Rainfall").is(":checked") == true) {
                map.setMapType(N_RAINFALL_MAP);
            } else {
                map.setMapType(N_CLEAN_MAP);
            }
        }
        if (checkedbox.id == "SolarRadiation") {
            if ($("#SolarRadiation").is(":checked") == true) {
                map.setMapType(N_SOLAR_MAP);
            } else {
                map.setMapType(N_CLEAN_MAP);
            }
        }
        if (checkedbox.id == "TidalEnergy") {
            if ($("#TidalEnergy").is(":checked") == true) {
                map.setMapType(N_TIDAL_MAP);
            } else {
                map.setMapType(N_CLEAN_MAP);
            }
        }
        if (checkedbox.id == "WaveEnergy") {
            if ($("#WaveEnergy").is(":checked") == true) {
                map.setMapType(N_WAVE_MAP);
            } else {
                map.setMapType(N_CLEAN_MAP);
            }
        }
        if (checkedbox.id == "WindSpeed") {
            if ($("#WindSpeed").is(":checked") == true) {
                map.setMapType(N_WIND_MAP);
            } else {
                map.setMapType(N_CLEAN_MAP);
            }
        }
        if (checkedbox.id == "PA") {
            if ($("#Rainfall").is(":checked") == true) {
                map.setMapType(N_RAINFALL_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#Rainfall").attr('checked', true);
            } else if ($("#SolarRadiation").is(":checked") == true) {
                map.setMapType(N_SOLAR_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#SolarRadiation").attr('checked', true);
            } else if ($("#TidalEnergy").is(":checked") == true) {
                map.setMapType(N_TIDAL_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#TidalEnergy").attr('checked', true);
            } else if ($("#WaveEnergy").is(":checked") == true) {
                map.setMapType(N_WAVE_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#WaveEnergy").attr('checked', true);
            } else if ($("#WindSpeed").is(":checked") == true) {
                map.setMapType(N_WIND_MAP);
                $(".resourceBoxes").attr('checked', false);
                $("#WindSpeed").attr('checked', true);
            } else {
                map.setMapType(N_CLEAN_MAP);
            }
            return;
        }

        if ($("#" + checkedbox.id).is(":checked") == true) {
            $(".resourceBoxes").attr('checked', false);
            $("#" + checkedbox.id).attr('checked', true);
        } else {
            $(".resourceBoxes").attr('checked', false);            
        }

    }



}

function TileToQuadKey(x, y, zoom) {
    var quad = "";
    for (var i = zoom; i > 0; i--) {
        var mask = 1 << (i - 1);
        var cell = 0;
        if ((x & mask) != 0)
            cell++;
        if ((y & mask) != 0)
            cell += 2;
        quad += cell;
    }
    return quad;
}






//******************************************* LAYERS ********************************************************************************************

function cleanMapTiles() {

    //Create Custom Map
    var cleanLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    cleanLayer.getTileUrl = function(a, b) {
    return tilePath + "/clean/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    //cleanLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    cleanLayer.isPng = function() { return true; };

    N_CLEAN_MAP = new GMapType([cleanLayer], G_SATELLITE_MAP.getProjection(), 'CleanMap', {
        shortName: 'CM',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_CLEAN_MAP;

}

function paMapTiles() {

    //Create Custom Map
    var paLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    paLayer.getTileUrl = function(a, b) {
    return tilePath + "/pa/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    paLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    paLayer.isPng = function() { return true; };

    N_PA_MAP = new GMapType([paLayer], G_NORMAL_MAP.getProjection(), 'PAMap', {
        shortName: 'PA',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_PA_MAP;

}

function rainfallMapTiles() {

    //Create Custom Map
    var rainfallLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    rainfallLayer.getTileUrl = function(a, b) {
    return tilePath + "/rainfall/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    rainfallLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    rainfallLayer.isPng = function() { return true; };

    N_RAINFALL_MAP = new GMapType([rainfallLayer], G_NORMAL_MAP.getProjection(), 'RainfallMap', {
        shortName: 'RM',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_RAINFALL_MAP;

}

function rainfallPaMapTiles() {

    //Create Custom Map
    var rainfallPaLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    rainfallPaLayer.getTileUrl = function(a, b) {
    return tilePath + "/rainfallpa/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    rainfallPaLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    rainfallPaLayer.isPng = function() { return true; };

    N_RAINFALLPA_MAP = new GMapType([rainfallPaLayer], G_NORMAL_MAP.getProjection(), 'RainfallPAMap', {
        shortName: 'RPA',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_RAINFALLPA_MAP;

}

function solarMapTiles() {

    //Create Custom Map
    var solarLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    solarLayer.getTileUrl = function(a, b) {
    return tilePath + "/solar/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    solarLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    solarLayer.isPng = function() { return true; };

    N_SOLAR_MAP = new GMapType([solarLayer], G_NORMAL_MAP.getProjection(), 'SolarMap', {
        shortName: 'SM',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_SOLAR_MAP;

}

function solarPaMapTiles() {

    //Create Custom Map
    var solarPaLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    solarPaLayer.getTileUrl = function(a, b) {
    return tilePath + "/solarpa/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    solarPaLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    solarPaLayer.isPng = function() { return true; };

    N_SOLARPA_MAP = new GMapType([solarPaLayer], G_NORMAL_MAP.getProjection(), 'SolarPAMap', {
        shortName: 'SPA',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_SOLARPA_MAP;

}

function tidalMapTiles() {

    //Create Custom Map
    var tidalLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    tidalLayer.getTileUrl = function(a, b) {
    return tilePath + "/tidal/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    tidalLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    tidalLayer.isPng = function() { return true; };

    N_TIDAL_MAP = new GMapType([tidalLayer], G_NORMAL_MAP.getProjection(), 'TidalMap', {
        shortName: 'TM',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_TIDAL_MAP;

}

function tidalPaMapTiles() {

    //Create Custom Map
    var tidalPaLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    tidalPaLayer.getTileUrl = function(a, b) {
    return tilePath + "/tidalpa/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    tidalPaLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    tidalPaLayer.isPng = function() { return true; };

    N_TIDALPA_MAP = new GMapType([tidalPaLayer], G_NORMAL_MAP.getProjection(), 'TidalPAMap', {
        shortName: 'TPA',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_TIDALPA_MAP;

}

function waveMapTiles() {

    //Create Custom Map
    var waveLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    waveLayer.getTileUrl = function(a, b) {
        return tilePath + "/wave/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    waveLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    waveLayer.isPng = function() { return true; };

    N_WAVE_MAP = new GMapType([waveLayer], G_NORMAL_MAP.getProjection(), 'WaveMap', {
        shortName: 'WM',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_WAVE_MAP;

}

function wavePaMapTiles() {

    //Create Custom Map
    var wavePaLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    wavePaLayer.getTileUrl = function(a, b) {
    return tilePath + "/wavepa/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    wavePaLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    wavePaLayer.isPng = function() { return true; };

    N_WAVEPA_MAP = new GMapType([wavePaLayer], G_NORMAL_MAP.getProjection(), 'WavePAMap', {
        shortName: 'WPA',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_WAVEPA_MAP;

}

function windMapTiles() {

    //Create Custom Map
    var windLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    windLayer.getTileUrl = function(a, b) {
    return tilePath + "/wind/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    windLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    windLayer.isPng = function() { return true; };

    N_WIND_MAP = new GMapType([windLayer], G_NORMAL_MAP.getProjection(), 'WindMap', {
        shortName: 'WiM',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_WIND_MAP;

}

function windPaMapTiles() {

    //Create Custom Map
    var windPaLayer = new GTileLayer(new GCopyrightCollection(''), 6, 11);

    windPaLayer.getTileUrl = function(a, b) {
    return tilePath + "/windpa/" + TileToQuadKey(a.x, a.y, b) + ".png";
    };

    windPaLayer.getCopyright = function(a, b) { return "Good Energy 2009"; };
    windPaLayer.isPng = function() { return true; };

    N_WINDPA_MAP = new GMapType([windPaLayer], G_NORMAL_MAP.getProjection(), 'WindPAMap', {
        shortName: 'WiPA',
        tileSize: 256,
        maxResolution: 11,
        minResolution: 6
    }

    );

    return N_WINDPA_MAP;

}