var geocoder;
var map;
var infowindow = new google.maps.InfoWindow() ;
var gridPolygon_infowindow = new Array();
var landmark_infowindow = new Array();
var gridPolygons = [];
var gridPolygon;
var marker;
var ctaLayer;

var landmarks = [
  ['Owyhee Reservoir', 43.6421, -117.235794, 4, 'blue'],
  ['Ash Grove Cement', 44.543849, -117.420824, 5, 'blue'],
  ['BLM - National Historic Oregon Trail Interpretive Center', 44.81483, -117.728763, 3, 'blue'],
  ['Malheur Butte', 44.010966, -117.085075, 1, 'blue'],
  ['Grassland Substation', 45.694422, -119.832128, 1, 'red'],
  ['Hemingway Substation', 43.352457, -116.661075, 1, 'red'],
  ['Longhorn Substation', 45.847673, -119.615207, 1, 'green'],
  ['Horn Butte Substation', 45.683891, -119.962389, 1, 'green']
];

var smallMaps = [
    [1, '-119.817735,45.718294,0.000000 -119.810136,45.663717,0.000000 -119.918315,45.656267,0.000000 -119.926018,45.710835,0.000000 -119.817735,45.718294,0.000000'],
    [2, '-119.981006,45.699157,0.000000 -119.902769,45.698055,0.000000 -119.905006,45.621851,0.000000 -119.983137,45.622953,0.000000 -119.981006,45.699157,0.000000'],
    [3, '-119.914854,45.602569,0.000000 -119.910021,45.657299,0.000000 -119.801544,45.652533,0.000000 -119.806482,45.597805,0.000000 -119.914854,45.602569,0.000000'],
    [4, '-119.811597,45.598166,0.000000 -119.804297,45.652764,0.000000 -119.696095,45.645590,0.000000 -119.703501,45.590997,0.000000 -119.811597,45.598166,0.000000'],
    [5, '-119.706641,45.591500,0.000000 -119.706456,45.646339,0.000000 -119.597774,45.646109,0.000000 -119.598065,45.591267,0.000000 -119.706641,45.591500,0.000000'],
    [6, '-119.602523,45.597150,0.000000 -119.599590,45.651954,0.000000 -119.490974,45.649041,0.000000 -119.494013,45.594238,0.000000 -119.602523,45.597150,0.000000'],
    [7, '-119.502877,45.597658,0.000000 -119.487989,45.651498,0.000000 -119.381307,45.636922,0.000000 -119.396294,45.583093,0.000000 -119.502877,45.597658,0.000000'],
    [8, '-119.411373,45.575870,0.000000 -119.389392,45.628502,0.000000 -119.285163,45.606997,0.000000 -119.307235,45.554384,0.000000 -119.411373,45.575870,0.000000'],
    [9, '-119.314272,45.551360,0.000000 -119.291760,45.603881,0.000000 -119.187798,45.581850,0.000000 -119.210398,45.529348,0.000000 -119.314272,45.551360,0.000000'],
    [10, '-119.220455,45.525994,0.000000 -119.200495,45.579022,0.000000 -119.095571,45.559473,0.000000 -119.115623,45.506462,0.000000 -119.220455,45.525994,0.000000'],
    [11, '-119.114971,45.508675,0.000000 -119.112913,45.563508,0.000000 -119.004409,45.561446,0.000000 -119.006573,45.506613,0.000000 -119.114971,45.508675,0.000000'],
    [12, '-119.017094,45.509077,0.000000 -119.010911,45.563758,0.000000 -118.902715,45.557665,0.000000 -118.909002,45.502988,0.000000 -119.017094,45.509077,0.000000'],
    [13, '-118.919751,45.502902,0.000000 -118.911216,45.557429,0.000000 -118.803343,45.549036,0.000000 -118.811982,45.494516,0.000000 -118.919751,45.502902,0.000000'],
    [14, '-118.823192,45.489159,0.000000 -118.809059,45.543109,0.000000 -118.702366,45.529242,0.000000 -118.716598,45.475303,0.000000 -118.823192,45.489159,0.000000'],
    [15, '-118.724823,45.461545,0.000000 -118.721308,45.516348,0.000000 -118.612958,45.512859,0.000000 -118.616578,45.458058,0.000000 -118.724823,45.461545,0.000000'],
    [16, '-118.622335,45.464934,0.000000 -118.618617,45.519732,0.000000 -118.510272,45.516045,0.000000 -118.514095,45.461249,0.000000 -118.622335,45.464934,0.000000'],
    [17, '-118.536754,45.461820,0.000000 -118.507463,45.512666,0.000000 -118.406996,45.483971,0.000000 -118.436363,45.433149,0.000000 -118.536754,45.461820,0.000000'],
    [18, '-118.455958,45.431346,0.000000 -118.408444,45.474839,0.000000 -118.322604,45.428305,0.000000 -118.370146,45.384847,0.000000 -118.455958,45.431346,0.000000'],
    [19, '-118.372773,45.385551,0.000000 -118.321694,45.426970,0.000000 -118.240026,45.376909,0.000000 -118.291121,45.335526,0.000000 -118.372773,45.385551,0.000000'],
    [20, '-118.288742,45.348835,0.000000 -118.223549,45.378805,0.000000 -118.164541,45.314892,0.000000 -118.229692,45.284955,0.000000 -118.288742,45.348835,0.000000'],
    [21, '-118.226147,45.294723,0.000000 -118.158449,45.321712,0.000000 -118.105374,45.255282,0.000000 -118.173019,45.228325,0.000000 -118.226147,45.294723,0.000000'],
    [22, '-118.160410,45.227082,0.000000 -118.117309,45.272728,0.000000 -118.027531,45.230357,0.000000 -118.070673,45.184744,0.000000 -118.160410,45.227082,0.000000'],
    [23, '-118.075728,45.199064,0.000000 -118.017216,45.235124,0.000000 -117.946374,45.177600,0.000000 -118.004874,45.141575,0.000000 -118.075728,45.199064,0.000000'],
    [24, '-118.013317,45.138572,0.000000 -117.953770,45.173724,0.000000 -117.884792,45.115121,0.000000 -117.944322,45.080005,0.000000 -118.013317,45.138572,0.000000'],
    [25, '-117.935130,45.096068,0.000000 -117.862857,45.115850,0.000000 -117.824116,45.044688,0.000000 -117.896313,45.024931,0.000000 -117.935130,45.096068,0.000000'],
    [26, '-117.894363,45.026369,0.000000 -117.822387,45.046531,0.000000 -117.782947,44.975573,0.000000 -117.854850,44.955436,0.000000 -117.894363,45.026369,0.000000'],
    [27, '-117.853852,44.953800,0.000000 -117.783944,44.977210,0.000000 -117.738196,44.908201,0.000000 -117.808040,44.884819,0.000000 -117.853852,44.953800,0.000000'],
    [28, '-117.799070,44.890710,0.000000 -117.726668,44.909768,0.000000 -117.689480,44.838222,0.000000 -117.761806,44.819188,0.000000 -117.799070,44.890710,0.000000'],
    [29, '-117.745074,44.836617,0.000000 -117.667978,44.838112,0.000000 -117.665112,44.761862,0.000000 -117.742107,44.760369,0.000000 -117.745074,44.836617,0.000000'],
    [30, '-117.757177,44.755119,0.000000 -117.683762,44.771723,0.000000 -117.651449,44.699005,0.000000 -117.724783,44.682422,0.000000 -117.757177,44.755119,0.000000'],
    [31, '-117.698619,44.682409,0.000000 -117.658885,44.729404,0.000000 -117.567325,44.689964,0.000000 -117.607107,44.643000,0.000000 -117.698619,44.682409,0.000000'],
    [32, '-117.605607,44.652806,0.000000 -117.559735,44.696854,0.000000 -117.473979,44.651307,0.000000 -117.519881,44.607293,0.000000 -117.605607,44.652806,0.000000'],
    [33, '-117.521121,44.608450,0.000000 -117.478541,44.654136,0.000000 -117.389655,44.611821,0.000000 -117.432275,44.566168,0.000000 -117.521121,44.608450,0.000000'],
    [34, '-117.444535,44.573965,0.000000 -117.383968,44.607709,0.000000 -117.318409,44.547514,0.000000 -117.378952,44.513805,0.000000 -117.444535,44.573965,0.000000'],
    [35, '-117.309948,44.453709,0.000000 -117.386568,44.453613,0.000000 -117.386806,44.529896,0.000000 -117.310086,44.529993,0.000000 -117.309948,44.453709,0.000000'],
    [36, '-117.289589,44.379861,0.000000 -117.366084,44.378368,0.000000 -117.369032,44.454623,0.000000 -117.292438,44.456118,0.000000 -117.289589,44.379861,0.000000'],
    [37, '-117.309371,44.297766,0.000000 -117.380075,44.318610,0.000000 -117.339714,44.389184,0.000000 -117.268939,44.368316,0.000000 -117.309371,44.297766,0.000000'],
    [38, '-117.445492,44.263923,0.000000 -117.463743,44.317216,0.000000 -117.360535,44.335400,0.000000 -117.342372,44.282090,0.000000 -117.445492,44.263923,0.000000'],
    [39, '-117.541217,44.245740,0.000000 -117.559548,44.299017,0.000000 -117.456402,44.317287,0.000000 -117.438158,44.263993,0.000000 -117.541217,44.245740,0.000000'],
    [40, '-117.536514,44.217122,0.000000 -117.612774,44.215130,0.000000 -117.616677,44.291364,0.000000 -117.540319,44.293358,0.000000 -117.536514,44.217122,0.000000'],
    [41, '-117.628825,44.210007,0.000000 -117.559786,44.233399,0.000000 -117.514657,44.164366,0.000000 -117.583633,44.141001,0.000000 -117.628825,44.210007,0.000000'],
    [42, '-117.584649,44.147788,0.000000 -117.515522,44.170931,0.000000 -117.470920,44.101736,0.000000 -117.539985,44.078620,0.000000 -117.584649,44.147788,0.000000'],
    [43, '-117.509514,44.105336,0.000000 -117.433505,44.101820,0.000000 -117.440328,44.025690,0.000000 -117.516240,44.029202,0.000000 -117.509514,44.105336,0.000000'],
    [44, '-117.515944,44.031542,0.000000 -117.439935,44.029310,0.000000 -117.444279,43.953084,0.000000 -117.520191,43.955314,0.000000 -117.515944,44.031542,0.000000'],
    [45, '-117.507229,43.950067,0.000000 -117.438443,43.973385,0.000000 -117.393654,43.904300,0.000000 -117.462378,43.881009,0.000000 -117.507229,43.950067,0.000000'],
    [46, '-117.454935,43.872719,0.000000 -117.425474,43.923302,0.000000 -117.328253,43.893637,0.000000 -117.357782,43.843079,0.000000 -117.454935,43.872719,0.000000'],
    [47, '-117.368995,43.844808,0.000000 -117.339475,43.895369,0.000000 -117.242342,43.865630,0.000000 -117.271930,43.815094,0.000000 -117.368995,43.844808,0.000000'],
    [48, '-117.300480,43.836260,0.000000 -117.231744,43.859454,0.000000 -117.187279,43.790286,0.000000 -117.255953,43.767119,0.000000 -117.300480,43.836260,0.000000'],
    [49, '-117.256873,43.771501,0.000000 -117.197013,43.805148,0.000000 -117.132530,43.744836,0.000000 -117.192365,43.711222,0.000000 -117.256873,43.771501,0.000000'],
    [50, '-117.195266,43.722589,0.000000 -117.126619,43.745720,0.000000 -117.082359,43.676509,0.000000 -117.150944,43.653404,0.000000 -117.195266,43.722589,0.000000'],
    [51, '-117.154429,43.656451,0.000000 -117.085841,43.679557,0.000000 -117.041677,43.610330,0.000000 -117.110203,43.587250,0.000000 -117.154429,43.656451,0.000000'],
    [52, '-117.121548,43.593423,0.000000 -117.061790,43.627001,0.000000 -116.997632,43.566611,0.000000 -117.057366,43.533066,0.000000 -117.121548,43.593423,0.000000'],
    [53, '-117.057202,43.536186,0.000000 -117.011724,43.579993,0.000000 -116.928045,43.533974,0.000000 -116.973549,43.490200,0.000000 -117.057202,43.536186,0.000000'],
    [54, '-116.974957,43.491169,0.000000 -116.928796,43.534578,0.000000 -116.845943,43.487833,0.000000 -116.892127,43.444458,0.000000 -116.974957,43.491169,0.000000'],
    [55, '-116.893569,43.443115,0.000000 -116.850978,43.488398,0.000000 -116.764604,43.445230,0.000000 -116.807229,43.399978,0.000000 -116.893569,43.443115,0.000000'],
    [56, '-116.813529,43.404747,0.000000 -116.762599,43.445183,0.000000 -116.685545,43.393543,0.000000 -116.736482,43.353141,0.000000 -116.813529,43.404747,0.000000'],
    [57, '-116.736237,43.358470,0.000000 -116.692099,43.402928,0.000000 -116.607422,43.358131,0.000000 -116.651589,43.313705,0.000000 -116.736237,43.358470,0.000000'],
    [58, '-119.675679,45.851030,0.000000 -119.610689,45.881786,0.000000 -119.549583,45.818641,0.000000 -119.614536,45.787920,0.000000 -119.675679,45.851030,0.000000'],
    [59, '-119.620923,45.803756,0.000000 -119.548024,45.823978,0.000000 -119.507917,45.753099,0.000000 -119.580740,45.732904,0.000000 -119.620923,45.803756,0.000000'],
    [60, '-119.581037,45.744932,0.000000 -119.506931,45.762722,0.000000 -119.471697,45.690594,0.000000 -119.545721,45.672829,0.000000 -119.581037,45.744932,0.000000'],
    [61, '-119.470469,45.617836,0.000000 -119.548504,45.614847,0.000000 -119.554487,45.690963,0.000000 -119.476346,45.693958,0.000000 -119.470469,45.617836,0.000000'],
    [62, '-117.461256,43.917416,0.000000 -117.385328,43.917339,0.000000 -117.385524,43.841048,0.000000 -117.461356,43.841125,0.000000 -117.461256,43.917416,0.000000'],
    [63, '-117.454548,43.849609,0.000000 -117.378706,43.849527,0.000000 -117.378911,43.773235,0.000000 -117.454657,43.773317,0.000000 -117.454548,43.849609,0.000000'],
    [64, '-117.455153,43.785291,0.000000 -117.379392,43.785210,0.000000 -117.379597,43.708916,0.000000 -117.455262,43.708998,0.000000 -117.455153,43.785291,0.000000'],
    [65, '-117.433031,43.688283,0.000000 -117.403642,43.738861,0.000000 -117.306731,43.709176,0.000000 -117.336188,43.658622,0.000000 -117.433031,43.688283,0.000000'],
    [66, '-117.340841,43.668636,0.000000 -117.311384,43.719191,0.000000 -117.214550,43.689427,0.000000 -117.244074,43.638897,0.000000 -117.340841,43.668636,0.000000'],
    [67, '-117.254870,43.647866,0.000000 -117.215842,43.694879,0.000000 -117.125850,43.655451,0.000000 -117.164923,43.608468,0.000000 -117.254870,43.647866,0.000000'],
    [68, '-117.173963,43.609934,0.000000 -117.134896,43.656919,0.000000 -117.045014,43.617427,0.000000 -117.084125,43.570472,0.000000 -117.173963,43.609934,0.000000']
]

var largeMaps = [
    [1, '-120.023125,45.570677,0.000000 -120.011503,45.751440,0.000000 -119.663360,45.739915,0.000000 -119.676102,45.559162,0.000000 -120.023125,45.570677,0.000000'],
    [2, '-119.772227,45.687168,0.000000 -119.766643,45.868089,0.000000 -119.417428,45.862289,0.000000 -119.424142,45.681363,0.000000 -119.772227,45.687168,0.000000'],
    [3, '-119.694852,45.538276,0.000000 -119.682171,45.719030,0.000000 -119.334259,45.706494,0.000000 -119.348057,45.525757,0.000000 -119.694852,45.538276,0.000000'],
    [4, '-119.396761,45.499416,0.000000 -119.348304,45.677185,0.000000 -119.006619,45.630728,0.000000 -119.056122,45.453084,0.000000 -119.396761,45.499416,0.000000'],
    [5, '-119.091782,45.458565,0.000000 -119.042387,45.636221,0.000000 -118.701178,45.588841,0.000000 -118.751614,45.411316,0.000000 -119.091782,45.458565,0.000000'],
    [6, '-118.779441,45.415177,0.000000 -118.713612,45.590192,0.000000 -118.377867,45.527181,0.000000 -118.444670,45.352347,0.000000 -118.779441,45.415177,0.000000'],
    [7, '-118.552022,45.368334,0.000000 -118.425453,45.525942,0.000000 -118.123858,45.405235,0.000000 -118.251009,45.247951,0.000000 -118.552022,45.368334,0.000000'],
    [8, '-118.333229,45.259337,0.000000 -118.152866,45.388152,0.000000 -117.907359,45.216110,0.000000 -118.087747,45.087679,0.000000 -118.333229,45.259337,0.000000'],
    [9, '-118.118370,45.124467,0.000000 -117.903515,45.222911,0.000000 -117.716727,45.017642,0.000000 -117.931146,44.919549,0.000000 -118.118370,45.124467,0.000000'],
    [10, '-117.944590,44.933729,0.000000 -117.716668,45.015078,0.000000 -117.563029,44.796654,0.000000 -117.790314,44.715613,0.000000 -117.944590,44.933729,0.000000'],
    [11, '-117.766892,44.735763,0.000000 -117.539494,44.816757,0.000000 -117.387051,44.598083,0.000000 -117.613814,44.517392,0.000000 -117.766892,44.735763,0.000000'],
    [12, '-117.550232,44.572857,0.000000 -117.304406,44.616961,0.000000 -117.221973,44.379977,0.000000 -117.466871,44.336052,0.000000 -117.550232,44.572857,0.000000'],
    [13, '-117.512996,44.444437,0.000000 -117.277655,44.378532,0.000000 -117.401551,44.151111,0.000000 -117.636118,44.216768,0.000000 -117.512996,44.444437,0.000000'],
    [14, '-117.704142,44.197544,0.000000 -117.458964,44.238905,0.000000 -117.382188,44.001017,0.000000 -117.626441,43.959825,0.000000 -117.704142,44.197544,0.000000'],
    [15, '-117.539379,43.984657,0.000000 -117.294963,44.025663,0.000000 -117.219118,43.787655,0.000000 -117.462618,43.746813,0.000000 -117.539379,43.984657,0.000000'],
    [16, '-117.467912,43.712411,0.000000 -117.329220,43.863115,0.000000 -117.049135,43.727112,0.000000 -117.188217,43.576743,0.000000 -117.467912,43.712411,0.000000'],
    [17, '-117.232756,43.551746,0.000000 -117.077070,43.693231,0.000000 -116.814992,43.540239,0.000000 -116.970896,43.399107,0.000000 -117.232756,43.551746,0.000000'],
    [18, '-116.980930,43.402376,0.000000 -116.826861,43.544578,0.000000 -116.564097,43.392795,0.000000 -116.718392,43.250943,0.000000 -116.980930,43.402376,0.000000']
]


function initialize() {
    geocoder = new google.maps.Geocoder();

    var wh = parseInt($(window).height());
    var ww = parseInt($(window).width());

    // adjust height of map
    //  this has to be above the map initialization or IE issues
    $('#mainContent').height(wh - 180);
    $('#mainContent').width(ww - 410);

    if (wh > 800 && ww > 1700) {
        zoomlevel = 8;
    } else {
        zoomlevel = 7;
    }

    var latlng = new google.maps.LatLng(44.762337, -117.515259);
    var myOptions = {
        zoom: zoomlevel,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        disableDoubleClickZoom: false,
        scaleControl: true
    }
    map = new google.maps.Map(document.getElementById("mainContent"), myOptions);


    // now show the info window when you get to a certain zoom level...
    var zoomLevel;

    google.maps.event.addListener(map, 'zoom_changed', function() {
        zoomLevel = map.getZoom();
        
        // walk through the landmarks and show them if the zoom level is 10 or greater.
        if (zoomLevel >= 10) {

            // make sure they are gone.  
            for (var i = 0; i < landmark_infowindow.length; i++) {
                landmark_infowindow[i].close();
            }
            
            // create new info windows.. Throw them in an array so we can unload them later.
            for (i = 0; i < landmarks.length; i++) {
                var landmark = landmarks[i];

                
                //alert(landmarks[0]);
                landmark_infowindow[i] = new google.maps.InfoWindow(
                    { content: "<div class=\"infoWindowLocation\">" + landmark[0] +"</div>",
                        size: new google.maps.Size(50, 50),
                        position: new google.maps.LatLng(landmark[1], landmark[2]),
                        disableAutoPan: true
                    });
                landmark_infowindow[i].open(map);
                
            }
        } else {
            // unload the info windows...
            for (i = 0; i < landmark_infowindow.length; i++) {
                landmark_infowindow[i].close();
            }
        }

    });


    setMarkers(map, landmarks);
    showKML();

    //setMapGrids(map, smallMaps);

}

function showKML() {
    ctaLayer = new google.maps.KmlLayer('http://www.boardmantohemingway.com/kml/OCT2011Routes.kml', { suppressInfoWindows: true, preserveViewport: true, clickable: false });
    ctaLayer.setMap(map);
}

function showMapGridLarge() {
    clearMapGrids();
    setMapGrids(map, largeMaps, "LARGE");
    pageTracker._trackEvent('Show PDF Map Grid', 'link_click', 'Large PDFs');
}

function showMapGridSmall() {
    clearMapGrids();
    setMapGrids(map, smallMaps, "SMALL");
    pageTracker._trackEvent('Show PDF Map Grid', 'link_click', 'Small PDFs');
}

function clearKML() {
    ctaLayer.setMap(null);
}

function clearMapGrids() {
    if (gridPolygons) {
        for (i in gridPolygons) {
            gridPolygons[i].setMap(null);
        }
    }
}

function codeAddress() {
    var address = document.getElementById("tbAddress").value;
    
    if (geocoder) {
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location,
                    title: address
                });
                infowindow.setContent(results[0].formatted_address);
                infowindow.open(map, marker);
                
            } else {
                alert("Address search was not successful for the following reason: " + status);
            }
        });
    }
}



function setMarkers(map, locations) {
    var shadow = new google.maps.MarkerImage('images/flag_shadow.png',
      new google.maps.Size(37, 32),
      new google.maps.Point(0, 0),
      new google.maps.Point(0, 32));
    var shape = {
        coord: [1, 1, 1, 20, 18, 20, 18, 1],
        type: 'poly'
    };

  

    for (var i = 0; i < locations.length; i++) {
        var landmark = locations[i];

        var image = new google.maps.MarkerImage('images/flag_' + landmark[4] + '.png',
          new google.maps.Size(20, 32),
          new google.maps.Point(0, 0),
          new google.maps.Point(0, 32));

        var myLatLng = new google.maps.LatLng(landmark[1], landmark[2]);
        marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            shadow: shadow,
            icon: image,
            shape: shape,
            title: landmark[0],
            zIndex: landmark[3]
        });

        showLandmark(marker, landmark[0], myLatLng);
    }

}


function showLandmark(marker, content, position) {

    var infowindow_landmark2 = new google.maps.InfoWindow();

    google.maps.event.addListener(marker, 'click', function(e) {
        infowindow_landmark2.setContent("<div class=\"infoWindowLocation\">" + content + "</div>");
        infowindow_landmark2.setPosition(position);
        infowindow_landmark2.open(map);
    });

}


function setMapGrids(map, mapGrids, mapType) {

    for (var i = 0; i < mapGrids.length; i++) {       // walk through each grid..

        var mapGrid = mapGrids[i];
        var mapNumber = mapGrid[0];
        var coordinates_outer = mapGrid[1];         // all the outer coordinates
        var coordinateArray_outer = coordinates_outer.split(" ");

        var pts_outer = [];
        var xycoords = [];

        // Define outer polygon
        // loop through each coordinate point and add it to the points array
        for (var j = 0; j < coordinateArray_outer.length; j++) {
            //Split the pair into its parts (X and Y)
            xycoords = coordinateArray_outer[j].split(",");

            var myLatLng = new google.maps.LatLng(xycoords[1], xycoords[0]);
            pts_outer[j] = myLatLng;
        }

        var strokeColor = "#555555";
        var fillColor = "#f2efe8";
        
        gridPolygon = new google.maps.Polygon({
            paths: pts_outer,
            strokeColor: strokeColor,
            strokeOpacity: 1,
            strokeWeight: 1,
            fillColor: fillColor,
            fillOpacity: 0.1
        });

        gridPolygon.setMap(map);
        gridPolygons.push(gridPolygon);

        
        showPDF(gridPolygon, mapNumber, mapType);
    }

}

function showPDF(gridPolygon, mapNumber, mapType) {

    var infowindow_grid = new google.maps.InfoWindow();
    var mapTitle = "";
    var mapURL = "";

    if (mapType == "SMALL") {
        mapTitle = "Small Map" + " " + mapNumber;
        mapURL = "documents/parcelMaps/2011_10/20111018_Aerial_11x17_" + mapNumber + "of68.pdf";
    } else {
        mapTitle = "Large Map" + " " + mapNumber;
        mapURL = "documents/DSizeMaps/2011_10/20111018_Aerial_ArchE_" + mapNumber + "of18.pdf";
    }

    var content = "<div id=\"infoWindowPDF\"><strong>" + mapTitle  + "</strong><br><br><a href=\"" + mapURL + "\" target=\"_blank\">View PDF</a></div>"
    
    google.maps.event.addListener(gridPolygon, 'click', function(e) {
        infowindow_grid.setContent(content);
        infowindow_grid.setPosition(e.latLng);
        infowindow_grid.open(map);
    });
}

