/// (function(){

////HMM HOW DO I MAKE THIS WORK CLIENT SIDE???
///	function get_bloginfo_url() {return <?php bloginfo('url'); ?>;}
//	function get_bloginfo_url() {return 'http://localhost/wassp';}
//	function get_bloginfo_url() {return 'http://voilawebsolutions.com/wassp';}
	function get_bloginfo_url() {return 'http://wassp.net';}

    //<![CDATA[

//	google.load("search","1");
//	google.load("maps","2");

	var	VENUE={CLUB:0,SPORTS_CENTRE:1,SCHOOL:2,VOLUNTEERING_OPPORTUNITY:3,OTHER:4,UNDEFINED:5};
	var	venues=['club','sports centre','school','volunteering opportunities','other','undefined'];
	var venueShowFlags=[true,true,true,true,true,true];
	var	venueListTitles=['clubs','sports-centres','schools','volunteering-opportunities','other-venues','other-venues'];
	var	venueMouseOverColours=['#00d','#d00','#b94','#090','#c62','#777'];
	var	mapVenuesLists=[];

	var MAP_AREA={CENTRE:0,NORTH:1,EAST:2,SOUTH:3,WEST:4,NONE:5};
	var	mapAreaNames=['centre','north','east','south','west',''];
	var	mapAreaLongNames=['Central Warrington','Warrington North','Warrington East','Warrington South','Warrington West',''];
	var	mapAreaZoomOffsets=[2,2,2,1,1];
	var polygonStrokeWeight=2;
	var polygonStrokeColours=['#444444','#444444','#444444','#444444','#444444'];
	var polygonStrokeOpacity=1.0;
	var polygonStrokeColourActive='#000000';
	var polygonColours=['#ffff00','#00ffff','#ff0000','#00ff00','#ff00ff'];
	var polygonOpacity=0.2;
	var polygonOpacityActive=0.4;
	var polygonStrokeWeightActive=4;
	var polygonStrokeOpacityActive=1;

	var	map;
	var	markers=[];
	var	markerIcons=[];
	var	currentActivePolygon=null;
	var	currentActiveMapArea=MAP_AREA.NONE;
	var mapZoomedOutCentre;
	var	mapZoomedOutLevel;

	function map_pageLoad()
	{
		// This is now set directly in the HTML as there's a delay if done here?
//		document.getElementById('mapAreaTitle').innerHTML='Loading Sports Activity Finder Map...';
//		document.getElementById('mapAreaTitle').style.color='#d00';
		google.load("maps","2",{callback:mapLoad});
	}

	// The Google API will call this function when the page has been loaded
	function mapLoad()
	{
		if (!google.maps.BrowserIsCompatible())
			return;	// Nowt doing!

		document.getElementById('resetMap').style.display='inline';

		mapVenuesLists[VENUE.CLUB]=document.getElementById('map-clubs-list');
		mapVenuesLists[VENUE.SPORTS_CENTRE]=document.getElementById('map-sports-centres-list');
		mapVenuesLists[VENUE.SCHOOL]=document.getElementById('map-schools-list');
		mapVenuesLists[VENUE.VOLUNTEERING_OPPORTUNITY]=document.getElementById('map-volunteering-opportunities-list');
		mapVenuesLists[VENUE.OTHER]=document.getElementById('map-other-venues-list');
		mapVenuesLists[VENUE.UNDEFINED]=document.getElementById('map-other-venues-list');

		// Create a search control
/*		var searchControl=new google.search.SearchControl();

		// Add in a full set of searchers
		var localSearch=new google.search.LocalSearch();
		searchControl.addSearcher(localSearch);

		searchControl.addSearcher(new google.search.WebSearch());
		searchControl.addSearcher(new google.search.VideoSearch());
		searchControl.addSearcher(new google.search.BlogSearch());

		// Set the Local Search center point
		localSearch.setCenterPoint("New York, NY");

		// Tell the searcher to draw itself and tell it where to attach
		searchControl.draw(document.getElementById("searchControl"));

		// Execute an inital search
		searchControl.execute("Google");
*/
		// Create a map control
		map=new google.maps.Map2(document.getElementById("map"));
//		mapZoomedOutCentre=new google.maps.LatLng(51.45,0);			// Greenwich prime meridian
		mapZoomedOutCentre=new google.maps.LatLng(53.392,-2.585);	// Central Warrington
		mapZoomedOutLevel=11;
//		map.setCenter(mapZoomedOutCentre,mapZoomedOutLevel);	
		map.addControl(new GSmallMapControl());
//		map.addControl(new GLargeMapControl());
//		map.setUIToDefault();
//		map.addControl(new GMapTypeControl());
		map.addControl(new GMenuMapTypeControl());
//		map.addControl(new GHierarchicalMapTypeControl());
//		map.addControl(new GOverviewMapControl());
//		map.addControl(new GNavLabelControl());
//		map.enableGoogleBar();
//		map.enableScrollWheelZoom();
		map.enableContinuousZoom();
//		map.disableDragging()

		resetMap();

// ground overlay
/*var lat2=centre.lat()+0.01;
var lng2=centre.lng()+0.0265;
var latOffset2=0.08;
var lngOffset2=0.14;
var boundaries = new GLatLngBounds(new GLatLng(lat2-latOffset2,lng2-lngOffset2), new GLatLng(lat2+latOffset2,lng2+lngOffset2));
//var oldmap = new GGroundOverlay("http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg", boundaries);
var oldmap = new GGroundOverlay(get_bloginfo_url()+"/vws-map/alcohol designated zones.png", boundaries);
var oldmap = new GGroundOverlay(get_bloginfo_url()+"/vws-map/My Merged Neighbourhood Boundaries.png", boundaries);
map.addOverlay(oldmap);
*/

//// Do it this way for now, should eventually use (base64?) encoded string contructor...
		var polygonCentre=new google.maps.Polygon([
			new GLatLng(53.423445,-2.582817),
			new GLatLng(53.427537,-2.555007),
			new GLatLng(53.423241,-2.554664),
			new GLatLng(53.420581,-2.561531),
			new GLatLng(53.415670,-2.563934),
			new GLatLng(53.413317,-2.568397),
			new GLatLng(53.407894,-2.567710),
			new GLatLng(53.404415,-2.571659),
			new GLatLng(53.400116,-2.561187),
			new GLatLng(53.391928,-2.560501),
			new GLatLng(53.388857,-2.564277),
			new GLatLng(53.389983,-2.573032),
			new GLatLng(53.385273,-2.575435),
			new GLatLng(53.386399,-2.590026),
			new GLatLng(53.391518,-2.583847),
			new GLatLng(53.397660,-2.591400),
			new GLatLng(53.407689,-2.592086),
			new GLatLng(53.416080,-2.596893),
			new GLatLng(53.422218,-2.619552),
			new GLatLng(53.423445,-2.582817)
			],polygonStrokeColours[MAP_AREA.CENTRE],polygonStrokeWeight,polygonStrokeOpacity,polygonColours[MAP_AREA.CENTRE],polygonOpacity);
		map.addOverlay(polygonCentre);

		var polygonNorth=new google.maps.Polygon([
			new GLatLng(53.440423,-2.581443),
			new GLatLng(53.448397,-2.571487),
			new GLatLng(53.458619,-2.565994),
			new GLatLng(53.462299,-2.545394),
			new GLatLng(53.467817,-2.548828),
			new GLatLng(53.481508,-2.493209),
			new GLatLng(53.476604,-2.483253),
			new GLatLng(53.465569,-2.487030),
			new GLatLng(53.448602,-2.471237),
			new GLatLng(53.444512,-2.473640),
			new GLatLng(53.437355,-2.464370),
			new GLatLng(53.434287,-2.471237),
			new GLatLng(53.437355,-2.478103),
			new GLatLng(53.434696,-2.526855),
			new GLatLng(53.427537,-2.555007),
			new GLatLng(53.440423,-2.581443)
			],polygonStrokeColours[MAP_AREA.NORTH],polygonStrokeWeight,polygonStrokeOpacity,polygonColours[MAP_AREA.NORTH],polygonOpacity);
		map.addOverlay(polygonNorth);

		var polygonEast=new google.maps.Polygon([
			new GLatLng(53.437355,-2.478103),
			new GLatLng(53.434287,-2.471237),
			new GLatLng(53.437355,-2.464370),
			new GLatLng(53.437355,-2.457504),
			new GLatLng(53.423855,-2.444114),
			new GLatLng(53.419354,-2.447204),
			new GLatLng(53.416284,-2.444458),
			new GLatLng(53.398888,-2.465744),
			new GLatLng(53.396636,-2.474327),
			new GLatLng(53.384147,-2.532691),
			new GLatLng(53.385990,-2.541275),
			new GLatLng(53.390904,-2.547798),
			new GLatLng(53.389266,-2.553291),
			new GLatLng(53.391928,-2.560501),
			new GLatLng(53.400116,-2.561187),
			new GLatLng(53.404415,-2.571659),
			new GLatLng(53.407894,-2.567710),
			new GLatLng(53.413317,-2.568397),
			new GLatLng(53.415670,-2.563934),
			new GLatLng(53.420581,-2.561531),
			new GLatLng(53.423241,-2.554664),
			new GLatLng(53.427537,-2.555007),
			new GLatLng(53.427537,-2.555007),
			new GLatLng(53.434696,-2.526855),
			new GLatLng(53.437355,-2.478103)
			],polygonStrokeColours[MAP_AREA.EAST],polygonStrokeWeight,polygonStrokeOpacity,polygonColours[MAP_AREA.EAST],polygonOpacity);
		map.addOverlay(polygonEast);

		var polygonSouth=new google.maps.Polygon([
			new GLatLng(53.391928,-2.560501),
			new GLatLng(53.389266,-2.553291),
			new GLatLng(53.390904,-2.547798),
			new GLatLng(53.385990,-2.541275),
			new GLatLng(53.384147,-2.532691),
			new GLatLng(53.396636,-2.474327),
			new GLatLng(53.392951,-2.467803),
			new GLatLng(53.395817,-2.461624),
			new GLatLng(53.396022,-2.447891),
			new GLatLng(53.387628,-2.420082),
			new GLatLng(53.375546,-2.423515),
			new GLatLng(53.367557,-2.434158),
			new GLatLng(53.366123,-2.443084),
			new GLatLng(53.368991,-2.454414),
			new GLatLng(53.365099,-2.456130),
			new GLatLng(53.364074,-2.461967),
			new GLatLng(53.367762,-2.482566),
			new GLatLng(53.348092,-2.517242),
			new GLatLng(53.343173,-2.515525),
			new GLatLng(53.336818,-2.535781),
			new GLatLng(53.330667,-2.542304),
			new GLatLng(53.332923,-2.548828),
			new GLatLng(53.323491,-2.559127),
			new GLatLng(53.330052,-2.584190),
			new GLatLng(53.322670,-2.593460),
			new GLatLng(53.332103,-2.618522),
			new GLatLng(53.343377,-2.604103),
			new GLatLng(53.347477,-2.609252),
			new GLatLng(53.346862,-2.630195),
			new GLatLng(53.359157,-2.625045),
			new GLatLng(53.364791,-2.628993),
			new GLatLng(53.367864,-2.611141),
			new GLatLng(53.375341,-2.603588),
			new GLatLng(53.374624,-2.597923),
			new GLatLng(53.386399,-2.590026),
			new GLatLng(53.385273,-2.575435),
			new GLatLng(53.389983,-2.573032),
			new GLatLng(53.388857,-2.564277),
			new GLatLng(53.391928,-2.560501),
			],polygonStrokeColours[MAP_AREA.SOUTH],polygonStrokeWeight,polygonStrokeOpacity,polygonColours[MAP_AREA.SOUTH],polygonOpacity);
		map.addOverlay(polygonSouth);

		var polygonWest=new google.maps.Polygon([
			new GLatLng(53.454531,-2.675857),
			new GLatLng(53.447580,-2.649078),
			new GLatLng(53.444921,-2.633972),
			new GLatLng(53.436128,-2.626419),
			new GLatLng(53.443899,-2.609596),
			new GLatLng(53.443490,-2.594146),
			new GLatLng(53.451055,-2.593803),
			new GLatLng(53.440423,-2.581443),
			new GLatLng(53.427537,-2.555007),
			new GLatLng(53.423445,-2.582817),
			new GLatLng(53.422218,-2.619552),
			new GLatLng(53.416080,-2.596893),
			new GLatLng(53.407689,-2.592086),
			new GLatLng(53.397660,-2.591400),
			new GLatLng(53.391518,-2.583847),
			new GLatLng(53.386399,-2.590026),
			new GLatLng(53.374624,-2.597923),
			new GLatLng(53.375341,-2.603588),
			new GLatLng(53.367864,-2.611141),
			new GLatLng(53.364791,-2.628993),
			new GLatLng(53.362128,-2.644615),
			new GLatLng(53.355264,-2.673454),
			new GLatLng(53.360387,-2.693023),
			new GLatLng(53.370015,-2.697486),
			new GLatLng(53.385171,-2.696456),
			new GLatLng(53.389471,-2.675857),
			new GLatLng(53.402163,-2.671051),
			new GLatLng(53.422832,-2.671394),
			new GLatLng(53.430810,-2.661437),
			new GLatLng(53.436128,-2.673110),
			new GLatLng(53.443490,-2.666244),
			new GLatLng(53.439809,-2.682037),
			new GLatLng(53.454531,-2.675857)
			],polygonStrokeColours[MAP_AREA.WEST],polygonStrokeWeight,polygonStrokeOpacity,polygonColours[MAP_AREA.WEST],polygonOpacity);
		map.addOverlay(polygonWest);

/*		var lat=53.4	//centre.getLat();
		var lng=-2.4;	//centre.getLng();
		var latOffset=0.01;
		var lngOffset=0.01;
		var polygon=new google.maps.Polygon([
			new GLatLng(lat,lng-lngOffset),
			new GLatLng(lat+latOffset,lng),
			new GLatLng(lat,lng+lngOffset),
			new GLatLng(lat-latOffset,lng),
			new GLatLng(lat,lng-lngOffset)
			],"#f33f00",5,1,"#ff0000",0.2);
		map.addOverlay(polygon);
		polygon.enableEditing();
*/
		google.maps.Event.addListener(polygonCentre,"click",function(latLng)
		{
			if (currentActiveMapArea!=MAP_AREA.CENTRE)
				setActiveMapArea(polygonCentre,MAP_AREA.CENTRE,true);
		});

		google.maps.Event.addListener(polygonNorth,"click",function(latLng)
		{
			if (currentActiveMapArea!=MAP_AREA.NORTH)
				setActiveMapArea(polygonNorth,MAP_AREA.NORTH,true);
		});

		google.maps.Event.addListener(polygonEast,"click",function(latLng)
		{
			if (currentActiveMapArea!=MAP_AREA.EAST)
				setActiveMapArea(polygonEast,MAP_AREA.EAST,true);
		});

		google.maps.Event.addListener(polygonSouth,"click",function(latLng)
		{
			if (currentActiveMapArea!=MAP_AREA.SOUTH)
				setActiveMapArea(polygonSouth,MAP_AREA.SOUTH,true);
		});

		google.maps.Event.addListener(polygonWest,"click",function(latLng)
		{
			if (currentActiveMapArea!=MAP_AREA.WEST)
				setActiveMapArea(polygonWest,MAP_AREA.WEST,true);
		});

/*		google.maps.Event.addListener(map,"click",function(overlay,latLng,overlayLatLng)
		{
			if (overlay)
			{
				if (overlay==polygonSouth)
				{
					alert("You clicked the polygon. lat="+overlayLatLng.lat()+" lng="+overlayLatLng.lng());
				}
				else
				{
					alert("You clicked on something? lat="+overlayLatLng.lat()+" lng="+overlayLatLng.lng());
				}
			}
			else
			{
				alert("You clicked the map. lat="+latLng.lat()+" lng="+latLng.lng());
			}
		});
*/
	}

	// See: "Creating a Store Locator with PHP, MySQL & Google Maps" in Google Maps API: Google Code Home > Google Maps API FAQ > Articles & Tutorials
/*	function searchLocations()
	{
		var address = document.getElementById('addressInput').value;
		geocoder.getLatLng(address, function(latlng)
		{
			if (!latlng)
				alert(address+' not found');
			else
				searchLocationsNear(latlng);
		});
	}
*/
	function resetMap()
	{
		map.setCenter(mapZoomedOutCentre,mapZoomedOutLevel);
		if (currentActiveMapArea!=MAP_AREA.NONE)
		{
			setActiveMapArea(null,MAP_AREA.NONE,true);
			document.getElementById('mapSearch').value='';
		}
		else
			setActiveMapArea(null,MAP_AREA.NONE,false);
	}

	function setActiveMapArea(polygon,mapArea,active)
	{
		// Clear current map markers instantly before (possible) asynchronous request for server to send new ones
		clearVenueLists();

		for (var i=0; i<markers.length; i++)
			map.removeOverlay(markers[i]);
		markers=[];

		if (active)
		{
			if (currentActivePolygon)
				setActiveMapArea(currentActivePolygon,currentActiveMapArea,false);
			if (polygon)
			{
				polygon.setFillStyle({color:polygonColours[mapArea],opacity:polygonOpacityActive});
				polygon.setStrokeStyle({color:polygonStrokeColourActive,opacity:polygonStrokeOpacityActive,weight:polygonStrokeWeightActive});
				currentActivePolygon=polygon;
				currentActiveMapArea=mapArea;

//				document.getElementById('mapAreaTitle').style.display='none';
				document.getElementById('mapAreaTitle').innerHTML='Retrieving venues for '+mapAreaLongNames[mapArea]+'...';
				document.getElementById('mapAreaTitle').style.color='orange';

				getMapAreaVenues(mapAreaNames[mapArea]);	// Asynchronous request for map area data

				map.setCenter(polygon.getBounds().getCenter(),mapZoomedOutLevel+mapAreaZoomOffsets[mapArea]);
			}
		}
		else
		{
			if (polygon)
			{
				polygon.setFillStyle({color:polygonColours[mapArea],opacity:polygonOpacity});
				polygon.setStrokeStyle({color:polygonStrokeColours[mapArea],opacity:polygonStrokeOpacity,weight:polygonStrokeWeight});
			}
			currentActivePolygon=null;
			currentActiveMapArea=MAP_AREA.NONE;
//			document.getElementById('mapAreaTitle').style.display='inline';
			document.getElementById('mapAreaTitle').innerHTML='Click on an area of Warrington to view its sporting venues';
			document.getElementById('mapAreaTitle').style.color='white';
		}
	}

	function getMapAreaVenues(searchAreas)
	{
//		var		areas=['centre','north','east','south','west'];
//		var		searchAreas='';
//		for (var i=0; i<areas.length; ++i)
//			if (document.getElementById('map-area-'+areas[i]).checked)
//				searchAreas+=areas[i]+',';	// Note: Trailing comma for last item will get ignored

		// DO NOT use an absolute URL here as it won't work on servers
		// XmlHttpRequest AJAX calls must have same address as HTML document they are called from
		// therefore an absolute URL is redundant, however absolute (or relative) paths are fine
//		var 	searchUrl='/wassp/vws-map/gen-kml.php?areas='+searchAreas;

		// Hmm not sure if the above is the case now?!? My brain hurts.
		var 	searchUrl=get_bloginfo_url()+'/vws-map/gen-kml.php?areas='+searchAreas;

		// To load pre-generated KML file (must be on a Google accessible host server [not localhost] to work!)
/*		var kmlUrl="http://voilawebsolutions.com/gen-kml.php?lat=51.45&lng=0&radius=0&v=" + Math.round(Math.random() * 10000000000);
		var kml=new GGeoXml(kmlUrl); 
		map.clearOverlays();
		map.addOverlay(kml);
*/
		// Fetch document asynchronously (here a php script document is being fetched that will be preprocessed server-side into an XML doc)
//		GDownloadUrl('/wassp/test.kml',function(data)	// Use to asynchronously download KML (XML format) file directly
		GDownloadUrl(searchUrl,function(data)
		{
			var xml=GXml.parse(data);

			if (xml.documentElement==null)
			{
				document.getElementById('mapAreaTitle').innerHTML='Error retrieving venue map markers from server!';
				document.getElementById('mapAreaTitle').style.color='#c00';
//				alert(data);
				return;
			}

			var placemarkElements=xml.documentElement.getElementsByTagName('Placemark');

//			alert("Found "+placemarkElements.length+" placemarkElements");

//			for (var i=0; i<mapVenuesLists.length; ++i)
//				mapVenuesLists[i].innerHTML='';

			if (placemarkElements.length==0)
			{
//				mapSidebar.innerHTML='No results found.';
//				map.setCenter(new GLatLng(40,-100),4);
				return;
			}

////TODO: READ STYLES FROM KML <STYLE> ELEMENTS...
			// Create custom marker icons
			if (markerIcons.length==0)
			{
				markerIcons[VENUE.CLUB]=createCustomIcon('blue_MarkerC','mm_20_shadow');
				markerIcons[VENUE.SPORTS_CENTRE]=createCustomIcon('red_MarkerL','mm_20_shadow');
				markerIcons[VENUE.SCHOOL]=createCustomIcon('yellow_MarkerS','mm_20_shadow');
				markerIcons[VENUE.VOLUNTEERING_OPPORTUNITY]=createCustomIcon('green_MarkerV','mm_20_shadow');
				markerIcons[VENUE.OTHER]=createCustomIcon('orange_MarkerO','mm_20_shadow');
				markerIcons[VENUE.UNDEFINED]=createCustomIcon('purple_MarkerU','mm_20_shadow');
			}

			// Create map markers
			var bounds=new GLatLngBounds();

			for (var i=0; i<placemarkElements.length; i++)
			{
				// Get placemark attributes
				var id=placemarkElements[i].getAttribute('id');

				// Get placemark elements (note that even though an array is read for each, only one should present and gets used)
				var	name=GXml.value(placemarkElements[i].getElementsByTagName("name")[0]);
				var	desc=GXml.value(placemarkElements[i].getElementsByTagName("description")[0]);
//				var	styleUrl=GXml.value(placemarkElements[i].getElementsByTagName("styleUrl")[0]);
				var	pointElements=placemarkElements[i].getElementsByTagName("Point");
				var	coords=GXml.value(pointElements[0].getElementsByTagName("coordinates")[0]);
				var	cats=GXml.value(placemarkElements[i].getElementsByTagName("Categories")[0]);
				var	tags=GXml.value(placemarkElements[i].getElementsByTagName("Tags")[0]);
				var	postId=GXml.value(placemarkElements[i].getElementsByTagName("PostId")[0]);
				var	postName=GXml.value(placemarkElements[i].getElementsByTagName("PostName")[0]);

				var	lngLat=coords.split(",");	// Break string up into its numeric components
				var	lng=parseFloat(lngLat[0]);
				var	lat=parseFloat(lngLat[1]);
				var	point=new GLatLng(lat,lng);

//				var	style=styleUrl.substr(1,styleUrl.length-6);	// Omit initial # character and 'Style' at the end
//				var	icon=markerIcons[style];
				var	marker=createMarker(point,name,desc,cats,tags,postName);

				marker.sidebarEntry=createMapSidebarEntry(marker,name,desc);
//				mapVenuesLists[marker.venue].appendChild(marker.sidebarEntry);	// Now done in applyMapFilters()

				map.addOverlay(marker);
				markers.push(marker);

				bounds.extend(point);
			}

//			map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds));

			applyMapFilters();

			document.getElementById('mapAreaTitle').innerHTML='Click on a venue map marker for more details';
			document.getElementById('mapAreaTitle').style.color='white';
		});
	}

	function onVenueListTitleClicked(venue)
	{
		venueShowFlags[venue]=!venueShowFlags[venue];
		var	mapVenueListTitle=document.getElementById('map-venue-'+venueListTitles[venue]);
		mapVenueListTitle.style.backgroundImage='url('+get_bloginfo_url()+'/wp-content/themes/hybrid-news/images/circle-arrow-'+(venueShowFlags[venue] ? 'down' : 'right')+'.gif)';
		applyMapFilters();
	}

	function applyMapFilters()
	{
//		var	showClubs=document.getElementById('map-venue-clubs').checked;
//		var	showSportsCentres=document.getElementById('map-venue-sports-centres').checked;
//		var	showSchools=document.getElementById('map-venue-schools').checked;
//		var	showVolunteeringOpportunities=document.getElementById('map-venue-volunteering-opportunities').checked;
//		var	showOtherVenues=document.getElementById('map-venue-other-venues').checked;

		var	searchString=document.getElementById('mapSearch').value;
		searchString=searchString.toLowerCase();	// Convert search text to lowercase

		clearVenueLists();

		var	mapVenuesListsLengths=[];
		for (var i=0; i<venues.length; ++i)
			mapVenuesListsLengths[i]=0;

		for (var i=0; i<markers.length; ++i)
		{
			var	cats=markers[i].categories;
			var	show=venueShowFlags[markers[i].venue];

			if (show && searchString!='')
			{
				// Search all tags to see if searchString is contained within any of them
				var	tags=','+markers[i].tags;	// Put delimiter at start so can check for ',<searchString>' to ensure always matches from beginning of tags (not within)
				show=(tags.indexOf(','+searchString)!=-1);
			}

			if (show)
			{
				markers[i].show();
				mapVenuesLists[markers[i].venue].appendChild(markers[i].sidebarEntry);
				var	numVenueMarkers=++mapVenuesListsLengths[markers[i].venue];
				markers[i].sidebarEntry.className=(numVenueMarkers==1 ? 'first' : '') + ((numVenueMarkers & 1)==0 ? 'odd' : '');
			}
			else
				markers[i].hide();
		}
	}

	function clearVenueLists()
	{
		// Delete all venues from list
		for (var i=0; i<markers.length; ++i)
		{
			if (markers[i].sidebarEntry.parentNode)	// Need to check for valid parentNodes for the entries otherwise doesn't work for non-IE browsers???
				markers[i].sidebarEntry.parentNode.removeChild(markers[i].sidebarEntry);
		}
	}

	function createMarker(point,name,desc,cats,tags,postName)
	{
//		alert("Placemark name="+name+" desc="+desc+" point="+point.lat()+","+point.lng());

		var	venue=VENUE.UNDEFINED;
		for (var i=0; i<venues.length; ++i)
			if (cats.indexOf(venues[i])!=-1)
				{venue=i; break;}

//		var	marker=new GMarker(point,icon);	// Don't use passed in 'styleUrl' icon for now as the server PHP script doesn't properly set this up
		var	venueIcon=markerIcons[venue];
		var	marker=new GMarker(point,venueIcon);

		marker.venue=venue;
		marker.categories=cats;
		marker.tags=tags;
//alert("TO DO: USE MAPINFOTAB / CONTENT/ TITLE HERE...");
		var	labels=[];
//		labels.push('<span style="color: #f00;"><strong>'+name+'</strong></span>');
		labels.push(''+name+'');
//		labels.push("Label 2");
		var	htmls=[];
		htmls.push(
			'<div style="text-align: left; width: 300px;">' +
				'<div style="font: 18px Verdana; text-align: center; margin-bottom: 8px; color: ' + venueMouseOverColours[venue] + ';">' + name + '</div>' +
				'<div style="font: 12px/22px Verdana; margin-bottom: 8px; color: black;">' +
					(desc!='' ? desc : 'Short description to go here!') +
				'</div>' +
				'<div style="position: absolute; top: -37px; left: -42px;">' +
					'<img src="'+get_bloginfo_url()+'/vws-map/images/wasp.gif"/>' +
				'</div>' +
				'<div style="float: right; text-align: right; font: 12px Verdana;">' +
					'<a href="'+get_bloginfo_url()+'/'+postName+'">Click for more details...</a><br/>' +
				'</div>' +
			'</div>');
//		htmls.push('<span style="color: #0ff;">content 2</span>');
//		htmls.push('content 2');

		GEvent.addListener(marker,'click',function()
		{
//			marker.openInfoWindowHtml(html);

			// Adjust width so that info window is large enough for this many tabs
//			if (htmls.length > 2)
//				htmls[0]='<div style="width:'+htmls.length*88+'px">' + htmls[0] + '<\/div>';

			var infoWindowTabs=[];
			for (var i=0; i<htmls.length; i++)
				infoWindowTabs.push(new GInfoWindowTab(labels[i],htmls[i]));

			marker.openInfoWindowTabsHtml(infoWindowTabs);
//			map.openInfoWindowTabsHtml(point,infoWindowTabs);
		});

		return marker;
	}

	function createCustomIcon(image,shadow)
	{
		var	icon=new GIcon();
		icon.image=get_bloginfo_url()+'/vws-map/images/markers/'+image+'.png';
		icon.shadow=get_bloginfo_url()+'/vws-map/images/markers/'+shadow+'.png';
//		icon.iconSize=new GSize(12,20);
//		icon.shadowSize=new GSize(22,20);
//		icon.iconAnchor=new GPoint(6,20);
//		icon.infoWindowAnchor=new GPoint(5,1);
		icon.iconSize=new GSize(12+6,20+10);
		icon.shadowSize=new GSize(22+11,20+10);
		icon.iconAnchor=new GPoint(6,20);
		icon.infoWindowAnchor=new GPoint(5,1);
		return icon;
	}

	function createMapSidebarEntry(marker,name,desc)
	{
///		var	li=document.createElement('li');	//// Grrr can't get rid of arrow 'bullet' markers???
		var	li=document.createElement('div');
		var	venueIconUrl=markerIcons[marker.venue].image;
//		li.innerHTML='<img src="'+venueIconUrl+'" style="color: #111; width: 12px; height: 18px; position: relative; top: 6px;" alt=""/> '+name;
		li.innerHTML='<img src="'+venueIconUrl+'" style="padding: 0px 8px 0px 16px; color: #111; width: 12px; height: 18px; margin-top: 2px;" alt=""/><span style="position: relative; top: -4px;">'+name+'</span>';
//li.innerHTML='<img src="'+venueIconUrl+'" style="padding: 0px 8px 0px 16px; color: #111; width: 12px; height: 18px; margin-top: 2px;" alt=""/>' +
//	'<span style="width: 180px; background-color: green; float: right; position: relative; top: -4px;">'+name+'</span>';
//li.innerHTML='<img src="'+venueIconUrl+'" style="float: left; padding: 0px 8px 0px 16px; color: #111; width: 12px; height: 18px; margin-top: 2px;" alt=""/>' +
//	'<span style="width: 180px; background-color: green; float: right; position: relative; top: 4px;">'+name+'</span>' +
//'<div style="clear: left;"></div>';
//li.style='clear: left';
		li.style.listStyleType='none';
		li.style.marginLeft='0px';
		li.style.paddingLeft='0px';
		li.style.cursor='pointer';

		GEvent.addDomListener(li,'click',function() {GEvent.trigger(marker,'click');});
		GEvent.addDomListener(li,'mouseover',function() {li.style.color=venueMouseOverColours[marker.venue];});
		GEvent.addDomListener(li,'mouseout',function() {li.style.color='#111';});
		return li;
	}

// HS From Google Maps API docs: Using this function [GUnload] has virtually eliminated Internet Explorer memory leaks in Google Maps, though you should test for memory leaks on your own site using tools like Drip if you are noticing memory consumption problems
	function map_pageUnload()
	{
		google.maps.Unload();
	}

//	google.setOnLoadCallback(OnLoad);
    //]]>

/// ;})();
