function ContactMap() {
 	this.points = new Array();
 	this.locations = new Array();
 	this.markerHeight = 36;
 	this.markerWidth = 23;
 	this.markerImagePrefix = null;
 	
 	ContactMap.prototype.searchComplete = function(searcher){
		if (searcher.results && searcher.results.length >0){
			var result = searcher.results[0];
			//alert(result.title + " " + result.lat + " " + result.lng);
			var point = new GLatLng(result.lat, result.lng);
			this.points[this.points.length] = point;
		}
		else {
			this.points[this.points.length] = null;
		}
		if (this.points.length == this.locations.length){
			this.drawMap();
		}
	}
	
	ContactMap.prototype.drawMap = function(){
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var mapType = map.getCurrentMapType();
					
		if (this.points[0] != null) {
			var bounds = new GLatLngBounds();
			bounds.extend(this.points[0]);
			
			var center = bounds.getCenter();
			var mapSize = map.getSize();
			size = new GSize(mapSize.width - this.markerWidth, mapSize.height - this.markerHeight);
		
			var zoom = 10;
	
			// move the center down
			map.setCenter(center, zoom);
			
			var pixelCentre = map.fromLatLngToDivPixel(center);
			pixelCentre = new GPoint(pixelCentre.x, pixelCentre.y - this.markerHeight);
			center = map.fromDivPixelToLatLng(pixelCentre);
			
			map.panTo(center);
			
			var marker = new GMarker(this.points[0]);
			marker.popupText = "<h4>Mecserve</h4><p>106A Stafford Road<br/>Wallington<br/>Surrey, SM6 9AY</p>";
			
			GEvent.addListener(marker, "click", function() {
		    marker.openInfoWindowHtml(marker.popupText);
		  });
			
	  	map.addOverlay(marker);
	    marker.openInfoWindowHtml(marker.popupText);
	  }			
	}
	
	ContactMap.prototype.show = function(){
		if (GBrowserIsCompatible()) {
			// need to use AJAX Search as maps IP does not support GeoCoding in the UK
	    var localSearch = new GlocalSearch();
			localSearch.setNoHtmlGeneration();
			localSearch.setSearchCompleteCallback(this, ContactMap.prototype.searchComplete,[localSearch]);
			for (var i=0; i< this.locations.length; i++){
				localSearch.execute(this.locations[i]);
			}
		}     
	}
}

function mapLoad(){
	var map = new ContactMap();
	map.locations = locations;
	map.show();
}