// add colour markers here
var orange;

// this variable will collect the html which will eventually be placed in the side_bar
var side_bar_html = "";

// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var i = 0;
	
jQuery(function(){
   
	var baseIcon = new GIcon();
	  baseIcon.iconSize=new GSize(16,28);
	  baseIcon.shadowSize=new GSize(40,28);
	  baseIcon.iconAnchor=new GPoint(16,28);
	  baseIcon.infoWindowAnchor=new GPoint(8,0);
	orange = new GIcon(baseIcon, "/images/marker_orange.png", null, "/images/pin_shadow.png");
	
	if(map_location == 'coonara'){
	  callMap(-33.745028,151.030525, 14);
	} else {
	  callMap(-33.713661,150.975056, 14);
	}
});

function callMap( lat, lon, zoom ) {
	 
	 // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(lat, lon), zoom);

  // add the points 

	// West Pennant Hills
	var point = new GLatLng(-33.745028,151.030525);
	var marker = createMarker(point,'<img src="/images/marker_orange.png" height="14" width="8"/>West Pennant Hills','<div style="width:218px; padding: 0; margin: 0 0 -20px 0;"><div style="height:80px; padding: 0; margin: 0px 0 10px 0;"><img src="/images/smart-map1.jpg" height="80"/></div><h4>West Pennant Hills</h4><p>Coonara Health Centre<br />Suite 1C, 35 Coonara Avenue<br />West Pennant Hills, NSW 2125<br />Telephone: 02 9894 4999</p></div>', orange)
	map.addOverlay(marker);
	
	// Kellyville
	var point = new GLatLng(-33.713661,150.975056);
	var marker = createMarker(point,'<img src="/images/marker_orange.png" height="14" width="8"/>Kellyville','<div style="width:218px; padding: 0; margin: 0 0 -20px 0;"><div style="height:80px; padding: 0; margin: 0px 0 10px 0;"><img src="/images/smart-map1.jpg" height="80"/></div><h4>Kellyville</h4><p>Kellyville Health Centre<br />120 Wrights Road<br />Kellyville, NSW 2155<br />Telephone: 02 8883 3999</p></div>', orange)
	map.addOverlay(marker);



	// Street View Pano
	var myPano = new GStreetviewPanorama(document.getElementById("pano"));
	if(map_location == 'coonara'){
	  	coonara = new GLatLng(-33.745028,151.030525);
		myPOV = {yaw:166,pitch:-5,zoom:0};
	} else {
	  	coonara = new GLatLng(-33.713661,150.975056);
		myPOV = {yaw:320,pitch:-5,zoom:0};
	}
	myPano.setLocationAndPOV(coonara, myPOV);
	
	
	
}





  // A function to create the marker and set up the event window
      function createMarker(point,name,html,icon) {
        var marker = new GMarker(point,icon);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        // add a line to the side_bar html
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        i++;
        return marker;
      }

      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }
