//	Google maps display routines
//	Written by G.R. Computers and Electronics
GRCMap =
{
myWidthRatio:1,
myHeightRatio:0.5,

zoomTimer:null,
zoomDelay:1000,

currentCenter:null,
mapObj:null,
mapIcon:null,
DisplayElm:null,

stopZoom:0,

getFrameWidth:function()
{
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
	}
	else return;
	return(frameWidth)
},
getFrameHeight:function()
{
	frameHeight=500;	//	default
	if (self.innerHeight)
	{
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameHeight = document.body.clientHeight;
	}
	return(frameHeight);
},
zoomInMap:function()
{
	with (GRCMap)
	{
		clearTimeout(zoomTimer);
		GRCMap.mapObj.zoomIn();
		if (GRCMap.mapObj.getZoom() < GRCMap.stopZoom)
		{
			GRCMap.zoomTimer=setTimeout("GRCMap.zoomInMap()",zoomDelay);
		}
	}
},
resizeMap:function(elementName)
{
	with (GRCMap)
	{
		mapDiv = document.getElementById(elementName);
		if (mapDiv)
		{
//			mapDiv.style.width  = Math.round(getFrameWidth() * GRCMap.myWidthRatio) + 'px';
			mapDiv.style.height = Math.round(getFrameHeight() * GRCMap.myHeightRatio) + 'px';
		}
		if (DisplayElm!=null)
		{
			dispElm = document.getElementById(DisplayElm);
			if (dispElm)
			{
				center = mapObj.getCenter();
				if (center)
				{
					dispElm.innerHTML=center.toString();
				}
			}
		}
	}	// end with
},
addInfo:function(latitude, longtitude, infoString)
{
	// Define icon for Google map
	if (!GRCMap.mapIcon)
	{
		GRCMap.mapIcon= new GIcon();
		GRCMap.mapIcon.image  = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		// GRCMap.mapIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		GRCMap.mapIcon.iconSize = new GSize(12, 20);
		GRCMap.mapIcon.shadowSize = new GSize(22, 20);
		GRCMap.mapIcon.iconAnchor = new GPoint(6, 20);
		GRCMap.mapIcon.infoWindowAnchor = new GPoint(5, 1);
	}
	// Set Marker preperties
	var marker = new GMarker(new GLatLng(latitude, longtitude), GRCMap.mapIcon);
	GEvent.addListener(marker, "click", function()
	{ 
		marker.openInfoWindowHtml(infoString);
	});
	GRCMap.mapObj.addOverlay(marker);
//	return marker;
},
displayMap:function(elementName, latitude, longtitude,
					zoomLevelStart, zoomLevelEnd, zoomLevelDelay,
					infoString,coordElm)
{
	if (GBrowserIsCompatible())
	{
		GRCMap.stopZoom = zoomLevelEnd;
		GRCMap.zoomDelay = zoomLevelDelay;
		GRCMap.resizeMap(elementName);
		GRCMap.DisplayElm=coordElm;
		// Set map properties
		with (GRCMap)
		{
			mapObj = new GMap2(document.getElementById(elementName));
			mapObj.addControl(new GLargeMapControl());
			mapObj.addControl(new GMapTypeControl());
			mapObj.setCenter(new GLatLng(latitude, longtitude), zoomLevelStart);
		// Set map type
		// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		// !!!!!!!!!!   must be set AFTER setting map center   !!!!!!
		// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		// Default types are:	G_NORMAL_MAP
		//						G_SATELLITE_MAP
		//						G_HYBRID_MAP
			mapObj.setMapType(G_HYBRID_MAP);
			addInfo(latitude, longtitude,infoString);		
			if (zoomLevelStart < zoomLevelEnd)
			{
				zoomTimer=setTimeout("GRCMap.zoomInMap()",zoomDelay);
			}
		}	//	End of with
	}
},
setRatio:function(widthRatio, heightRatio)
{
	GRCMap.myWidthRatio=widthRatio;
	GRCMap.myHeightRatio=heightRatio;
},
init:function()
{
}
}
DOMhelp.addEvent(window,'load',GRCMap.init,false);
DOMhelp.addEvent(window,'unload',GUnload,false);
DOMhelp.addEvent(window,'resize',function(){GRCMap.resizeMap('GRCMapDiv');},false);

