/***************************************************************************
	Theme Name: Quit!
	Theme URI: http://www.richardlefever.com
	Description: Java Script - contains Java Script for the Google Map
	Date: 20 June, 2008 
	Author: Petra G. Yocum (www.petragyocum.com)
***********************************************************************/
var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;

// A function to create the marker and set up the event window
function createMarker(point,name,html, icon) {
var marker = new GMarker(point, {icon:icon, title:name});
	
	// The info window version with the "to here" form open
	to_htmls[i] = html + '<p>Directions: <strong>To here<\/strong> - <a href="javascript:fromhere(' + i + ')">From here<\/a><\/p>' +
		 '<p>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
		 '<input type="text" name="saddr" id="saddr" value="" /><br />' +
		 '<button value="Get Directions" type="submit">Get Directions<\/button><\/p>' +
		 '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + '"/>';
	// The info window version with the "to here" form open
	from_htmls[i] = html + '<p>Directions: <a href="javascript:tohere(' + i + ')">To here<\/a> - <strong>From here<\/strong><\/p>' +
		 '<p>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
		 '<input type="text" name="daddr" id="daddr" value="" /><br />' +
		 '<button value="Get Directions" type="submit">Get Directions<\/button><\/p>' +
		 '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() + '"/>';
	// The inactive version of the direction info
	html = html + '<p>Directions: <a href="javascript:tohere('+i+')">To here<\/a> - <a href="javascript:fromhere('+i+')">From here<\/a><\/p>';
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

// functions that open the directions forms
function tohere(i) {
	gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}

function fromhere(i) {
	gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}

function load() {
    if (GBrowserIsCompatible()) {

			// Display the map, with some controls and set the initial location 
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(45.633439,-122.665863), 16);
			// Create our "tiny" marker icon
			var icon = new GIcon();
			icon.image = "../images/googleMapMarker.png";
			icon.shadow = "../images/googleMapMarkerShadow.png";
			icon.iconSize = new GSize(58, 60);
			icon.shadowSize = new GSize(58, 60);
			icon.iconAnchor = new GPoint(6, 20);
			icon.infoWindowAnchor = new GPoint(5, 1);
		
			var point = new GLatLng(45.633439,-122.665863);
			// Our info window content for the main location
			var v_title1 = 'CRM Key Office';
			var v_adr1 = '604 E 16th Street';
			var v_stzip1 = 'Vancouver, WA 98663';
			var v_qs1 = (v_adr1 + ' ' +v_stzip1).split(' ').join('+');
			// Set point and click event for popup Information Window
			 var point = new GLatLng(45.633439,-122.665863);
			 var html = '<h1>' + v_title1 + '</h1><p>' + v_adr1 + '<br />' + v_stzip1 + '</p>'
			// Add pointer to map - calls createMarker function
			 map.addOverlay(createMarker(point, "CRM Key Office", html, icon));
   	}
    
    // display a warning if the browser was not compatible
    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/