var map;
var baseIcon;
var bounds;
var mapCenter;
var directions;
var directionsPanel;
function HoverItem(hitem, on)
{

	if (on)
	{
		hitem.style.backgroundColor='#EEEEEE';
	}
	else
	{
		hitem.style.backgroundColor='';
	}
}

function HoverMarker(listitem, on)
{

	if (on)
	{
		document.getElementById(listitem).style.backgroundColor='#EEEEEE';
	}
	else
	{
		document.getElementById(listitem).style.backgroundColor='';
	}
}

function bestFitWithCenter(map, bounds, mapCenter)
{
	var minLatlng, maxLatlng;
	var swLL = bounds.getSouthWest();
    var neLL = bounds.getNorthEast();
    var marginRatio = 0.0001;
    var minLat = Math.min(2*mapCenter.lat() - neLL.lat(), swLL.lat());                
    var maxLat = Math.max(2*mapCenter.lat() - swLL.lat(),  neLL.lat());        
    var minLng = Math.min(2*mapCenter.lng() - neLL.lng(), swLL.lng());               
    var maxLng = Math.max(2*mapCenter.lng() - swLL.lng(), neLL.lng());
  	var minLatLng = new GLatLng(minLat-marginRatio, minLng-marginRatio);
  	var maxLatLng = new GLatLng(maxLat+marginRatio, maxLng+marginRatio);
   	bounds.extend(maxLatLng);
   	bounds.extend(minLatLng);      
     
   	map.setZoom(map.getBoundsZoomLevel(bounds));
    map.setCenter(mapCenter);    
}
	
function loadmap(mapCenter,mapName) {
      
  if (GBrowserIsCompatible())
  {
   	baseIcon = new GIcon();
	baseIcon.image = "/images/map/marker.png";
	baseIcon.shadow = "/images/map/shadow.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(10, 34);
	baseIcon.infoWindowAnchor = new GPoint(5, 1);
	map = new GMap2(document.getElementById(mapName));
	map.setCenter(mapCenter, 13);
	map.setUIToDefault();
	bounds = new GLatLngBounds();
  }
}
				

function setPoint(map,mid,callLat,callLng,busname,busurl)
{
	var point = new GLatLng(callLat,callLng);
  	var numberedIcon = new GIcon(baseIcon);
	numberedIcon.image = "/images/map/marker"+mid+".png";
	markerOptions = { icon:numberedIcon };
	var marker = new GMarker(point, markerOptions);
	map.addOverlay(marker);
	GEvent.addListener(marker, 'mouseover', function() {
				HoverMarker('list'+mid,true);
			});
	GEvent.addListener(marker, 'mouseout', function() {
				HoverMarker('list'+mid,false);
	});
	GEvent.addListener(marker, 'click', function() {
				location.href=busurl;
	});
	bounds.extend(marker.getPoint());
}

