/*===========================================================================*/
// 20090605 AK added prod key, changed this file to _prod
// 20090302 AK separated buildPin, changed addPin to accept additional params, gen HTML
// 20090227 AK converted from gmap to gmap2, GBrowserIsCompatible
// 20090226 AK added getDirections
// 20090225 AK new file
/*===========================================================================*/
// DEV
// document.write('<script language="javascript" type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAgA-FoG1r5vikrXYa6QLy1hQTP4g-bV_wp9TW4euxpk5mDEIeGBTq67lWW8g-pEE_Fev6iwhd-VSNTg"></script>');
// PROD
document.write('<script language="javascript" type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAgA-FoG1r5vikrXYa6QLy1hRZbj-zoTFLmZ86xl2lqgiegVtDkhRLJ9tBKszHItjyysClzlcVF1xVPA"></script>');
                                                                                                                         

var gMap;
function buildMap(lat, lon, zoom) {
	if (GBrowserIsCompatible()) {
		var point;
		var marker;
		var map = new GMap2(document.getElementById("map"));
		//map.addControl(new GSmallMapControl());
		map.addControl(new GSmallZoomControl());
		map.addControl(new GMapTypeControl());
		// lat, long of center of the map plus a zoom level (smaller takes you closer) 
		// for this page the center of the map will equal the one community we are displaying
		map.setCenter(new GLatLng(lat, lon), zoom);

		gMap = map;
		
		// so far every use of a map will add at least one pin, so code is here...
		buildPin();
	};
};

var iconCommunity;
function buildPin() {
	// icon object we can reuse if we place several pins on the map
	var iconCommunity = new GIcon();
	iconCommunity.image = "http://maps.google.com/mapfiles/ms/micons/green-dot.png";
	iconCommunity.shadow = "http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png";
	iconCommunity.iconSize = new GSize(32, 32);
	iconCommunity.shadowSize = new GSize(59, 32);
	iconCommunity.iconAnchor = new GPoint(16, 32);
	iconCommunity.infoWindowAnchor = new GPoint(5, 1);
};

function addPin(lat, lon, communityID, communityName, communityStreet1, communityStreet2, communityApt, communityCity, communityState, communityZipcode, communityImage) {
	if (GBrowserIsCompatible()) {
		// These three lines place a pin on the map. Needs lat, long and name
		point = new GLatLng(lat, lon);
		marker = new GMarker(point, {title: communityName, icon: iconCommunity});

		var myHTML = null;
        myHTML = "<table width=330 cellpadding=0 cellspacing=0 class=cContentXsmall><tr>";
        myHTML += "<td width=105 valign=top><img width=100 height=72 src='" + communityImage + "'></td>";
		myHTML += "<td width=225 valign=top><b>" + communityName + "</b><br>";
		myHTML += communityStreet1 + "<br>";
		if (trim(communityStreet2) != '') {
			myHTML += communityStreet2 + "<br>";
		};
		if (trim(communityApt) != '') {
			myHTML += communityApt + "<br>";
		};
		myHTML += communityCity + ', ' + communityState + ' ' + communityZipcode;
		myHTML += "<div align=right><br><a href='comm_detail_main.php?cid=" + communityID + "' class=cCopyrightLink>View Community Details >></a></div>";
		myHTML += "</td></tr></table>";

		//myHTML = "<a href='comm_detail_main.php?cid=" + communityID + "'>" + communityName + "</a>";
		
		GEvent.addListener(
			  marker
			, "click"
			, function() {
				this.openInfoWindowHtml(myHTML);
			  }
		);
		
		gMap.addOverlay(marker);
	};
};

var directionsPanel;
var directions;
function getDirections(addressStart, addressEnd, divRoute) {
	if (GBrowserIsCompatible()) {
		directionsPanel = document.getElementById(divRoute);
		directions = new GDirections(gMap, directionsPanel);
		directions.load("from: " + addressStart + " to: " + addressEnd);
	};
};

/*
function load() {
	// key for prod site: ABQIAAAAgA-FoG1r5vikrXYa6QLy1hRZbj-zoTFLmZ86xl2lqgiegVtDkhRLJ9tBKszHItjyysClzlcVF1xVPA
     if (GBrowserIsCompatible()) {
       var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	var point = new GLatLng(33.847608,-117.89978);
    map.setCenter(point, 7);
 	//map.addOverlay(new GMarker(point, G_DEFAULT_ICON));		
     }
   };
*/
