// ==UserScript==
// @name        USPS Zipcode Mapper
// @author      Kees Cook
// @version     1.0
// @namespace   http://outflux.net/greasemonkey
// @description Add full zipcode map to zipcode overview page
// @include     http://*.payphone-project.com/mailboxes/zip_codes/*.html
// @license     GNU General Public License
// ==/UserScript==

//(function() {

window.addEventListener(
    'load', 
    function() {

    div = document.createElement('div');
    div.innerHTML = ''+
'  <div id="map" style="width: 400px; height: 300px"></div>'+
    '<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAugjNpM6L-Vy1fkpB8H3iERTxM3Ve_u2wwS0LGzxdvF96QABuahSGXvlA4H3cM8v0sqcIstMirIOA-g"'+
      'type="text/javascript"></script>'+
''+
    '<script type="text/javascript">'+
''+
    '//<![CDATA['+
''+
   'var geocoder;'+
   'var map;'+
''+
   'var addresses;+
''+
   '// On page load, call this function'+
''+
   'function globals_init()'+
   '{'+
      '// Create new map object'+
      'map = new GMap2(document.getElementById("map"));'+
      '// Create new geocoding object'+
      'geocoder = new GClientGeocoder();'+
'  map.addControl(new GMapTypeControl());'+
    'map.addControl(new GSmallMapControl());'+
      '// Retrieve location information, pass it to addToMap()'+
'for ( addr in addresses ) {'+
      'geocoder.getLocations(addr, addToMap);'+
'}'+
''+
   '}'+
''+
   '// This function adds the point to the map'+
   'function addToMap(response)'+
   '{'+
      '// Retrieve the object'+
      'place = response.Placemark[0];'+
''+
      '// Retrieve the latitude and longitude'+
      'point = new GLatLng(place.Point.coordinates[1],'+
                          'place.Point.coordinates[0]);'+
''+
      '// Center the map on this point'+
      'map.setCenter(point, 13);'+
''+
      '// Create a marker'+
      'marker = new GMarker(point);'+
''+
      '// Add the marker to map'+
      'map.addOverlay(marker);'+
''+
      '// Add address information to marker'+
      'marker.openInfoWindowHtml(addresses[place.address]+"<br />"+place.address);'+
   '}'+
''+
''+
'addresses["5010  SE  FOSTER  RD 97206-0001"]="S SIDE OF PO";'+
'addresses["4400  SE  STEELE  ST 97206-0007"]="44TH CRNR = NE";'+
'addresses["5000  SE  WOODWARD  ST 97206-0014"]="50TH CRNR = NE";'+
''+
'   globals_init();'+
    '//]]>'+
    '</script>'+
'<div>HELLO KEES</div>';
    document.body.appendChild(div);

},
    true);

//});

