

	var map = null;
	var center = null;
	var commentMarker = false;
	var eventMarker = false;
	
	var minLat = null;
	var maxLat = null;
	var minLng = null;
	var maxLng = null;
	var avLat = null;
	var avLng = null;

	var photoIcon = null;
	var commentIcon = null;
	var newMarkerIcon = null;
	var mouseOverPolygon;

	var $rateForm;

	var debug = '';

	var markers = new Array();
	var locations = new Array();
	var locationPoints = new Array();
	locations['mouseover'] == '';

	var om1;
	var om2;
	var om3;
	var om4;

function pfmMap() {

	// vars


	// methods
	// init
	
		// new map
//		OverlayMessage.SetBackgroundColor('#317300');
    om1 = new OverlayMessage(document.getElementById('map'));
    om1.visibleStyle = 'color: white; position: relative; top: -400px; left: 0; height: 24px; background: transparent url(/wp-content/themes/placesforme/images/curve-top-left.png) no-repeat; width: 24px; text-align: center; margin-left: 0; margin-right: auto; margin-top: 0; margin-bottom: auto; border: none; z-index: 99;';
		om1.Set('');
//    om2 = new OverlayMessage(document.getElementById('map'));
//   om2.visibleStyle = 'color: white; position: relative; top: -400px; left: 0; height: 24px; background: transparent url(/wp-content/themes/placesforme/images/curve-top-right.png) no-repeat; width: 24px; text-align: center; margin-left: auto; margin-right: 0; border: none; z-index: 99;';
//		om2.Set('');
    om3 = new OverlayMessage(document.getElementById('map'));
    om3.visibleStyle = 'color: white; position: relative; top: -24px; left: 0; height: 24px; background: transparent url(/wp-content/themes/placesforme/images/curve-bottom-left.png) no-repeat; width: 24px; text-align: center; margin-left: 0; margin-right: auto; margin-top: 0; margin-bottom: auto; border: none; z-index: 99;';
		om3.Set('');
//    om4 = new OverlayMessage(document.getElementById('map'));
//    om4.visibleStyle = 'color: white; position: relative; top: -24px; left: 0; height: 24px; background: transparent url(/wp-content/themes/placesforme/images/curve-bottom-right.png) no-repeat; width: 24px; text-align: center; margin-left: auto; margin-right: 0; border: none; z-index: 99;';
//		om4.Set('');
		
		map = new google.maps.Map2(document.getElementById("map"), {mapTypes:[G_NORMAL_MAP]});
		center = new GLatLng(-31.952499, 115.859059);
		map.setCenter(center, 12);
		//map.enableContinuousZoom();
		
		// add tile overlay
		var tilelayer = new GTileLayer();
		tilelayer.getTileUrl = function() { return "/wp-content/images/white.png"; };
		tilelayer.isPng = function() { return true;};
		tilelayer.getOpacity = function() { return 0.5; }
		var myTileLayer = new GTileLayerOverlay(tilelayer);
		map.addOverlay(myTileLayer);
	
		// recenters map on browser resize
		if (window.attachEvent) { window.attachEvent("onresize", function() { map.setCenter(center); } ); } else { window.addEventListener("resize", function() { map.setCenter(center); }, false); }
		
		// resets center on dragend
		GEvent.addListener(map, "moveend", function() { center = map.getCenter(); });
	
		// map controls
		map.addControl(new GLargeMapControl());

		photoIcon = new GIcon(G_DEFAULT_ICON);
		commentIcon = new GIcon(G_DEFAULT_ICON);
		eventBlueIcon = new GIcon(G_DEFAULT_ICON);
		eventRedIcon = new GIcon(G_DEFAULT_ICON);
		eventPinkIcon = new GIcon(G_DEFAULT_ICON);
		eventGreenIcon = new GIcon(G_DEFAULT_ICON);
		eventYellowIcon = new GIcon(G_DEFAULT_ICON);
		eventOrangeIcon = new GIcon(G_DEFAULT_ICON);
		newMarkerIcon = new GIcon(G_DEFAULT_ICON);
		newEventIcon = new GIcon(G_DEFAULT_ICON);
		asteriskBlueIcon = new GIcon(G_DEFAULT_ICON);
		crossRedIcon = new GIcon(G_DEFAULT_ICON);
		dotYellowIcon = new GIcon(G_DEFAULT_ICON);
		dotDarkGreenIcon = new GIcon(G_DEFAULT_ICON);
		dotOrangeIcon = new GIcon(G_DEFAULT_ICON);
		dotPinkIcon = new GIcon(G_DEFAULT_ICON);
		
		
		// add markers
		photoIcon.image = "/wp-content/images/icon-red-dot.png";
		photoIcon.shadow = "";
		photoIcon.iconSize = new GSize(16, 16);
		photoIcon.iconAnchor = new GPoint(8, 16);
		photoIcon.infoWindowAnchor = new GPoint(8, 0);
		
		commentIcon.image = "/wp-content/images/icon-red-dot.png";
		commentIcon.shadow = "";
		commentIcon.iconSize = new GSize(16, 16);
		commentIcon.iconAnchor = new GPoint(8, 16);
		commentIcon.infoWindowAnchor = new GPoint(8, 0);

		eventBlueIcon.image = "/wp-content/images/icon-flag_blue.png";
		eventBlueIcon.shadow = "";
		eventBlueIcon.iconSize = new GSize(16, 16);
		eventBlueIcon.iconAnchor = new GPoint(8, 16);
		eventBlueIcon.infoWindowAnchor = new GPoint(8, 0);

		eventYellowIcon.image = "/wp-content/images/icon-flag_yellow.png";
		eventYellowIcon.shadow = "";
		eventYellowIcon.iconSize = new GSize(16, 16);
		eventYellowIcon.iconAnchor = new GPoint(8, 16);
		eventYellowIcon.infoWindowAnchor = new GPoint(8, 0);

		eventOrangeIcon.image = "/wp-content/images/icon-flag_orange.png";
		eventOrangeIcon.shadow = "";
		eventOrangeIcon.iconSize = new GSize(16, 16);
		eventOrangeIcon.iconAnchor = new GPoint(8, 16);
		eventOrangeIcon.infoWindowAnchor = new GPoint(8, 0);

		eventRedIcon.image = "/wp-content/images/icon-flag_red.png";
		eventRedIcon.shadow = "";
		eventRedIcon.iconSize = new GSize(16, 16);
		eventRedIcon.iconAnchor = new GPoint(8, 16);
		eventRedIcon.infoWindowAnchor = new GPoint(8, 0);

		eventPinkIcon.image = "/wp-content/images/icon-flag_pink.png";
		eventPinkIcon.shadow = "";
		eventPinkIcon.iconSize = new GSize(16, 16);
		eventPinkIcon.iconAnchor = new GPoint(8, 16);
		eventPinkIcon.infoWindowAnchor = new GPoint(8, 0);

		eventGreenIcon.image = "/wp-content/images/icon-flag_green.png";
		eventGreenIcon.shadow = "";
		eventGreenIcon.iconSize = new GSize(16, 16);
		eventGreenIcon.iconAnchor = new GPoint(8, 16);
		eventGreenIcon.infoWindowAnchor = new GPoint(8, 0);

		newMarkerIcon.image = "/wp-content/images/icon-lightbulb.png";
		newMarkerIcon.shadow = "";
		newMarkerIcon.iconSize = new GSize(20, 20);
		newMarkerIcon.iconAnchor = new GPoint(10, 20);
		newMarkerIcon.infoWindowAnchor = new GPoint(10, 0);

		newEventIcon.image = "/wp-content/images/icon-flag_red.png";
		newEventIcon.shadow = "";
		newEventIcon.iconSize = new GSize(16, 16);
		newEventIcon.iconAnchor = new GPoint(8, 16);
		newEventIcon.infoWindowAnchor = new GPoint(8, 0);

		asteriskBlueIcon.image = "/wp-content/images/icon-blue-asterisk.png";
		asteriskBlueIcon.shadow = "";
		asteriskBlueIcon.iconSize = new GSize(16, 16);
		asteriskBlueIcon.iconAnchor = new GPoint(8, 16);
		asteriskBlueIcon.infoWindowAnchor = new GPoint(8, 0);

		crossRedIcon.image = "/wp-content/images/icon-red-star.png";
		crossRedIcon.shadow = "";
		crossRedIcon.iconSize = new GSize(16, 16);
		crossRedIcon.iconAnchor = new GPoint(8, 16);
		crossRedIcon.infoWindowAnchor = new GPoint(8, 0);

		dotYellowIcon.image = "/wp-content/images/icon-yellow-dot.png";
		dotYellowIcon.shadow = "";
		dotYellowIcon.iconSize = new GSize(16, 16);
		dotYellowIcon.iconAnchor = new GPoint(8, 16);
		dotYellowIcon.infoWindowAnchor = new GPoint(8, 0);

		dotDarkGreenIcon.image = "/wp-content/images/icon-dark-green-dot.png";
		dotDarkGreenIcon.shadow = "";
		dotDarkGreenIcon.iconSize = new GSize(16, 16);
		dotDarkGreenIcon.iconAnchor = new GPoint(8, 16);
		dotDarkGreenIcon.infoWindowAnchor = new GPoint(8, 0);

		dotOrangeIcon.image = "/wp-content/images/icon-orange-dot.png";
		dotOrangeIcon.shadow = "";
		dotOrangeIcon.iconSize = new GSize(16, 16);
		dotOrangeIcon.iconAnchor = new GPoint(8, 16);
		dotOrangeIcon.infoWindowAnchor = new GPoint(8, 0);

		dotPinkIcon.image = "/wp-content/images/icon-pink-dot.png";
		dotPinkIcon.shadow = "";
		dotPinkIcon.iconSize = new GSize(16, 16);
		dotPinkIcon.iconAnchor = new GPoint(8, 16);
		dotPinkIcon.infoWindowAnchor = new GPoint(8, 0);

	}

  
	// adds a location (polygon)
  addLocation = function(id, title, link, ptString, clickable, editable) {
  	var pts = new Array();
  	var mnLat; var mxLat; var mnLng; var mxLng; var aLat; var aLng;
		var ptArray = new Array();
		ptArray = ptString.split("|");
		while (ptArray.length > 0) {
			var tPt = ptArray.shift();
			var pt = tPt.split(",");
			if (pts.length > 0) {
				if (pt[1] < mnLat) { mnLat = pt[1]; }
				if (pt[1] > mxLat) { mxLat = pt[1]; }
				if (pt[0] < mnLng) { mnLng = pt[0]; }
				if (pt[0] > mxLng) { mxLng = pt[0]; }
			} else {
				mnLat = mxLat = pt[1];
				mnLng = mxLng = pt[0];
			}
			aLat = (Number(mnLat) + Number(mxLat)) / 2;
			aLng = (Number(mnLng) + Number(mxLng)) / 2;
			pts.push(new GLatLng(pt[1], pt[0]));
		}

		if (locations.length > 0) {
			if (mnLat < minLat) { minLat = mnLat; }
			if (mxLat > maxLat) { maxLat = mxLat; }
			if (mnLng < minLng) { minLng = mnLng; }
			if (mxLat > maxLat) { maxLat = mxLat; }
		} else {
			minLat = mnLat; maxLat = mxLat; minLng = mnLng; maxLng = mxLng;
		}
		
		if (id == 'mouseover') {
	  	var location = new GPolygon(pts,"#0099ff",1,0,"#0099ff",0.6);
		} else {
  		var location = new GPolygon(pts,"#0099ff",1,0.8,"#0099ff",0);
		}
  	if (clickable) {
			
			GEvent.addListener(location, "mouseover", function() { 
	  		if (!locations['mouseover']) { addLocation('mouseover', '', link, ptString, false); }
		  });
	  	GEvent.addListener(location, "mouseout", function() {
	  		if (locations['mouseover']) {
	  			map.removeOverlay(locations['mouseover']);
	  			delete locations['mouseover'];
	  		}
	  	});
	  	//GEvent.addListener(location, "click", function() { window.location = link; });
  	}

  	if (title == '') {
	  	GEvent.addListener(location, "click", function() { window.location = link; });
  	}
		if (editable) {
			location.enableEditing();
	  	GEvent.addListener(location, "lineupdated", function() {
				var ptsg = '';
				for (var i=0; i < location.getVertexCount(); i++) {
					tgll = location.getVertex(i);
					ptsg += '|' + tgll.lng() + ',' + tgll.lat();
				}
				submitPolygonChange(id, ptsg.substring(1));
	  	});
		}
  
  	map.addOverlay(location);
 		locations[id] = location;
 		locationPoints[id] = pts;  
  }
  
  // hilights location polygon
  showHilite = function(id) {
  	if (locationPoints[id] != null) {
	  	var loca = new GPolygon(locationPoints[id],"#0099ff",1,0,"#0099ff",0.6);
 		 	map.addOverlay(loca);
 			locations['mouseover'] = loca;
  	}
  }
  // hides hilite
  hideHilite = function(id) {
  	if (locations['mouseover'] != null) {
			map.removeOverlay(locations['mouseover']);
			delete locations['mouseover'];
  	}
  }
  
  // adds a marker
  addMarker = function(id, lat, lng, type, info) {
  	if (type== 'photo') {
  		var markerIcon = photoIcon;
  	} else if (type == 'event-red') {
  		var markerIcon = eventRedIcon;
  	} else if (type == 'event-blue') {
  		var markerIcon = eventBlueIcon;
  	} else if (type == 'event-green') {
  		var markerIcon = eventGreenIcon;
  	} else if (type == 'event-orange') {
  		var markerIcon = eventOrangeIcon;
  	} else if (type == 'event-purple') {
  		var markerIcon = eventPurpleIcon;
  	} else if (type == 'event-pink') {
  		var markerIcon = eventPinkIcon;
  	} else if (type == 'event-yellow') {
  		var markerIcon = eventYellowIcon;
  	} else if (type == 'claremont-blue') {
  		var markerIcon = asteriskBlueIcon;
  	} else if (type == 'claremont-red') {
  		var markerIcon = crossRedIcon;
  	} else if (type == 'claremont-yellow') {
  		var markerIcon = dotOrangeIcon;
  	} else if (type == 'claremont-green') {
  		var markerIcon = dotDarkGreenIcon;
  	} else if (type == 'claremont-pink') {
  		var markerIcon = dotPinkIcon;
  	} else {
  		var markerIcon = commentIcon;
  	}
  	var marker = new GMarker(new GLatLng(lat, lng), { icon: markerIcon });
  	if (info != '') {
  		var el = document.getElementById(info);
	  	GEvent.addListener(marker, "click", function() { marker.openInfoWindow(el.innerHTML); });
	  }
  	map.addOverlay(marker);
  	markers[id] = marker;
  }
  
  // centers map and optimises zoom level
	showBestMap = function(z) {
		var z = (z == null) ? 0 : z;
		avLat = (Number(minLat)+Number(maxLat)) / 2;
		avLng = (Number(minLng)+Number(maxLng)) / 2;
		center = new GLatLng(avLat, avLng);
		map.setCenter(center);
		if (z > 0) {
			map.setZoom(z);
		} else {
			map.setZoom(map.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(maxLat, minLng), new GLatLng(minLat, maxLng))));
		}
	}

	// adds a draggable marker and form for leaving a comment
	addComment = function(id) {
	
		if (!commentMarker) {

			var rateFormEl = document.getElementById('map-right-inner');
			rateForm = rateFormEl.innerHTML;
			
			map.closeInfoWindow();
			var marker = new GMarker(center, {draggable: true, icon: newMarkerIcon});
			GEvent.addListener(marker, "drag", function() {
				map.closeInfoWindow();
      });
			GEvent.addListener(marker, "dragend", function() {
				var mar = marker.getLatLng();
				document.newCommentForm.newCommentLat.value = mar.lat();
				document.newCommentForm.newCommentLon.value = mar.lng();
			 	marker.openInfoWindow('<div class="commentBalloon"><h1>thanks!</h1><p>now then... what\'s your idea?</p><p class="sml">fill in the details on the right</p></div>');
      });
		 	
		 	map.addOverlay(marker);
		 	marker.openInfoWindow('<div class="commentBalloon"><h1>hi there!</h1><p>so firstly...</p><p>where does your idea go?</p><p class="sml">drag bulb to place your idea</p></div>');

		 	getCommentForm(id);
			
			var comm = document.getElementById('addCommentLink');
			comm.innerHTML = '<span><img src="/wp-content/images/icon-rate.png" /> you can also rate this place... click here</span>';
			comm.onclick = function() { getRateThisPlaceForm(); };
		
			markers['comment'] = marker;
			commentMarker = true;

	  } else {
	  	marker.setLatLng(marker.getLatLng());
	  }
	}

	addIdeaComment = function() {
	
		getIdeaCommentForm();
		var comm = document.getElementById('addCommentLink');
		comm.style.display = 'none';
	
	}

	// adds a draggable marker and form for leaving a comment
	addEvent = function() {
	
		if (!eventMarker) {

			map.closeInfoWindow();
			var marker = new GMarker(center, {draggable: true, icon: newEventIcon});
			GEvent.addListener(marker, "drag", function() {
				map.closeInfoWindow();
      });
			GEvent.addListener(marker, "dragend", function() {
				var mar = marker.getLatLng();
				document.newEventForm.newEventLat.value = mar.lat();
				document.newEventForm.newEventLon.value = mar.lng();
			 	marker.openInfoWindow('<div class="commentBalloon" style="width:250px"><h1>great!</h1><p>now... what\'s your event all about?</p><p>fill in the details on the right</p></div>');
      });
		 	
		 	map.addOverlay(marker);
		 	marker.openInfoWindow('<div class="commentBalloon" style="width:250px"><h1>a new event!</h1><p>where will your event be?</p></div>');

		 	getEventForm();
			
			var comm = document.getElementById('addEventLink');
			comm.style.display = "none";
		 	  
	  } else {
	  	marker.setLatLng(marker.getLatLng());
	  }
	}

	
	//
	showMarker = function(id, info) {
		var m = markers[id];
		var el = document.getElementById("markerHTML"+id);
		m.openInfoWindow(el.innerHTML);
		self.scrollTo(0, 90);
	}
				
	function showLocation(id) {
		var l = locations[id];
//		l.openInfoWindow();
	}
	
	printIdea = function(url) {
	//	printWindow = window.open(url, "myWindow"); 
	//	printWindow.print();
	//	printWindow.close();
	}
	
	emailIdea = function(url) {
		
	}


