// JavaScript Document

//<![CDATA[

if (GBrowserIsCompatible()) { 

      // ========== Read paramaters that have been passed in ==========
      
      // Before we go looking for the passed parameters, set some defaults
      // in case there are no parameters
      var lat = 38.277805;
      var lng = -96.099010;
      var zoom = 4;
      var maptype = G_NORMAL_MAP;

      // If there are any parameters at the end of the URL, they will be in  location.search
      // looking something like  "?lat=50&lng=-3&zoom=10&type=h"

      // skip the first character, we are not interested in the "?"
      var query = location.search.substring(1);

      // split the rest at each "&" character to give a list of  "argname=value"  pairs
      var pairs = query.split("&");
      for (var i=0; i<pairs.length; i++) {
        // break each pair at the first "=" to obtain the argname and value
	var pos = pairs[i].indexOf("=");
	var argname = pairs[i].substring(0,pos).toLowerCase();
	var value = pairs[i].substring(pos+1).toLowerCase();

        // process each possible argname
        if (argname == "lat") {lat = parseFloat(value);}
        if (argname == "lng") {lng = parseFloat(value);}
        if (argname == "zoom") {zoom = parseInt(value);}
        if (argname == "type") {
          if (value == "m") {maptype = G_NORMAL_MAP;}
          if (value == "k") {maptype = G_SATELLITE_MAP;}
          if (value == "h") {maptype = G_HYBRID_MAP;}
        }
      }

      // ========== Create the map using the information obtained above ========
      var map = new GMap2(document.getElementById("amoremap"));
      map.addControl(new GLargeMapControl());
      map.setCenter(new GLatLng(lat,lng), zoom, maptype);
      var mm = new GMarkerManager(map);

      // ========== This function will create the "link to this page"
      function makeLink() {
        var a="../locations" 
           + "?lat=" + map.getCenter().lat().toFixed(6)
           + "&lng=" + map.getCenter().lng().toFixed(6)
           + "&zoom=" + map.getZoom()
           + "&type=" + map.getCurrentMapType().getUrlArg();
        document.getElementById("mylink").innerHTML = '<a href="' +a+ '">Link to this page</a>';
      }

      // Make the link the first time when the page opens
      //makeLink();

      // Make the link again whenever the map changes
      GEvent.addListener(map, 'moveend', makeLink);
    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }








	
// Create our "tiny" marker icon
var icon = new GIcon();
icon.iconSize = new GSize(16, 24);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(8, 24);
icon.infoWindowAnchor = new GPoint(5, 1);


// Create the marker and corresponding information window
function createInfoMarker(point, address) {
   var marker = new GMarker(point, icon);
   GEvent.addListener(marker, "click",
      function() {
         marker.openInfoWindowHtml(address);
      }
   );
  return marker;
}


// -------------------- STATE LEVEL ---------------------------------------------

// -------------------- michigan -------------------------
var point = new GPoint(-84.552279, 42.73202);
var icon = new GIcon(G_DEFAULT_ICON);
address = "<h1>MICHIGAN</h1><p>1 Location</p>";
var marker = createInfoMarker (point, address);
mm.addMarker(marker,0,4); 

// -------------------- missouri -------------------------
var point = new GPoint (-92.460938, 38.238180);
var icon = new GIcon(G_DEFAULT_ICON);
address = "<h1>MISSOURI</h1><p>1 Location</p>";
var marker = createInfoMarker (point, address);
mm.addMarker(marker,0,4);

// -------------------- illinois -------------------------
var point = new GPoint (-89.643604, 39.801055);
var icon = new GIcon(G_DEFAULT_ICON);
address = "<h1>ILLINOIS</h1><p>1 Location</p>";
var marker = createInfoMarker (point, address);
mm.addMarker(marker,0,4);


// -------------------- CITY LEVEL ---------------------------------------------

// -------------------- michigan -------------------------

// EASTPOINTE
//var point = new GPoint(-82.955419, 42.4682);
//var icon = new GIcon(G_DEFAULT_ICON);
//address = "<h1>Eastpointe</h1><p>1 Location</p>";
//var marker = createInfoMarker(point, address);
//mm.addMarker(marker,5,7); 


// -------------------- missouri -------------------------

// KANSAS CITY
//var point = new GPoint (-94.583062, 39.10296);
//var icon = new GIcon(G_DEFAULT_ICON);
//address = "<h1>Kansas City</h1><p>1 Location</p>";
//var marker = createInfoMarker (point, address);
//mm.addMarker(marker,5,7); 


// -------------------- illinois -------------------------

// WILLOWBROOK
//var point = new GPoint (-87.940253, 41.747282);
//var icon = new GIcon(G_DEFAULT_ICON);
//address = "<h1>Willowbrook</h1><p>1 Location</p>";
//var marker = createInfoMarker (point, address);
//mm.addMarker(marker,5,7); 


// -------------------- DETAIL LEVEL ---------------------------------------------


// -------------------- michigan -------------------------

// 22432 Petersburg Ave
var point = new GPoint(-82.926959, 42.463124);
var icon = new GIcon(G_DEFAULT_ICON);
address = "<div style='height:150px'><h2>Beautiful Scenery, Inc.</h2><p>22432 Petersburg Ave<br />Eastpointe, MI 48021<br />LaSonda Clark</p></div>";
var marker = createInfoMarker(point, address);
mm.addMarker(marker,5,17); 


// -------------------- missouri -------------------------

// 3101 Broadway
var point = new GPoint (-94.589912, 39.071161);
var icon = new GIcon(G_DEFAULT_ICON);
address = "<div style='height:150px'><h2>Open Options</h2><p style='margin:0px;'>3101 Broadway, Suite 400<br />Kansas City, MO 64111<br />Bruce Scott CEO</p></div>";
var marker = createInfoMarker (point, address);
mm.addMarker(marker,5,17); 


// -------------------- illinois -------------------------

// 16W621 S Frontage Rd
var point = new GPoint (-87.950295, 41.738763);
var icon = new GIcon(G_DEFAULT_ICON);
address = "<div style='height:150px'><h2>Champagne Lodge &amp; Luxury Suites</h2><p>16W621 S Frontage Rd<br />Willowbrook, IL 60527<br />Robert Hanson<br />John VanProoyen</p></div>";
var marker = createInfoMarker (point, address);
mm.addMarker(marker,5,17); 

//]]>

