$(document).ready(function() {
  $("#map").css({
		height: 490,
		width: 640
	});
  var myLatLng = new google.maps.LatLng(-31.34, 163.2);

  MYMAP.init('#map', myLatLng, 5);

  var Route = [new google.maps.LatLng(-26.67710, 153.13248), new google.maps.LatLng(-39.05334, 174.04137)];
  var Course = new google.maps.Polyline({
    path: Route,
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  Course.setMap(MYMAP.map);



  $("#showmarkers").click(function(e){
		MYMAP.placeMarkers('wishbone.xml');
  });
});

var MYMAP = {
  map: null,
  bounds: null
}

MYMAP.init = function(selector, latLng, zoom) {
  var myOptions = {
    zoom:zoom,
    center: latLng,
    mapTypeId: google.maps.MapTypeId.HYBRID,

  }
  this.map = new google.maps.Map($(selector)[0], myOptions);
  this.bounds = new google.maps.LatLngBounds();

}

MYMAP.placeMarkers = function(filename) {
	$.get(filename, function(xml){
		$(xml).find("marker").each(function(){
			var name = $(this).find('name').text();
			var address = $(this).find('address').text();
			
			// create a new LatLng point for the marker
			var lat = $(this).find('lat').text();
			var lng = $(this).find('lng').text();
			var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
			
			// extend the bounds to include the new point
/*			MYMAP.bounds.extend(point); */
			var image = 'http://www.trishlewis.com/uploads/wishbone/button.png';

			var marker = new google.maps.Marker({
				position: point,
				map: MYMAP.map,
				icon: image
			});
			
			var infoWindow = new google.maps.InfoWindow();
			var html='<h3>'+name+'</h3>Pos: <strong>'+lat+' '+lng+'</strong><br />'+'<em>'+address+'</em>';
			google.maps.event.addListener(marker, 'click', function() {
				infoWindow.setContent(html);
				infoWindow.open(MYMAP.map, marker);
			});
 		/*MYMAP.map.fitBounds(MYMAP.bounds);*/

		});
	});
}