<!-- TODO:  Add in all general map related stuff here -->
	<!-- Geocode -->
		var degreesToRadians = (180/Math.PI);
		function OffsetLng(latlng, amount)
		{
			return latlng.lng() + (amount / 3959) * degreesToRadians;
		}
		function DistanceLatLong(latlng1, latlng2)
		{
			var result = 
				3959 * Math.acos(Math.sin(latlng1.lat()/degreesToRadians) * Math.sin(latlng2.lat()/degreesToRadians) +
					Math.cos(latlng1.lat()/degreesToRadians) * Math.cos(latlng2.lat()/degreesToRadians) *
					Math.cos(latlng1.lng()/degreesToRadians - latlng2.lng()/degreesToRadians));
			if(result == 0) result = 0.01;
			return result;
		}
	<!-- /Geocode -->
	<!-- Map -->
		<!-- Include Google maps script -->
		var myMap = null;
		var myDirections = null;
		var myMapType = null;
		function CreateMap(div, onDragEndEvent)
		{
			myMap = new GMap2(div);
			//myMap.enableDoubleClickZoom();
			//myMap.enableContinuousZoom();
			myMap.enableScrollWheelZoom();
			myMap.addControl(new GLargeMapControl());
			InitializeTraffic();
			
			// On mouse dragend, capture center point of map
			if(onDragEndEvent != null)
				GEvent.addListener(myMap, "dragend", onDragEndEvent);
			GEvent.addListener(myMap, "zoomend", OnZoomEndEvent);
//			initGas();
		}
		function CheckMapCreated(div, onDragEndEvent)
		{
			if(myMap == null)
				CreateMap(div, onDragEndEvent);
		}
		function SetMapCenter(latlng, zoom)
		{
			myMap.setCenter(latlng, zoom);
		}
	<!-- /Map -->
	<!-- Icons -->
		function getMarkerIconSrc(i, talkconnector)
		{
			return "/images/marker_" + ((talkconnector && TalkByPCSupportsBrowser()) ? "green" : "red") + (i+1) + ".png";
		}
		function CreateGIcon(width, height)
		{
			var icon = new GIcon();
			icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			icon.iconSize = new GSize(width, height);
			icon.shadowSize = new GSize(37, 34);
			icon.iconAnchor = new GPoint(9, 34);
			icon.infoWindowAnchor = new GPoint(9, 2);
			icon.infoShadowAnchor = new GPoint(18, 25);
			return icon;
		}

		var baseIconHome = CreateGIcon(39, 34);
		var baseIcon = CreateGIcon(40, 38);
	<!-- /Icons -->
	<!-- Marker -->
		var markerArray = [];
		var allMarkerArray = [];
		function CreateMarker(latlng, address, information, index, talkconnector)
		{
			// Create a lettered icon for this point using our icon class
			var icon;
			var latlnguse = latlng;
			index ++;
			if (index == 0)
			{
				icon = new GIcon(baseIconHome);
				icon.image = "http://maps.google.com/mapfiles/arrow.png";
			}
			else
			{
				icon = new GIcon(baseIcon);
				icon.image = getMarkerIconSrc(index - 1, talkconnector);
				for(var n = 1; n < markerArray.length; n ++)
				{
					var markerPoint = markerArray[n].getPoint();
					var dist = DistanceLatLong(latlng, markerPoint);
					if(dist < .01)
					{
						<!-- Offset a little so they don't appear to be at the exact same address -->
						latlnguse = new GLatLng(latlng.lat(), OffsetLng(latlng, dist - .01));
						break;
					}
				}
			}
			var marker = new GMarker(latlnguse, icon);
			myMap.addOverlay(marker);
			marker.businessInformation = information;
			marker.businessAddress = address;
			marker.businessTalkByPC = talkconnector;
			if(index != 0)
			{
				marker.currentClickListener = GEvent.addListener(marker, "click", 
					function()
					{
						myMap.closeInfoWindow();
						marker.openInfoWindowHtml(GetInfoWindowHtmlText(marker));
					}
				);
			}
			marker.businessIndex = index;
			markerArray[index] = marker;
			allMarkerArray[allMarkerArray.length] = marker;
			return marker;
		}
		function OpenInfoLocation(index)
		{
			SetMapCenter(markerArray[index].getPoint());
			markerArray[index].openInfoWindowHtml(GetInfoWindowHtmlText(markerArray[index]));
		}
		function ClearMarkers()
		{
			for(var n = 1; n < allMarkerArray.length; n ++)
			{
				myMap.removeOverlay(allMarkerArray[n]);
			}
			markerArray = markerArray.slice(0,1);
			allMarkerArray = allMarkerArray.slice(0,1);
		}
	<!-- /Marker -->
	<!-- Traffic -->
		function InitializeTraffic()
		{
			myMap.addControl(myMapType = new ExtMapTypeControl({showTraffic: true}));
		}
		function ShowTraffic()
		{
			myMapType.trafficInfo.hidden = false;
			myMapType.trafficInfo.show();
			myMapType.toggleButton_(myMapType.trafficDiv.firstChild, true);
			CheckForTrafficIcons();
		}
		function HideTraffic()
		{
			myMapType.trafficInfo.hidden = true;
			myMapType.trafficInfo.hide();
			myMapType.toggleButton_(myMapType.trafficDiv.firstChild, false);
		}
		function OnZoomEndEvent()
		{
			nTrafficCheckedCount = 0;
			CheckForTrafficIcons();
		}
		var nTrafficCheckedCount = 0;
		function CheckForTrafficIcons()
		{
			if(UpdateTrafficIcons() == 0)
			{
				nTrafficCheckedCount ++;
				if(nTrafficCheckedCount < 15)
				//Increase milli-seconds below (2nd argument) if some of the custom traffic light icons are not showing up.
					setTimeout("CheckForTrafficIcons();", 1000); 
			}
		}
		function UpdateTrafficIcons()
		{
			var nChanged = 0;
			for(var i = 0; i < document.images.length; i ++)
			{
				var img = document.images[i]
				var imgName = img.src.toUpperCase()
				//If Google's file name changes then the following condition will never be true and Google's traffic light icons will not be replaced.
				//So we need to use the "if" statement below (commented out) to find out the new name of the file we are trying to replace.
				if(imgName == 'HTTP://MAPS.GSTATIC.COM/INTL/EN_US/MAPFILES/TRAFFIC.PNG') 
				{
					img.src = '/images/Traffic_Icon.png';
					img.style.width =(img.width = 20) + "px";
					img.style.height =(img.height = 40) + "px";
					nChanged ++;
					
				}
				//if (imgName.indexOf("PNG") > 0 && imgName.indexOf("TRAFFIC") > 0) alert(imgName);
			}
			FixPngTransparency();
			return nChanged;
		}
	<!-- /Traffic -->
	<!-- Businesses -->
	function GetHomeLocation(lat, long, address, onDragEndEvent)
	{
		CheckMapCreated(document.getElementById('mapId'), onDragEndEvent);
		ptHome = new GLatLng(lat,long);
		SetMapCenter(ptHome, (address == null) ? 3 : 14);
		if(address != null)
		{
			CreateMarker(ptHome, address, address, -1, null);
		}
	}

	function GetInfoWindowHtmlText(marker)
	{
		if(marker.businessTalkByPC && TalkByPCSupportsBrowser())
		{
			return marker.businessInformation + "<br /><a href='javascript:void(0);' onClick='LaunchTalkConnector(\"" + marker.businessTalkByPC + "\");'><img src='http://www.talkbypc.com/TalkbyPC-16.gif' />Call NOW!</a>";
		}
		return marker.businessInformation;
	}
	<!-- /Businesses-->
	
	<!-- Directions -->
	function RegisterEvent(element, type, func)
	{
		if (element.addEventListener)
		{
			element.addEventListener(type, func, false)
		}
		else if (element.attachEvent)
		{
			if (!element._listeners) element._listeners = new Array()
			if (!element._listeners[type]) element._listeners[type] = new Array()
			var workaroundFunc = function()
			{
				func.apply(element, new Array())
			}
			element._listeners[type][func] = workaroundFunc
			element.attachEvent('on' + type, workaroundFunc)
		}
	}
	function UnregisterEvent(element, type, func)
	{
		if (element.removeEventListener)
		{
			element.removeEventListener(type, func, false)
		}
		else if (element.detachEvent)
		{
			if (element._listeners 
					&& element._listeners[type] 
					&& element._listeners[type][func])
			{
				element.detachEvent('on' + type, 
						element._listeners[type][func])
			}
		}
	}
	function LoadDirections(start, finish, panel)
	{
		if(myDirections != null)
			myDirections.clear();
		else
		{
			myDirections = new GDirections(myMap, panel);
			 GEvent.addListener(myDirections, "load", function() {panel.innerText = '';});
			GEvent.addListener(myDirections, "error", function() {alert('Error loading directions.');});
		}
		panel.innerText = "Loading directions...";
		myDirections.load(start + " to " + finish, {getSteps:true});
	}
	var savedTarget=null; // The target layer (effectively vidPane)
	var orgCursor=null;   // The original Cursor (mouse) Style so we can restore it
	var dragOK=false;     // True if we're allowed to move the element under mouse
	var dragXoffset=0;    // How much we've moved the element on the horozontal
	var dragYoffset=0;    // How much we've moved the element on the verticle
	var vidPaneID;
	function moveHandler(e)
	{
		if (e == null) { e = window.event } 
		if (e.button<=1&&dragOK)
		{
			vidPaneID.style.left=e.clientX-dragXoffset+'px';
			vidPaneID.style.top=e.clientY-dragYoffset+'px';
			return false;
		}
	}
	function cleanup(e)
	{
		document.onmousemove=null;
		document.onmouseup=null;
		savedTarget.style.cursor=orgCursor;
		dragOK=false;
	}
	function OnDirectionsPopupTitleMouseDown(event, panelId)
	{
		var htype='-moz-grabbing';
		if (event == null)
		{
			event = window.event;
			htype='move';
		} 
		var target = event.target != null ? event.target : event.srcElement;
		orgCursor=target.style.cursor;
		vidPaneID = document.getElementById(panelId);
		savedTarget=target;
		target.style.cursor=htype;
		dragOK=true;
		dragXoffset=event.clientX-parseInt(vidPaneID.style.left);
		dragYoffset=event.clientY-parseInt(vidPaneID.style.top);
		document.onmousemove=moveHandler;
		document.onmouseup=cleanup;
		return false;
	}
	function LoadDirectionsPopup(start, finish, panel)
	{
		if(panel.style.visibility != 'hidden')
		{
			panel.innerHTML = "";
			panel.style.visibility = 'hidden';
		}
		panel.style.width = '350px';
		panel.style.borderWidth = '1px';
		panel.style.borderColor = 'black';
		panel.style.borderStyle = 'solid';
		var newInnerHtml = '<table cellpadding=0 cellspacing=0 style="width:100%; background-color:#EFF7FF;"><tr><td style="width:100%"><div onmousedown="OnDirectionsPopupTitleMouseDown(event, ' + "'" + panel.id + "'" + ');">&nbsp;</div></td><td><div class="DirectionsPopupHeader" style="padding:2px;"><a href="javascript:void(0);" onclick="HideTalkConnector();"><img src="images/Close.png" border=0 /></a></div></td></tr></table>';
		newInnerHtml += '<div id="DirectionsDest" style="background-color:white;"></div>';
		panel.innerHTML = newInnerHtml;
		OnResized();
		var children = panel.getElementsByTagName('div');
		var target = null;
		for(var n = 0; n < children.length && target == null; n ++)
		{
			if(children[n].id == 'DirectionsDest')
				target = children[n];
		}
		if(myDirections != null)
		{
			myDirections.clear();
			delete myDirections;
		}
		myDirections = new GDirections(myMap, target);
        GEvent.addListener(myDirections, "load", function() {panel.style.visibility = 'visible'; OnResized();});
        GEvent.addListener(myDirections, "error", function() {alert('Error loading directions.');});
		myDirections.load(start + " to " + finish, {getSteps:true});
		OnResized();
	}
	<!-- /Directions -->
	
	<!-- Talk Connector -->
		function TalkByPCSupportsBrowser()
		{
			// IE only
			var browser=navigator.appName;
			if (browser=="Microsoft Internet Explorer")
				return true;
			return false;
		}
		function LaunchTalkConnector(phoneNumber)
		{
			var div = document.getElementById('TalkConnectorDiv');
			if(div.style.visibility != 'hidden')
				HideTalkConnector();
			div.style.width = '671px';
			div.style.height = '483px';
			div.style.visibility = 'visible';
			var newInnerHtml = "";
			newInnerHtml = '<div class="TalkConnectorHeader"><a href="javascript:void(0);" onclick="HideTalkConnector();">Close</a></div>';
			newInnerHtml += '<div class="TalkConnectorObject"><object classid="clsid:C179BBD3-20AF-47C0-9071-82427E2A8E50" CODEBASE="http://www.talkconnector.com/talkconnector.cab" id="MainWnd">';
			newInnerHtml += '<param name="init" value="1[0.2.0.2] C[TALKBYPCGUEST] S[ftp://www2.meetbypc.com] N[N=' + phoneNumber + '] K[http://www.talkconnector.com/TalkConnector20070821.ymsk]">';
			newInnerHtml += '</object></div>';
			div.innerHTML = newInnerHtml;
			MainWnd.width = 669;
			MainWnd.height = 473;
			OnResized();
		}
		function HideTalkConnector()
		{
			var div = document.getElementById('TalkConnectorDiv');
			div.style.visibility = 'hidden';
			div.innerHTML = "";
			div.style.width = '1px';
			div.style.height = '1px';
			OnResized();
		}
	<!-- /Talk Connector -->
	<!-- PNG Transparency -->
		function FixPngTransparency()
		{
			var arVersion = navigator.appVersion.split("MSIE")
			var version = parseFloat(arVersion[1])
			if ((version >= 5.5) && (document.body.filters) && (version <= 6.5))
			{
				for(var i=0; i<document.images.length; i++)
				{
					var img = document.images[i]
					var imgName = img.src.toUpperCase()
					if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.src.indexOf('locallocator.com') != -1)
					{
						var imgID = (img.id) ? "id='" + img.id + "' " : ""
						var imgClass = (img.className) ? "class='" + img.className + "' " : ""
						var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
						var imgStyle = "display:inline-block;" + img.style.cssText 
						if (img.align == "left") imgStyle = "float:left;" + imgStyle
						if (img.align == "right") imgStyle = "float:right;" + imgStyle
						if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
						var strNewHTML = "<span " + imgID + imgClass + imgTitle
						+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
						img.outerHTML = strNewHTML
						i = i-1
					}
				}
			}
		}
	<!-- /PNG Transparency -->
