function addGoogleControls(googleMap)
{
//  map.addControl(new GLargeMapControl());
//  map.addControl(new PositionControl());
  googleMap.addControl(new GLargeMapControl3D());
  //googleMap.addControl(new GMapTypeControl());
  googleMap.setMapType(G_NORMAL_MAP);
}

function addFullScreenToggler(googleMap)
{
	GEvent.addListener(googleMap, "dblclick", function() {
		alert("in method map dblclicked");
		// toggle the small and large Drive map classes
		// refresh the map
		$('#fullScreenAnchor').trigger("click");
	});	
}

function fullScreenToggler()
{
	if ($('#map').hasClass("smallDriveMap")) {
		$('#map').removeClass("smallDriveMap");
		$('#map').addClass("largeDriveMap");
	}
	else {
		$('#map').removeClass("largeDriveMap");
		$('#map').addClass("smallDriveMap");
	}
}

function openFullScreenDriveMap(hostBase, institutionId)
{
//	alert("hostBase is: " + hostBase + " id is: " + institutionId);
	var actionStr = 'organization!showDrivemapFullscreen.do?id=' + institutionId;
	var theUrl = hostBase + "/" + actionStr;
	var newWindow = window.open(theUrl, '', 'fullscreen=yes, scrollbars=yes');
	if (newWindow)
		newWindow.focus();
	var mapDiv = newWindow.document.getElementById("map2");
}

function openFullScreenMemberMap(hostBase, institutionId)
{
//	alert("hostBase is: " + hostBase + " id is: " + institutionId);
	var actionStr = 'organization!showMembermapFullscreen.do?id=' + institutionId;
	var theUrl = hostBase + "/" + actionStr;
	var newWindow = window.open(theUrl, '', 'fullscreen=yes, scrollbars=yes');
	if (newWindow)
		newWindow.focus();
	var mapDiv = newWindow.document.getElementById("map2");
}

function openFullScreenProjectMap(hostBase, projectId)
{
//	alert("hostBase is: " + hostBase + " id is: " + projectId);
	var actionStr = 'project!showMapFullscreen.do?id=' + projectId;
	var theUrl = hostBase + "/" + actionStr;
	var newWindow = window.open(theUrl, '', 'fullscreen=yes, scrollbars=yes');
	if (newWindow)
		newWindow.focus();
}

function closeWindow()
{
	window.close();
}

function getSearchIdx(testValue, searchList)
{
	var retVar = -1;
	
	for(var j = 0; j < searchList.length; j++)
	{
//		alert("comparing " + testValue + " and " + searchList[j]);
		if (testValue == searchList[j])
		{
			retVar = j;
			break;
		}
	}
	return retVar;
}

function createStatusList (hostBase, institutionId, statusArray)
{
	var url = hostBase + '/ajax/data/members/unique/status/' + institutionId;
	jQuery.ajax({
		url: url,
		dataType: 'xml',
		success: function(xml){
			// XMLSerializer exists in current Mozilla browsers
//			serializer = new XMLSerializer();
//			serialized = serializer.serializeToString(xml);
//			alert("function returned with the following xml: " + serialized);
			
			$(xml).find('status').each(function(i) {
				var memStatus = $(this).text();
				statusArray.push(memStatus);
			});
		}
	});
}

function createMarkerOptions(statusStr, fName, lName, statusList, colorList, hostBase)
{
	var colorIdx = 0;
	var statusIdx = getSearchIdx(statusStr, statusList);
	if (statusIdx != -1)
	{
//		alert("match a status");
		if (statusIdx < colorList.length)
			colorIdx = statusIdx;
	}
	
	var tempImagePath = colorList[colorIdx];
	// Create our "member" marker icon
	
	var memIcon = createGoogleIcon (hostBase, tempImagePath, null, null,
			null, null, null);
	
	var titleStr = fName + " " + lName;
//	alert("title is: " + titleStr);
	// Set up our GMarkerOptions object
	var markerOptions = { icon:memIcon, title:titleStr};
	
	return markerOptions;
}

function createGoogleIcon (hostBase, iconPath, iconWidth, iconHeight, shadowPath, shadowWidth, shadowHeight)
{
	// Create a marker icon
	
	var iconSize = null;
	var shadowSize = null;
	
	if (iconWidth != null && iconHeight != null)
		iconSize = new GSize(iconWidth, iconHeight);
	
	if (shadowWidth != null && shadowHeight != null)
		shadowSize = new GSize(shadowWidth, shadowHeight);
	
	var myIcon = new GIcon(G_DEFAULT_ICON);
	
	// override the defaults
	// example 	churchIcon.image = hostBase + "/images/memberPlot/blue-point.png";

	myIcon.image = hostBase + iconPath;
	if (iconSize != null)
		myIcon.iconSize = iconSize;
	//if (shadowPath != null)
		myIcon.shadow = "";
	//if (shadowSize != null)
		myIcon.shadowSize = shadowSize;
	
	return myIcon;
	
}

function createChurchIcon(hostBase)
{
	var churchImagePath = "/images/memberPlot/church-icon.png";
	var churchImageShadow = "/images/memberPlot/shadow.png";
	
	// Create our "church" marker icon
	
	var churchIcon = createGoogleIcon (hostBase, churchImagePath, null, null,
			null, null, null);

	return churchIcon;
}

function createColorList()
{
	var colorList = ['/images/memberPlot/red-point.png', '/images/memberPlot/green-point.png', '/images/memberPlot/orange-point.png', '/images/memberPlot/purple-point.png', '/images/memberPlot/yellow-point.png', '/images/memberPlot/dark-blue-point.png'];

	return colorList;
}
