var map;
var mapDirectionsPanel;
var mapDirections;
var officeIcon;
var serviceIcon;
var counter = 0;
var currentMarkerOverlay;

function mapLoad() {

	if (GBrowserIsCompatible()) {

		mapDiv = $("map");
		map = new GMap2(mapDiv);
		map.addControl(new GSmallMapControl());
		map.enableScrollWheelZoom();

		initialize();
	}
}

function initialize() {
		// Icons
		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(27, 41);
		baseIcon.shadowSize = new GSize(45, 44);
		baseIcon.iconAnchor = new GPoint(14, 41);

		officeIcon = new GIcon(baseIcon);
		officeIcon.image = "/images/map-office-icon.png";
		officeIcon.shadow = "/images/map-office-shadow.png";

		serviceIcon = new GIcon(baseIcon);
		serviceIcon.image = "/images/map-service-icon.png";
		serviceIcon.shadow = "/images/map-office-shadow.png";

		GEvent.addDomListener(mapDiv, "DOMMouseScroll", wheelevent);
		mapDiv.onmousewheel = wheelevent;

		if (currentMarker && currentType) createNewMarker(currentMarker, currentType, 13);

		$('map').down().next().setStyle({
			width: '200px',
			whiteSpace: 'normal'
		});
}

function createNewMarker(latLng, markerType, zoomLevel) {
	if (markerType == "main") icon = officeIcon;
	if (markerType == "service") icon = serviceIcon;
	if (currentMarkerOverlay) map.removeOverlay(currentMarkerOverlay);
	if (zoomLevel) map.setCenter(latLng,zoomLevel);
	else map.panTo(latLng);
	currentMarkerOverlay = new GMarker(latLng,icon);
	map.addOverlay(currentMarkerOverlay);
}

//----- Stop page scrolling if wheel over map ----
function wheelevent(e) {
		if (!e) e = window.event;
		if (e.preventDefault) e.preventDefault();
		e.returnValue = false;
}
