//<![CDATA[

var map;
var marker_o;
var htmls = [];
var lat = [];
var lng = [];


htmls[0] = "<div align='left'><b>KEPCO, Inc.</b><br>145 North Leja Drive<br>Vicksburg, MI 49097<br>Phone: (269) 649-5800</div>";
lat[0]= 42.123342;
lng[0] = -85.547769;

// the icon information is passed to this function
function createMarker(point, pi)
{
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(""+htmls[pi]);});
    return marker;
}


function load() 
{
  var geocoder = new GClientGeocoder();

  if (GBrowserIsCompatible())
  {
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    /*GEvent.addListener(map, "moveend", function() {
      var center = map.getCenter();
      document.getElementById("message").innerHTML = center.toString();
    });   */
    //map.setCenter(new GLatLng(43.059857997098916, -85.94329833984375), 10);
    map.setCenter(new GLatLng(42.123342, -85.547769), 11);
    //map.setCenter(new GLatLng(42.747012,-84.550781), 10);
  }

  for (var i = 0; i < lat.length; i++) {
      map.addOverlay(createMarker(new GLatLng(lat[i],lng[i]), i));
  }
}

function switch_view(nview)
{
    if (nview ==0)
       map.setCenter(new GLatLng(43.059857997098916, -85.94329833984375), 9);
    else if (nview ==1)
       map.setCenter(new GLatLng(43.51668853502906, -84.39697265625), 7);
    else if (nview ==2)
      map.setCenter(new GLatLng(41.244772343082076, -97.646484375), 4);
}



//]]>

 var map;
  var gdir;
  var geocoder = null;
  var addressMarker;

  function initialize() {
    if (GBrowserIsCompatible()) {      
      map = new GMap2(document.getElementById("map_canvas"));
      gdir = new GDirections(map, document.getElementById("g_directions"));
      GEvent.addListener(gdir, "load", onGDirectionsLoad);
      GEvent.addListener(gdir, "error", handleErrors);

      setDirections("49097", "145 North Leja Drive 49097", "en_US");
    }
  }
  
  function setDirections(fromAddress, toAddress, locale) {
    gdir.load("from: " + fromAddress + " to: " + toAddress,
              { "locale": + "en_US" });
  }

  function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
     
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
    
   else alert("An unknown error occurred.");
   
}

function onGDirectionsLoad(){ 
    // Use this function to access information about the latest load()
    // results.

    // e.g.
    // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  // and yada yada yada...
}
