var obj = {
	SGmap : Object,
	sidebar_html : "",
	gmarkers : Array,
	htmls : Array,
	i : 0,
	baseIcon : Object,
	init : function() {
	  // set local object vars here
	  // Display the map, with some controls
	  obj.gmarkers=new Array();
	  obj.SGmap = new GMap2(document.getElementById("map"));
	  obj.SGmap.addControl(new GLargeMapControl());
	  obj.SGmap.addControl(new GMapTypeControl());
  	  obj.SGmap.setCenter(new GLatLng(42.01716197,-87.773208),9);
      	  obj.baseIcon = new GIcon();
      	  obj.baseIcon.image = "marker.png";
      	  obj.baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
      	  obj.baseIcon.iconSize = new GSize(20, 34);
      	  obj.baseIcon.shadowSize = new GSize(37, 34);
      	  obj.baseIcon.iconAnchor = new GPoint(9, 34);
      	  obj.baseIcon.infoWindowAnchor = new GPoint(9, 2);
      	  obj.baseIcon.infoShadowAnchor = new GPoint(18, 25);
	  this.run();
	},
	run : function() {
	  // run bulk of behavior here
      	  // ================================================================
      	  // === Fetch the JSON data file ====
          GDownloadUrl("data.json.php", obj.process_it);
      	  // ================================================================

	},

	// This function picks up the click and opens the corresponding info window
	myclick : function (i) {
	  obj.SGmap.openInfoWindowHtml(obj.gmarkers[i].getPoint(),obj.htmls[i]);
	},

	// A function to create the marker and set up the event window
	createMarker : function (point,name,html) {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
          });
          // save the info we need to use later for the sidebar
          obj.gmarkers[obj.i] = marker;
          obj.htmls[obj.i] = html;
          // add a line to the sidebar html
          obj.sidebar_html += '<a href="javascript:obj.myclick(' + obj.i + ')">' + name + '</a><br>';
          obj.i++;
          return marker;
      },

      // ================================================================
      // === Define the function thats going to process the JSON file ===
      process_it : function(doc) {
        // === Parse the JSON document ===
        var jsonData = eval('(' + doc + ')');
        // === Plot the markers ===
        for (var i=0; i<jsonData.markers.length; i++) {
          var point = new GLatLng(jsonData.markers[i].lat, jsonData.markers[i].lng);
          var marker = obj.createMarker(point, jsonData.markers[i].label, jsonData.markers[i].html);
          obj.SGmap.addOverlay(marker);
        }
        // put the assembled sidebar_html contents into the sidebar div
        $("sidebar").innerHTML = obj.sidebar_html;
        //obj.polyline_it(jsonData); // use for drawing lines
      },

      polyline_it : function(jsonData){
        // === Plot the polylines ===
        for (var i=0; i<jsonData.lines.length; i++) {
          var pts = [];
          for (var j=0; j<jsonData.lines[i].points.length; j++) {
            pts[j] = new GLatLng(jsonData.lines[i].points[j].lat, jsonData.lines[i].points[j].lng);
          }
          obj.SGmap.addOverlay(new GPolyline(pts, jsonData.lines[i].colour, jsonData.lines[i].width));
        }
      }
}


var timer_ = {
  date1 : Object,
  milliseconds1 : '',
  date2 : Object,
  milliseconds2 : '',
  start : function () {
    this.date1 = new Date();
    this. milliseconds1 = this.date1.getTime();
  },
  stop : function () {
    this.date2 = new Date();
    this.milliseconds2 = this.date2.getTime();
  },
  time : function (){
    return this.milliseconds2 - this.milliseconds1;
  }
}


var util_ = {


}


function initializer() {
	if (GBrowserIsCompatible()) {
	  obj.init();
	// other init() methods go here
	

	//timer_.stop();
	//alert(timer_.time());
	
	
	
	} else {
	  alert("Sorry, the Google Maps API is not compatible with this browser");
	}

}
// This Javascript is based on code provided by the
// Blackpool Community Church Javascript Team
// http://www.commchurch.freeserve.co.uk/
// http://www.econym.demon.co.uk/googlemaps/
// as well as can be found on Dustan Diaz''s site
// http://www.dustindiaz.com/json-for-the-masses/
// and modified by http://www.shawngo.com
