var dArgyle;
var dSorrento;
var dSettlers;
var dCoastal;
var dCapeSkillion;
var dCapricorn;

    function CreateMarker(lattitude, longitude, infoWindowHtml)
	{
	    var center = new GLatLng(lattitude,longitude);
	  	var dLocalObj = new GMarker(center, {draggable: false});
	  	GEvent.addListener(dLocalObj, "click", function() {
        	dLocalObj.openInfoWindowHtml(infoWindowHtml);
        });
		
		return dLocalObj;
	}
	
	function initialize() {
      if (GBrowserIsCompatible()) {
	  	
		//Establish Canvas
        map = new GMap2(document.getElementById("map_canvas"));
		
		//Set map center and zoom level
		//map.setCenter(new GLatLng(-31.94284,115.85495), 9); Perth
		//map.setCenter(new GLatLng(-31.886886525780806,115.8233642578125), 9); Joondalup
		map.setCenter(new GLatLng(-32.56533316084102, 115.751953125), 7);

		//Michigan Marker and Information
		dArgyle = CreateMarker(-31.916033, 116.074677, "<div class='markerInfo'><h2>The Argyle View </h2><img src='../images/googleMaps/argyle.jpg' alt='The Argyle' class='markerThumb' /><h3>Location</h3><p>Intersection of Darlington<br/>and Coulston Road</p><div><a href='/range_farmhouse/argyle.aspx'>More information</a>&nbsp;|&nbsp;<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Intersection+of+Darlington+and+Coulston+Road&aq=&sll=-31.543668,115.627649&sspn=0.010149,0.014484&ie=UTF8&hq=&hnear=Coulston+Rd+%26+Darlington+Rd,+Darlington+Western+Australia+6070,+Australia&z=16' target='_blank'>Get directions</a></div></div>");
		
		//Michigan Marker and Information
		dSorrento = CreateMarker(-31.543668,115.627649, "<div class='markerInfo'><h2>The Sorrento View </h2><img src='../images/googleMaps/sorrento.jpg' alt='The Sorrento' class='markerThumb' /><h3>Location</h3><p>15 Beachhaven Drive,<br /> Yanchep</p><div><a href='/range_retreat/sorrento.aspx'>More information</a>&nbsp;|&nbsp;<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=15+Beachhaven+Drive,+Yanchep&aq=&sll=-33.950765,115.074234&sspn=0.30188,0.463486&ie=UTF8&hq=&hnear=15+Beachhaven+Dr,+Yanchep+Western+Australia+6035,+Australia&ll=-31.543668,115.627649&spn=0.010149,0.014484&z=16' target='_blank'>Get directions</a></div></div>");
		
		//Michigan Marker and Information
		dSettlers = CreateMarker(-32.33645980333739, 115.85529327392578, "<div class='markerInfo'><h2>The Settlers View </h2><img src='../images/googleMaps/settlers.jpg' alt='The Settlers' class='markerThumb' /><h3>Location</h3><p>Cape Meander, <br />Settlers Hill, Baldivis </p><div><a href='/range_views/settlers.aspx'>More information</a>&nbsp;|&nbsp;<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Cape+Meander,+Settlers+Hill,+Baldivis+&sll=-31.89253,115.8439&sspn=0.012279,0.01929&ie=UTF8&hq=Cape+Meander,+Settlers+Hill,&hnear=Baldivis+WA,+Australia&ll=-32.340811,115.855293&spn=0.204207,0.308647&z=12' target='_blank'>Get directions</a></div></div>");
		
		//Coastal Marker and Information
		dCoastal = CreateMarker(-33.406981, 115.612638, "<div class='markerInfo'><h2>The Coastal View</h2><img src='../images/googleMaps/coastal.jpg' alt='The Coastal View' class='markerThumb' /><h3>Location</h3><p>Lot 4088, Dalyellup Boulevard, <br />Dalyellup</p><div><a href='/range_views/coastal.aspx'>More information</a>&nbsp;|&nbsp;<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Lot+4088,+Dalyellup+Boulevard,+Dalyellup&sll=-31.765001,115.970396&sspn=0.012844,0.01929&ie=UTF8&hq=&hnear=4088+Dalyellup+Blvd,+Dalyellup+Western+Australia+6230,+Australia&z=17' target='_blank'>Get directions</a></div></div>");
		
		//CapeSkillion Marker and Information
	  	dCapeSkillion = CreateMarker(-33.95115645788215, 115.07389068603516, "<div class='markerInfo'><h2>The Cape Skillion</h2><img src='../images/googleMaps/cape-skillion.jpg' alt='The Cape Skillion' class='markerThumb' /><h3>Location</h3><p>Lot 5 Crellin Place, Rapids Landing, <br /> Margaret River </p>  <div><a href='/range_retreat/cape-skillion.aspx'>More information</a>&nbsp;|&nbsp;<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Crellin+Place,+Margaret+River+WA&sll=-33.950124,115.068612&sspn=0.024136,0.038581&ie=UTF8&hq=Crellin+Place,&hnear=Margaret+River+WA,+Australia&ll=-33.951156,115.073891&spn=0.024136,0.038581&z=15' target='_blank'>Get directions</a></div></div>");
		
		//Notre Dame Marker and Information
		dCapricorn = CreateMarker(-31.542607740363767, 115.62917232513428, "<div class='markerInfo'><h2>The Capricorn Loft</h2><img src='../images/googleMaps/capricorn.jpg' alt='The Capricorn Loft' class='markerThumb' /><h3>Location</h3><p>Corner Two Rocks Road &amp; Lindsay Beach Boulevard, <br />Yanchep</p><div><a href='/range_loft/capricorn.asp'>More information</a>&nbsp;|&nbsp;<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Lindsay+Beach+Boulevard,+Yanchep&sll=-32.10119,116.603394&sspn=1.579792,2.469177&ie=UTF8&hq=&hnear=Lindsay+Beach+Blvd,+Yanchep+Western+Australia+6035,+Australia&ll=-31.542608,115.629172&spn=0.012874,0.01929&z=16' target='_blank'>Get directions</a></div></div>");
	
		//Add markers
		map.addOverlay(dArgyle);
		map.addOverlay(dSorrento);
		map.addOverlay(dSettlers);
		map.addOverlay(dCoastal);
		map.addOverlay(dCapeSkillion);
		  
		//Add Controls, remove Scale
		var customUI = map.getDefaultUI();
		customUI.controls.scalecontrol = false;
		map.setUI(customUI);

      }
    }
	
	//Go to the Michigan when this function is called
    function gotoArgyle() {    
closeAll();
      var center = new GLatLng(-31.543668,115.627649);
	  map.panTo(center);
	  GEvent.trigger(dArgyle, "click");
	}
	//Go to the Michigan when this function is called
    function gotoSorrento() {    
closeAll();
      var center = new GLatLng(-33.950765,115.074234);
	  map.panTo(center);
	  GEvent.trigger(dSorrento, "click");
	}
	
	function gotoSettlers(){
	closeAll();
	      var center = new GLatLng(-32.33645980333739, 115.85529327392578);
	  map.panTo(center);
	  GEvent.trigger(dSettlers, "click");
	}
	
	//Go to the Coastal when this function is called
    function gotoCoastal() {    
closeAll();
      var center = new GLatLng(-33.406981, 115.612638);
	  map.panTo(center);
	  GEvent.trigger(dCoastal, "click");
	}
	
	//Go to the CapeSkillion when this function is called
    function gotoCapeSkillion() {    
closeAll();
      var center = new GLatLng(-33.968403, 115.085918);
	  map.panTo(center);
	  GEvent.trigger(dCapeSkillion, "click");
	}
	
	//Go to the Notre Dame when this function is called
    function gotoCapricorn() {    
	  closeAll();
      var center = new GLatLng(-33.968188815916434, 115.085928440094);
	  map.panTo(center);
	  GEvent.trigger(dCapricorn, "click");
	}
	
	function closeAll(){
	dSettlers.closeInfoWindow();
	  dCoastal.closeInfoWindow();
	  dCapeSkillion.closeInfoWindow();
	dArgyle.closeInfoWindow();
dSorrento.closeInfoWindow();
	}
