    var map = null;
    var geocoder = null;
	
	//LOAD INITIAL MAP
	function onloadmap(location){
		if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl (new GLargeMapControl());
		map.enableDoubleClickZoom();
        geocoder = new GClientGeocoder();
		var NZlocation = location+', New Zealand';
		geocoder.getLatLng(NZlocation, function(point) {
																			map.setCenter(point, 7);});
		} else {
        alert("Sorry, Your web browser is not fully supported by this map service.\nPlease use the browsers suggested in the following page.");
		document.location.href="http://local.google.com/support/bin/answer.py?answer=16532&topic=1499";
	  }
    }


    function loadMap(pointArray) {
        var bounds = new GLatLngBounds();	
        var maxZoom = 16;	
		
		function placeMarker(lat, lng, business, address, length){ 
			var markerPoint = new GLatLng(lat,lng);
			var marker = new GMarker(markerPoint);
        	map.addOverlay(marker);
        	bounds.extend(markerPoint);
          	GEvent.addListener(marker, "click", function() {
            				marker.openInfoWindowHtml('<b>'+business+'</b><br><br>'+address);})
			if (length == 1) {
			marker.openInfoWindowHtml('<b>'+business+'</b><br><br>'+address);}
	  	}	
	  for (var i=0; i<pointArray.length; i++) {	
		 var splitDetail = pointArray[i].split(":");
		 var address = splitDetail[0];
		 var businessName = splitDetail[1];
		 var point = splitDetail[2];
		 var lat = point.split(",")[0];
		 var lng = point.split(",")[1];
		 if(lat!=0 && lng!=0){
		    	placeMarker(lat, lng, businessName, address, pointArray.length);	} 
	}
		//FIND AND SET CENTER POINT
		var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
		var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
		map.setCenter(new GLatLng(clat,clng));
		map.panTo(new GLatLng(clat,clng));
		var boundsZoom = map.getBoundsZoomLevel(bounds);
		if (boundsZoom > maxZoom) {
			map.setZoom(maxZoom);
		} else {
			map.setZoom(boundsZoom);
		}
    }
	
	function showCity(id) {
    var cityName=id+'_cityName';
        document.getElementById(id).style.display='block';
		document.getElementById(cityName).getElementsByTagName('a')[0].style.backgroundImage='URL(CSSimages/downArrow.gif)';
		document.getElementById(cityName).getElementsByTagName('a')[0].style.backgroundPosition='left 5px';}
	
	function hideCity(id) {
    var cityName=id+'_cityName';
        document.getElementById(id).style.display='none';
        document.getElementById(id).style.border='none';
		document.getElementById(cityName).getElementsByTagName('a')[0].style.backgroundImage='URL(CSSimages/rightArrow.gif)';
		document.getElementById(cityName).getElementsByTagName('a')[0].style.backgroundPosition='left 3px';}
		
	function showAdd(id) {
	var status= document.getElementById(id).style.display;
	var business=id+'p';
	var closeImg=id+'_img';
        document.getElementById(id).style.display='block';
        //document.getElementById(business).getElementsByTagName('a')[0].style.color='#BD1015';
        document.getElementById(business).style.border='1px solid #CCC';
        document.getElementById(business).style.padding='5px';
		//document.getElementById(closeImg).style.display="inline";
	}
	
	function closeDiv(id) {
	var business=id+'p';
	var closeImg=id+'_img';
		document.getElementById(closeImg).style.display="none";
        document.getElementById(id).style.display='none';
        document.getElementById(business).getElementsByTagName('a')[0].style.color='#05B';
        document.getElementById(business).style.border='none'
        document.getElementById(business).style.padding='0';
	}
	
	function showCityMap(city){	
	 var status= document.getElementById(city).style.display;
	 if (status != 'block') {
		showCity(city);
		var cityblock= document.getElementById(city);
		var DIV= cityblock.getElementsByTagName("div");
		var busNo = DIV.length;
		var businessName = "";
		var address ="";
		var point ="";
		var pointArray = new Array();
		for (var i = 0; i < busNo; i++) { 
			var classTest = DIV[i].getAttribute('title');
				if (classTest == "businessName") {
					businessName = DIV[i].getElementsByTagName("a")[0].innerHTML;
				} else if (classTest == "address") {
					address = DIV[i].getElementsByTagName("font")[0].innerHTML;
					point = DIV[i].getElementsByTagName("font")[1].innerHTML;
				}
				
				if (businessName!="" && address!="" && point!="") {
					var t=(i-1)/2;
					pointArray[t] = address+':'+businessName+':'+point;
					businessName = "";
					address ="";
					point="";}
		}
		loadMap(pointArray);
	 } else {
		hideCity(city);
	 }
	}
	function detailMap(point, address, business, id) {
		showAdd(id);
		var lat = point.split(",")[0];
		var lng = point.split(",")[1];
		map.panTo(new GLatLng(lat,lng));
		map.setCenter(new GLatLng(lat,lng), 16);
		var markerPoint = new GLatLng(lat,lng);
		var marker2 = new GMarker(markerPoint);
        map.addOverlay(marker2);
        marker2.openInfoWindowHtml("<b>"+business+"</b><br><br>"+address);
        GEvent.addListener(marker2, "click", function() {
            				marker2.openInfoWindowHtml("<b>"+business+"</b><br><br>"+address);})
		 }
	
