	/*
		Dependencies from WorldBrowser.aspx and WorldBrowser.js:
		
		mapDivID
		GEvent
		mapDiv
	*/		
	var addingLocation = false;
	var placedAddLocationMarker = false;
	var addLocationMarker;
	
	var listener_AddStuff_Move;
	var listener_AddStuff_Click;
	
	function addLocation()
	{
		if (map.getZoom() < 7)
		{
			alert("You'll need to zoom in a bit first!");
			return;
		}
	
		if (!addingLocation)
		{
		
			var mapDiv = document.getElementById(mapDivID);
			mapDiv.firstChild.firstChild.style.cursor = "crosshair";
		
			listener_AddStuff_Move = GEvent.bind(map, "mousemove", this, addLocation_MouseMove);
			GEvent.removeListener(mapClickListener);
			listener_AddStuff_Click = GEvent.bind(map, "click", this, addLocation_Click);
			
			addingLocation = true;
			placedAddLocationMarker	= false;
			
			var divAddStuff = document.getElementById("divAddStuff");
			divAddStuff.style.display = "block";
			divAddStuff.style.visibility = "visible";

		}
	}
	
	function closeAddLocation()
	{
		addingLocation = false;
		placedAddLocationMarker = false;
		
		var divAddStuff = document.getElementById("divAddStuff");
		divAddStuff.style.display = "none";
		divAddStuff.style.visibility = "hidden";

		var mapDiv = document.getElementById(mapDivID);
		mapDiv.firstChild.firstChild.style.cursor = "hand";

		GEvent.removeListener(listener_AddStuff_Move);
		GEvent.removeListener(listener_AddStuff_Click);

		map.removeOverlay(addLocationMarker);
		addLocationMarker = null
		
	}

	function addLocation_MouseMove(latlng)
	{
		if (placedAddLocationMarker)
		{
			return;
		}
		
		if (!addLocationMarker)
		{
			addLocationMarker = new GMarker(latlng, starMarker);
			map.addOverlay(addLocationMarker);
			//addLocationMarker.iconImage.setAttribute("title", "Click to drop me");

			GEvent.addListener(addLocationMarker, "click", function() {
				addLocation_Click(null, addLocationMarker.getPoint());
			});
		}
		addLocationMarker.setPoint(latlng);
		addLocationMarker.redraw(true); 

		//var txt = "Click the map to add a place at (" + latlng.lng() + ", " + latlng.lat() + ")";
	}

	function addLocation_Click(overlay, point)
	{
		if (point != null && !placedAddLocationMarker)
		{
			placedAddLocationMarker = true;
			document.frmAddLocation.hdNewPlaceLat.value = point.y;
			document.frmAddLocation.hdNewPlaceLon.value = point.x;
			
			var spanAddLocationLatLng = document.getElementById("spanAddLocationLatLng");
			spanAddLocationLatLng.innerHTML = "&nbsp; Cool.  (" + point.x + ", " + point.y + ")";
		}
	}

		
	function tagNewPlace(tag)
	{
		var box = document.getElementById("txtNewPlaceTags")
		
		if (box.value != "")
		{
			tag = ", " + tag;
		}
		box.value += tag;
	}

	
	function saveNewPlace()
	{
		var lat = document.getElementById("hdNewPlaceLat").value;
		var lon = document.getElementById("hdNewPlaceLon").value;
		var name = document.getElementById("txtNewPlaceName").value;
		var tags = document.getElementById("txtNewPlaceTags").value;
		
		if (name == "")
		{
			showAddStuffMessage("What should I call it?");
			document.getElementById("txtNewPlaceName").focus();
		}
		else if (lat == "")
		{
			showAddStuffMessage("Where should I put it?");
		}
		else if (tags == "")
		{
			showAddStuffMessage("What is it?");
			document.getElementById("txtNewPlaceTags").focus();
		}
		else
		{
			document.frmAddLocation.submit();
		}
	}
	
	function showAddStuffMessage(message)
	{
		var div = document.getElementById("divAddStuffMessage");
		div.innerHTML = message;
		
		div.style.visibility = "visible";
		setTimeout("hideAddStuffMessage()", 1000);
	}
	
	function hideAddStuffMessage()
	{
		document.getElementById("divAddStuffMessage").style.visibility = "hidden";
	}
	
	var throbStep = 15;
	var throbDelta = -1;
	var base16 = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f');
	function throbMapExtras()
	{
		var div = document.getElementById("divMapExtras");
		if (div)
		{
			throbStep = throbStep + throbDelta;
			var r = base16[throbStep].toString();
			div.style.backgroundColor = "#FF" + r + r +  r + r;
			
			if (throbStep < 1)
			{
				throbDelta = 1;
			}
			
			if (throbStep < 15)
			{
				setTimeout("throbMapExtras()", 30);
			}
			
		}
		
	}
	
	function AddNewStuffBox_init()
	{
		setTimeout("throbMapExtras()", 5000);
	}
	
	
	AddNewStuffBox_init();
	
	

