
    //<![CDATA[
	
	var map;
	var singlePoint;
	var searchlocation = '';
	var icon = new GIcon();
    var markerArray = new Array();
    var myCluster;
	icon.image = "/images/google/property_sml.gif";
	icon.iconSize = new GSize(16, 18);
	icon.iconAnchor = new GPoint(13, 35);
	icon.infoWindowAnchor = new GPoint(10, 10); 
	 
	var iconBig = new GIcon();
	iconBig.image = "/images/google/property.gif";
	iconBig.iconSize = new GSize(33, 33);
	iconBig.iconAnchor = new GPoint(13, 35);
	iconBig.infoWindowAnchor = new GPoint(40, 35); 
	
	var iconOffice = new GIcon();
	iconOffice.image = "/images/google/home.gif";
	iconOffice.iconSize = new GSize(33, 33);
	iconOffice.iconAnchor = new GPoint(16, 29);
	iconOffice.infoWindowAnchor = new GPoint(15, 15); 
	
	var iconCluster = new GIcon();
	iconCluster.image = "/images_mapping/property_cluster.gif";
	iconCluster.iconSize = new GSize(18, 20);
	iconCluster.iconAnchor = new GPoint(16, 29);
	iconCluster.infoWindowAnchor = new GPoint(15, 15); 
	
    function getPointFromPostcode(postcode, callbackFunction) {
		localSearch.setSearchCompleteCallback(null, 
			function() {
				if (localSearch.results[0]) {    
					var resultLat = localSearch.results[0].lat;
					var resultLng = localSearch.results[0].lng;
					var point = new GLatLng(resultLat,resultLng);
					callbackFunction(point);
				}else{
					var point = new GLatLng(0,0);
					callbackFunction(point);
				}
			});  
		localSearch.execute(postcode + ", UK");
	}
   function loadGoogle() {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById(mapdiv));
			map.addControl(new GSmallMapControl());
			if(searchlocation != ''){
				getPointFromPostcode(searchlocation + ' cambs', setStartCoords);
			} else {
				startMapping();
			}
		}
		function setStartCoords(point) {
			centerX = point.x;
			centerY = point.y;
			startMapping();
		}
		function startMapping(){
			//loadMarkers()
			map.setCenter(new GLatLng(centerY, centerX), zoomLevel);
     		setMarkers();
     		
			myCluster = new ClusterMarker(map, { markers:markerArray , clusterMarkerTitle:'Click to see more Cheffins Properties' , clusterMarkerClick:myClusterClick, clusterMarkerIcon:iconCluster, intersectPadding:-6});
			myCluster.fitMapToMarkers();
			map.setCenter(new GLatLng(centerY, centerX), zoomLevel);
		}
     	function myClusterClick(args) {
     		var rnd=(Math.floor(Math.random()*10000)) + '_'
			myCluster.defaultClickAction=function(){
				if(map.getZoom() < 16) {
					map.setCenter(args.clusterMarker.getLatLng(), map.getZoom()+1)
				} else {
					alert('no further zoom allowed');
				}
				delete myCluster.defaultClickAction;
			}
			var html='<div class="clusterholder"><b class="hdr">'+args.clusteredMarkers.length+' Properties</b> &nbsp;&nbsp;<a href="javascript:void(0)" onclick="myCluster.defaultClickAction()">Zoom</a> in to show<br />';
			
			if(args.clusteredMarkers.length > 10) {
			
			} else {
				html+='<ul class="tab">';
				for(var x = 0; x <= args.clusteredMarkers.length-1; x++) {
					var classname='';
					if (x==0) {
						classname='on';
					}
					html+='<li><a href="#" class="'+classname+'" id="a'+rnd+x+'" onclick="SwitchMarkerView(\''+rnd+'\',\''+x+'\');return false;">'+(x+1)+'</a></li>';
				}
				html+='</ul><br class="clr" />';	
				for(var x = 0; x <= args.clusteredMarkers.length-1; x++) {
					var strID = rnd+''+(x);
					var classname='';
					if (x==0) {
						classname='markerholderOn';
					} else {
						classname='markerholder';
					}
					html+='<div id="'+strID+'" class="'+classname+'">'+args.clusteredMarkers[x].getTitle()+'</div>';
				}
			}
			html+='<br class="clr" /></div><br class="clr" /><br class="clr" />';
			args.clusterMarker.openInfoWindowHtml(html);
		}

		function setCenterToPoint(point){
			map.setCenter(point, zoomLevel);
		}
	
		function setMarkers(){
			if (pointArray.length >= 0) {
				for(var x = 0; x <= pointArray.length-1; x++) {
					//set the view over the marker if there is only 1
					var bool = (pointArray.length-1 == 0);
					pushMarkerArray(pointArray[x], bool, pointArrayText[x], pointArrayLink[x], pointArrayType[x]);
				}
			}
		}
	
		function pushMarkerArray(point, center, text, link, type) {
			if(point.x != 0 || point.y != 0) {
				var marker;
				title = 'Click to view Cheffins Property details';
				if (type == "1") {
					marker = new GMarker(point, {title:title, icon:iconBig});
				} else if (type == "2") {
					marker = new GMarker(point, {title:title, icon:iconOffice});
				} else {
					marker = new GMarker(point, {title:title, icon:icon});
				}
				
				if (text == '' && link == '') {
					// do nothing for now
				} else if (text == '') {
					GEvent.addListener(marker, "click", function() {window.location=link;});
				} else {
					GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("" + text + "");});
				}
				if (center) {
					centerX = point.x;
					centerY = point.y;
				}
				markerArray.push(marker);
			}
		}
    
		//Below two functions are used to place the markers directly onto the map
		//will place all markers onto the map
		function loadMarkers(){
			if (pointArray.length >= 0) {
				for(var x = 0; x <= pointArray.length-1; x++) {
					var bool = (pointArray.length-1 == 0);
					placeMarkerAtPoint(pointArray[x], bool, pointArrayText[x], pointArrayLink[x], pointArrayType[x])
				}
			}
		}
	  
		function placeMarkerAtPoint(point, center, text, link, type) {
			if(point.x != 0 || point.y != 0) {
				var marker;
				if (type == "1") {
					marker = new GMarker(point, iconBig);
				} else if (type == "2") {
					marker = new GMarker(point, iconOffice);
				} else {
					marker = new GMarker(point, icon);
				}
				
				if (text == '' && link == '') {
					// do nothing for now
				} else if (text == '') {
					GEvent.addListener(marker, "click", function() {window.location=link;});
				} else {
					GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("" + text + "");});
				}
				if (center) {setCenterToPoint(point);}
     			map.addOverlay(marker);
			}
		}
	}
	
	function SwitchMarkerView(prefix,ref) {
		for(var x = 0; x <= 100; x++) {
			if(document.getElementById(prefix+x)){
				document.getElementById(prefix+x).style.display = 'none';
			}
			if(document.getElementById('a'+prefix+x)){
				document.getElementById('a'+prefix+x).className = '';
			}
		}
		if(document.getElementById(prefix+ref)){
			document.getElementById(prefix+ref).style.display = 'block';
		}
		if(document.getElementById('a'+prefix+ref)){
			document.getElementById('a'+prefix+ref).className = 'on';
		}
	}

    //]]>