﻿//<![CDATA[
// This is the http request we can use to get long lat coords.  replace the cvs with xml as well http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=csv&key=ABQIAAAA6tSh_Vyn09OW9rbfGKFNhhQMeMQHS-Qlp7mm7Xp_Ws3FJFtlIBQKMtIfKl_6WH7FzaMzohzY27Dklw
//
var map;
var bounds = new GLatLngBounds();

// Setup icons
	    var hotIcon = new GIcon();
      hotIcon.image = "images/markerHOT.png";
      hotIcon.shadow = "images/shadow50.png";
      hotIcon.iconSize = new GSize(20, 34);
      hotIcon.shadowSize = new GSize(37, 34);
      hotIcon.iconAnchor = new GPoint(9, 34);
      hotIcon.infoWindowAnchor = new GPoint(9, 2);
      hotIcon.infoShadowAnchor = new GPoint(18, 25);
    
      var coldIcon = new GIcon(hotIcon);
      coldIcon.image = "images/markerCOLD.png";

function load() {
    if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(0,0),0);
	
	// this function is dynamically generated outside of this script.  
	// Once this call is coimpleted, the map should contain all the markers.
	addMarkers();
	
	// dont zooom in closer than 13
    var zoom = map.getBoundsZoomLevel(bounds);
    zoom = zoom > 13 ? 13 : zoom;
    map.setZoom(zoom);

    var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
    var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
    map.setCenter(new GLatLng(clat,clng));
  }
}
      var gmarkers = [];
      var htmls = [];
      var to_htmls = [];
      var from_htmls = [];
      var i=0;
      
      // There are now two arrays of markers, one for cold icons and one for hot
      var cmarkers = [];
      var hmarkers = [];
      
function createMarker(point,html,officenum) {
    i = officenum;
    // ======== Add a "directions" link ======
	// html += '<br> <font face=arial size=2><b><a href="http://maps.google.com/maps?saddr=&daddr=' + point.toUrlValue() + '" target ="_blank">Directions</a></b>';
    
    var marker = new GMarker(point,coldIcon);
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
    
    // The info window version with the "to here" form open
        to_htmls[i] = html + '<br><font face=arial size=2>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
           '<br><font face=arial size=2>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br><font face=arial size=2>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' +
           '<br><font face=arial size=2>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" + 
           '"/>';
        // The inactive version of the direction info
        html = html + '<br><font face=arial size=2>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';
    
    
    
    // save two markers for each point, one with each of the possible icons
        cmarkers[i] = marker;
        hmarkers[i] = new GMarker(point,hotIcon);
		gmarkers[i] = marker;
		htmls[i] = html;
    i++;
    return marker;
}
// functions that open the directions forms
      function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      }
      function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      }
      
// Stuff for rollover links
	  // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        hmarkers[i].openInfoWindowHtml(htmls[i]);
      }
	  
	  // This function is invoked when the mouse goes over an entry in the side_bar
      // It deletes the cold Icon marker and replaces it with the hot Icon marker      
      function mymouseover(i) {
        map.removeOverlay(cmarkers[i]);
        map.addOverlay(hmarkers[i]);
      }
      // This function is invoked when the mouse leaves an entry in the side_bar
      // It deletes the hot Icon marker and replaces it with the cold Icon marker      
      function mymouseout(i) {
        map.removeOverlay(hmarkers[i]);
        map.addOverlay(cmarkers[i]);
      }

    //]]>
