//<![CDATA[
var restaurants = {
	south: { coords: [33.700025,-111.925239],
			 address:'23425 N Scottsdale Rd',
			 citystate: "Scottsdale, AZ 85255",
			 phone: "(480) 585-6221",
			 name: "Kashman's Place at Pinnacle Peak" },
	north: { coords: [33.780663,-111.92576],
			 address: '32531 N Scottsdale Rd',
			 citystate: "Scottsdale, AZ 85262",
			 phone: "(480) 488-5274",
			 name: "Kashman's Place at the Summit" }
};
var map;

function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	set_center();
	add_location('north');
	add_location('south');
  }
}

function add_location(loc) {
	var coords = restaurants[loc].coords;
	var marker = new GMarker(new GLatLng(coords[0],coords[1]));
	GEvent.addListener(marker,'click',function() {
		marker.openExtInfoWindow(
			map,
			"simple_example_window",
			"<p><span>" + restaurants[loc].name + "</span><br />" +
			restaurants[loc].address + "<br />" +
			restaurants[loc].citystate + "<br />" +
			restaurants[loc].phone + "<br />" + 
			"<div><strong>Start address:</strong><br /><input type='text' id='" + loc + "_to_addr' /> <button onclick='set_directions(\"" + loc + "\")'>Get Directions</button></div>",
			{beakOffset: 3}
		);
	});
	map.addOverlay(marker);
}

function set_center() {
	var lat;
	var lng;
	lat = (restaurants.north.coords[0] + restaurants.south.coords[0]) / 2;
	lng = (restaurants.north.coords[1] + restaurants.south.coords[1]) / 2;
	map.setCenter(new GLatLng(lat,lng),12);
}

function set_directions(loc) {
	var query = "from: " + $('#'+loc+'_to_addr').val() + " to: " + restaurants[loc].address + " " + restaurants[loc].citystate;
	window.location = "http://maps.google.com/maps?q=" + query;
}

//]]>

$(window).load(function() {
	load();
});

$(window).unload(function() {
	GUnload();
});