local compost = CompostLib:GetInstance('compost-1')
local tourist = TouristLib:GetInstance("1.0")
local tablet = TabletLib:GetInstance('1.0')
local dewdrop = DewdropLib:GetInstance('1.0')
local metro = Metrognome:GetInstance('1')
local jostle = JostleLib:GetInstance('1.0')

LocationFu = FuBarPlugin:GetInstance("1.2"):new({
	name          = LocationFuLocals.NAME,
	description   = LocationFuLocals.DESCRIPTION,
	version       = "1.1." .. string.sub("$Revision: 2027 $", 12, -3),
	releaseDate   = string.sub("$Date: 2006-05-20 16:32:03 -1000 (Sat, 20 May 2006) $", 8, 17),
	aceCompatible = 103,
	author        = "ckknight",
	email         = "ckknight@gmail.com",
	website       = "http://ckknight.wowinterface.com/",
	category      = "map",
	db            = AceDatabase:new("LocationFuDB"),
	defaults      = {
		showMapCoords = true,
		showCoords = true,
		showSubZoneName = true,
		showZoneName = false,
		showRecZones = true,
		showMapOverlay = true,
		showLevelRange = true,
	},
	cmd           = AceChatCmd:new(LocationFuLocals.COMMANDS, LocationFuLocals.CMD_OPTIONS),
	loc           = LocationFuLocals,
	hasIcon       = true,
})
function LocationFu:IsShowingCoords()
	return self.data.showCoords
end

function LocationFu:ToggleShowingCoords()
	self.data.showCoords = not self.data.showCoords
	if loud then
		self.cmd:status(self.loc.ARGUMENT_COORDS, self.data.showCoords and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	self:UpdateText()
	return self.data.showCoords
end

function LocationFu:IsShowingZoneName()
	return self.data.showZoneName
end

function LocationFu:ToggleShowingZoneName()
	self.data.showZoneName = not self.data.showZoneName
	if loud then
		self.cmd:status(self.loc.ARGUMENT_ZONENAME, self.data.showZoneName and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	self:UpdateText()
	return self.data.showZoneName
end

function LocationFu:IsShowingSubZoneName()
	return self.data.showSubZoneName
end

function LocationFu:ToggleShowingSubZoneName()
	self.data.showSubZoneName = not self.data.showSubZoneName
	if loud then
		self.cmd:status(self.loc.ARGUMENT_SUBZONENAME, self.data.showSubZoneName and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	self:UpdateText()
	return self.data.showSubZoneName
end

function LocationFu:IsShowingLevelRange()
	return self.data.showLevelRange
end

function LocationFu:ToggleShowingLevelRange()
	self.data.showLevelRange = not self.data.showLevelRange
	if loud then
		self.cmd:status(self.loc.ARGUMENT_LEVEL, self.data.showLevelRange and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	self:UpdateText()
	return self.data.showLevelRange
end

function LocationFu:IsShowingMinimapBar()
	return self.data.minimapBar
end

function LocationFu:ToggleShowingMinimapBar(loud)
	self.data.minimapBar = not self.data.minimapBar
	if loud then
		self.cmd:status(self.loc.ARGUMENT_MINIMAPBAR, self.data.minimapBar and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	if not self.data.minimapBar then
		MinimapBorderTop:Hide()
		MinimapToggleButton:Hide()
		MinimapZoneTextButton:Hide()
	else
		MinimapBorderTop:Show()
		MinimapToggleButton:Show()
		MinimapZoneTextButton:Show()
	end
	jostle:Refresh()
	return self.data.minimapBar
end

function LocationFu:IsShowingMapCoords()
	return self.data.showMapCoords
end

function LocationFu:ToggleShowingMapCoords(loud)
	self.data.showMapCoords = not self.data.showMapCoords
	if loud then
		self.cmd:status(self.loc.ARGUMENT_MAPCOORDS, self.data.showMapCoords and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	if not self.data.showMapCoords then
		LocationFuMapFrameCursorCoords:Hide()
		LocationFuMapFramePlayerCoords:Hide()
	else
		LocationFuMapFrameCursorCoords:Show()
		LocationFuMapFramePlayerCoords:Show()
	end
	return self.data.showMapCoords
end

function LocationFu:IsShowingRecommendedZones()
	return self.data.showRecZones
end

function LocationFu:ToggleShowingRecommendedZones(loud)
	self.data.showRecZones = not self.data.showRecZones
	if loud then
		self.cmd:status(self.loc.ARGUMENT.RECZONES, self.data.showRecZones and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	self:UpdateTooltip()
	return self.data.showRecZones
end

function LocationFu:IsShowingMapOverlay()
	return self.data.showMapOverlay
end

function LocationFu:ToggleShowingMapOverlay(loud)
	self.data.showMapOverlay = not self.data.showMapOverlay
	if loud then
		self.cmd:status(self.loc.ARGUMENT.MAPOVERLAY, self.data.showMapOverlay and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	if not self.data.showMapOverlay then
		LocationFuMapFrameText:Hide()
		WorldMapFrameAreaLabel:SetTextColor(1, 1, 1)
	else
		LocationFuMapFrameText:Show()
	end
	return self.data.showMapOverlay
end

function LocationFu:Initialize()
	local mapFrame = CreateFrame("Frame", "LocationFuMapFrame", WorldMapFrame)
	mapFrame:SetScript("OnUpdate", function()
		self:MapFrame_OnUpdate()
	end)
	local cursorCoords = mapFrame:CreateFontString("LocationFuMapFrameCursorCoords", "ARTWORK")
	cursorCoords:SetFont(GameFontNormal:GetFont())
	cursorCoords:SetTextColor(GameFontNormal:GetTextColor())
	cursorCoords:SetShadowColor(GameFontNormal:GetShadowColor())
	cursorCoords:SetShadowOffset(GameFontNormal:GetShadowOffset())
	cursorCoords:SetPoint("RIGHT", WorldMapFrame, "CENTER", -80, -367)
	
	local playerCoords = mapFrame:CreateFontString("LocationFuMapFramePlayerCoords", "ARTWORK")
	playerCoords:SetFont(GameFontNormal:GetFont())
	playerCoords:SetTextColor(GameFontNormal:GetTextColor())
	playerCoords:SetShadowColor(GameFontNormal:GetShadowColor())
	playerCoords:SetShadowOffset(GameFontNormal:GetShadowOffset())
	playerCoords:SetPoint("RIGHT", WorldMapFrame, "CENTER", 80, -367)
	
	local text = mapFrame:CreateFontString("LocationFuMapFrameText", "OVERLAY")
	local font, size = GameFontHighlightLarge:GetFont()
	text:SetFont(font, size, "OUTLINE")
	text:SetTextColor(GameFontHighlightLarge:GetTextColor())
	text:SetShadowColor(GameFontHighlightLarge:GetShadowColor())
	text:SetShadowOffset(GameFontHighlightLarge:GetShadowOffset())
	text:SetPoint("TOP", WorldMapFrameAreaDescription, "BOTTOM", 0, -5)
end

function LocationFu:Enable()
	self:RegisterEvent("ZONE_CHANGED", "UpdateData")
	self:RegisterEvent("ZONE_CHANGED_INDOORS", "UpdateData")
	self:RegisterEvent("ZONE_CHANGED_NEW_AREA", "OnZoneChangedNewArea")
	self:RegisterEvent("MINIMAP_ZONE_CHANGED", "UpdateData")
	self:RegisterEvent("PLAYER_ENTERING_WORLD", "UpdateData")
	if not self:IsShowingMinimapBar() then
		self.data.minimapBar = not self.data.minimapBar
		self:ToggleShowingMinimapBar()
	end
	if not self:IsShowingMapCoords() then
		self.data.showMapCoords = not self.data.showMapCoords
		self:ToggleShowingMapCoords()
	end
	metro:Register(self.name, self.UpdateDisplay, 0.1, self)
	metro:Start(self.name)
end

function LocationFu:Disable()
	if not self:IsShowingMinimapBar() then
		self:ToggleShowingMinimapBar()
		self.data.minimapBar = not self.data.minimapBar
	end
	if self:IsShowingMapCoords() then
		self:ToggleShowingMapCoords()
		self.data.showMapCoords = not self.data.showMapCoords
	end
	LocationFuMapFrameText:SetText("")
	metro:Unregister(self.name)
end

function LocationFu:Report()
	local report = compost:Acquire(
		compost:AcquireHash(
			'text', self.loc.ARGUMENT_COORDS,
			'val', self:IsShowingCoords() and 1 or 0,
			'map', FuBarLocals.MAP_ONOFF
		),
		compost:AcquireHash(
			'text', self.loc.ARGUMENT_ZONENAME,
			'val', self:IsShowingZoneName() and 1 or 0,
			'map', FuBarLocals.MAP_ONOFF
		),
		compost:AcquireHash(
			'text', self.loc.ARGUMENT_MINIMAPBAR,
			'val', self:IsShowingMinimapBar() and 1 or 0,
			'map', FuBarLocals.MAP_ONOFF
		),
		compost:AcquireHash(
			'text', self.loc.ARGUMENT_MAPCOORDS,
			'val', self:IsShowingMapCoords() and 1 or 0,
			'map', FuBarLocals.MAP_ONOFF
		),
		compost:AcquireHash(
			'text', self.loc.ARGUMENT_RECZONES,
			'val', self:IsShowingRecommendedZones() and 1 or 0,
			'map', FuBarLocals.MAP_ONOFF
		),
		compost:AcquireHash(
			'text', self.loc.ARGUMENT_MAPOVERLAY,
			'val', self:IsShowingMapOverlay() and 1 or 0,
			'map', FuBarLocals.MAP_ONOFF
		)
	)
	self.cmd:report(report)
	compost:Reclaim(report, 1)
end

function LocationFu:MenuSettings(level, value)
	if level == 1 then
		dewdrop:AddLine(
			'text', self.loc.MENU_OPEN_WORLD_MAP,
			'func', function()
				ToggleWorldMap()
				dewdrop:Close()
			end
		)
		
		if Atlas_Toggle then
			dewdrop:AddLine(
				'text', self.loc.MENU_OPEN_ATLAS,
				'func', function()
					Atlas_Toggle()
					dewdrop:Close()
				end
			)
		end
		
		dewdrop:AddLine()
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_COORDS,
			'arg1', self,
			'func', "ToggleShowingCoords",
			'checked', self:IsShowingCoords()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_SUBZONE_NAME,
			'arg1', self,
			'func', "ToggleShowingSubZoneName",
			'checked', self:IsShowingSubZoneName()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_ZONE_NAME,
			'arg1', self,
			'func', "ToggleShowingZoneName",
			'checked', self:IsShowingZoneName()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_LEVEL_RANGE,
			'arg1', self,
			'func', "ToggleShowingLevelRange",
			'checked', self:IsShowingLevelRange()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_MINIMAP_BAR,
			'arg1', self,
			'func', "ToggleShowingMinimapBar",
			'checked', self:IsShowingMinimapBar()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_COORDS_ON_MAP,
			'arg1', self,
			'func', "ToggleShowingMapCoords",
			'checked', self:IsShowingMapCoords()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_MAP_OVERLAY,
			'arg1', self,
			'func', "ToggleShowingMapOverlay",
			'checked', self:IsShowingMapOverlay()
		)
		
		dewdrop:AddLine(
			'text', self.loc.MENU_SHOW_RECOMMENDED_ZONES,
			'arg1', self,
			'func', "ToggleShowingRecommendedZones",
			'checked', self:IsShowingRecommendedZones()
		)
	end
end

function LocationFu:OnZoneChangedNewArea()
	SetMapToCurrentZone()
	self:UpdateData()
end

function LocationFu:UpdateData()
	self.subZoneText = GetSubZoneText()
	self.zoneText = GetZoneText()
	if self.subZoneText == "" then
		self.subZoneText = self.zoneText
	end
	self.zoneColor = FuBarUtils.COLOR_HEX_YELLOW
	self.pvpType,_,self.isArena = GetZonePVPInfo()
	local faction = UnitFactionGroup("player")
	if self.isArena or self.pvpType == "hostile" then
		self.zoneColor = FuBarUtils.COLOR_HEX_RED
	elseif self.pvpType == "friendly" then
		self.zoneColor = FuBarUtils.COLOR_HEX_GREEN
	elseif tourist:IsHostile(self.zoneText) then
		self.zoneColor = FuBarUtils.COLOR_HEX_RED
	elseif tourist:IsFriendly(self.zoneText) then
		self.zoneColor = FuBarUtils.COLOR_HEX_GREEN
	end
	if Atlas_Toggle and tourist:IsInstance(self.zoneText) then
		self:SetIcon("Interface\\AddOns\\Atlas\\Images\\AtlasIcon")
	else
		self:SetIcon(TRUE)
	end
end

function LocationFu:UpdateText()
	local text
	local x, y = GetPlayerMapPosition("player")
	local t = compost:Acquire()
	local r, g, b = tourist:GetFactionColor(self.zoneText)
	if self:IsShowingZoneName() and self:IsShowingSubZoneName() then
		if self.subZoneText == self.zoneText then
			table.insert(t, format("|cff%02x%02x%02x%s|r", r*255, g*255, b*255, self.zoneText))
		else
			table.insert(t, format("|cff%02x%02x%02x%s: %s|r", r*255, g*255, b*255, self.zoneText, self.subZoneText))
		end
	elseif self:IsShowingZoneName() then
		table.insert(t, format("|cff%02x%02x%02x%s|r", r*255, g*255, b*255, self.zoneText))
	elseif self:IsShowingSubZoneName() then
		table.insert(t, format("|cff%02x%02x%02x%s|r", r*255, g*255, b*255, self.subZoneText))
	end
	if self:IsShowingCoords() and x ~= 0 and y ~= 0 then
		table.insert(t, format("|cff%02x%02x%02x(%.0f, %.0f)|r", r*255, g*255, b*255, x * 100, y * 100))
	end
	local low, high = tourist:GetLevel(self.zoneText)
	if self:IsShowingLevelRange() and low > 0 and high > 0 then
		local r, g, b = tourist:GetLevelColor(self.zoneText)
		table.insert(t, format("|cff%02x%02x%02x[%d-%d]|r", r*255, g*255, b*255, low, high))
	end
	self:SetText(table.concat(t, " "))
	compost:Reclaim(t)
end

function LocationFu:UpdateTooltip()
	local cat = tablet:AddCategory(
		'columns', 2,
		'child_textR', 1,
		'child_textG', 1,
		'child_textB', 0,
		'child_text2R', 1,
		'child_text2G', 1,
		'child_text2B', 1
	)
	
	cat:AddLine(
		'text', self.loc.TEXT_ZONE .. ":",
		'text2', self.zoneText
	)
	
	if self.subZoneText ~= self.zoneText then
		cat:AddLine(
			'text', self.loc.TEXT_SUBZONE .. ":",
			'text2', self.subZoneText
		)
	end
	
	local text
	local r, g, b = 1, 1, 0
	if self.isArena then
		text = self.loc.TEXT_ARENA
		g = 0
	elseif self.zoneColor == FuBarUtils.COLOR_HEX_GREEN then
		text = self.loc.TEXT_FRIENDLY
		r = 0
	elseif self.zoneColor == FuBarUtils.COLOR_HEX_YELLOW then
		text = self.loc.TEXT_CONTESTED
	elseif self.zoneColor == FuBarUtils.COLOR_HEX_RED then
		text = self.loc.TEXT_HOSTILE
		g = 0
	end
	
	cat:AddLine(
		'text', self.loc.TEXT_STATUS .. ":",
		'text2', self.loc.TEXT_ARENA,
		'text2R', r,
		'text2G', g,
		'text2B', b
	)
	
	local x, y = GetPlayerMapPosition("player")
	cat:AddLine(
		'text', self.loc.TEXT_COORDINATES .. ":",
		'text2', format("%.0f, %.0f", x*100, y*100)
	)
	
	local low, high = tourist:GetLevel(self.zoneText)
	if low >= 1 and high >= 1 then
		local r, g, b = tourist:GetLevelColor(self.zoneText)
		cat:AddLine(
			'text', self.loc.TEXT_LEVEL_RANGE .. ":",
			'text2', format("%d-%d", low, high),
			'text2R', r,
			'text2G', g,
			'text2B', b
		)
	end
	
	if tourist:DoesZoneHaveInstances(self.zoneText) then
		cat = tablet:AddCategory(
			'columns', 2,
			'text', self.loc.TEXT_INSTANCES,
			'child_textR', 1,
			'child_textG', 1,
			'child_textB', 0
		)
		
		for instance in tourist:IterateZoneInstances(self.zoneText) do
			local low, high = tourist:GetLevel(instance)
			local r, g, b = tourist:GetLevelColor(instance)
			cat:AddLine(
				'text', instance,
				'text2', format("%d-%d", low, high),
				'text2R', r,
				'text2G', g,
				'text2B', b
			)
		end
	end
	if self:IsShowingRecommendedZones() then
		cat = tablet:AddCategory(
			'columns', 2,
			'text', self.loc.TEXT_RECOMMENDED_ZONES
		)
		
		for zone in tourist:IterateRecommendedZones() do
			local low, high = tourist:GetLevel(zone)
			local r1, g1, b1 = tourist:GetFactionColor(zone)
			local r2, g2, b2 = tourist:GetLevelColor(zone)
			cat:AddLine(
				'text', zone,
				'textR', r1,
				'textG', g1,
				'textB', b1,
				'text2', format("%d-%d", low, high),
				'text2R', r2,
				'text2G', g2,
				'text2B', b2
			)
		end
		
		if tourist:HasRecommendedInstances() then
			cat = tablet:AddCategory(
				'columns', 2,
				'text', self.loc.TEXT_RECOMMENDED_INSTANCES
			)
			
			for instance in tourist:IterateRecommendedInstances() do
				local low, high = tourist:GetLevel(instance)
				local r1, g1, b1 = tourist:GetFactionColor(instance)
				local r2, g2, b2 = tourist:GetLevelColor(instance)
				cat:AddLine(
					'text', instance,
					'textR', r1,
					'textG', g1,
					'textB', b1,
					'text2', format("%d-%d", low, high),
					'text2R', r2,
					'text2G', g2,
					'text2B', b2
				)
			end
		end
	end
	
	if Atlas_Toggle then
		if tourist:IsInstance(self.zoneText) then
			tablet:SetHint(self.loc.TEXT_HINT_ATLAS .. "\n" .. self.loc.TEXT_HINT_SHIFT .. "\n" .. self.loc.TEXT_HINT_CTRL)
		else
			tablet:SetHint(self.loc.TEXT_HINT .. "\n" .. self.loc.TEXT_HINT_SHIFT .. "\n" .. self.loc.TEXT_HINT_ATLAS_CTRL)
		end
	else
		tablet:SetHint(self.loc.TEXT_HINT .. "\n" .. self.loc.TEXT_HINT_SHIFT)
	end
end

function LocationFu:MapFrame_OnUpdate(t)
	if not self.disabled then
		if self:IsShowingMapCoords() then
			local OFFSET_X = 0.0022
			local OFFSET_Y = -0.0262
			
			local x, y = GetCursorPosition()
			x = x / WorldMapFrame:GetScale()
			y = y / WorldMapFrame:GetScale()
		
			local px, py = GetPlayerMapPosition("player")
			local centerX, centerY = WorldMapFrame:GetCenter()
			local width = WorldMapButton:GetWidth()
			local height = WorldMapButton:GetHeight()
			local adjustedX = (x - (centerX - (width/2))) / width
			local adjustedY = (centerY + (height/2) - y ) / height
			local cx = (adjustedX + OFFSET_X)
			local cy = (adjustedY + OFFSET_Y)
			
			local cursorCoordsText = format("%.0f, %.0f", 100 * cx, 100 * cy)
			local playerCoordsText = format("%.0f, %.0f", 100 * px, 100 * py);			
			LocationFuMapFrameCursorCoords:SetText(format("%s: %.0f, %.0f", self.loc.TEXT_CURSOR, 100 * cx, 100 * cy))
			LocationFuMapFramePlayerCoords:SetText(format("%s: %.0f, %.0f", self.loc.TEXT_PLAYER, 100 * px, 100 * py))
		end
		
		if self:IsShowingMapOverlay() then
			local underAttack = false
			local zone = WorldMapFrameAreaLabel:GetText()
			if zone then
				zone = string.gsub(WorldMapFrameAreaLabel:GetText(), " |cff.+$", "")
				if WorldMapFrameAreaDescription:GetText() then
					underAttack = true
					zone = string.gsub(WorldMapFrameAreaDescription:GetText(), " |cff.+$", "")
				end
			end
			if GetCurrentMapContinent() == 0 then
				local c1, c2 = GetMapContinents()
				if zone == c1 or zone == c2 then
					WorldMapFrameAreaLabel:SetTextColor(1, 1, 1)
					LocationFuMapFrameText:SetText("")
					return
				end
			end
			if not zone or not tourist:IsZoneOrInstance(zone) then
				zone = WorldMapFrame.areaName
			end
			WorldMapFrameAreaLabel:SetTextColor(1, 1, 1)
			if zone ~= nil and tourist:IsZoneOrInstance(zone) then
				if not underAttack then
					WorldMapFrameAreaLabel:SetTextColor(tourist:GetFactionColor(zone))
					WorldMapFrameAreaDescription:SetTextColor(1, 1, 1)
				else
					WorldMapFrameAreaLabel:SetTextColor(1, 1, 1)
					WorldMapFrameAreaDescription:SetTextColor(tourist:GetFactionColor(zone))
				end
				local low, high = tourist:GetLevel(zone)
				if low ~= nil and high ~= nil and low ~= -6 and high ~= -6 then
					local r, g, b = tourist:GetLevelColor(zone)
					if not underAttack then
						local text = string.gsub(WorldMapFrameAreaLabel:GetText(), " |cff.+$", "")
						text = text .. format(" |cff%02x%02x%02x(%d-%d)|r", r * 255, g * 255, b * 255, low, high)
						WorldMapFrameAreaLabel:SetText(text)
					else
						local text = string.gsub(WorldMapFrameAreaDescription:GetText(), " |cff.+$", "")
						text = text .. format(" |cff%02x%02x%02x(%d-%d)|r", r * 255, g * 255, b * 255, low, high)
						WorldMapFrameAreaDescription:SetText(text)
					end
				end
				
				if tourist:DoesZoneHaveInstances(zone) then
					if self.lastZone ~= zone then
						self.lastZone = zone
						local mapText = format("|cffffff00%s:|r", self.loc.TEXT_INSTANCES)
						for instance in tourist:IterateZoneInstances(zone) do
							local low, high = tourist:GetLevel(instance)
							local r1, g1, b1 = tourist:GetFactionColor(instance)
							local r2, g2, b2 = tourist:GetLevelColor(instance)
							mapText = mapText .. "\n" .. format("|cff%02x%02x%02x%s|r |cff%02x%02x%02x(%d-%d)|r", r1 * 255, g1 * 255, b1 * 255, instance, r2 * 255, g2 * 255, b2 * 255, low, high)
						end
						LocationFuMapFrameText:SetText(mapText)
					end
				else
					self.lastZone = nil
					LocationFuMapFrameText:SetText("")
				end
			elseif zone == nil then
				self.lastZone = nil
				LocationFuMapFrameText:SetText("")
			end
		end
	end
end

function LocationFu:OnClick()
	if IsShiftKeyDown() then
		if ChatFrameEditBox:IsVisible() then
			local x, y = GetPlayerMapPosition("player")
			local message
			local coords = format("%.0f, %.0f", x * 100, y * 100)
			if not self:IsShowingZoneName() and not self:IsShowingSubZoneName() then
				message = coords
			elseif self:IsShowingZoneName() and self:IsShowingSubZoneName() then
				if self.zoneText ~= self.subZoneText then
					message = format("%s: %s (%s)", self.zoneText, self.subZoneText, coords)
				else
					message = format("%s (%s)", self.zoneText, coords)
				end
			elseif self:IsShowingZoneName() then
				message = format("%s (%s)", self.zoneText, coords)
			elseif self:IsShowingSubZoneName() then
				message = format("%s (%s)", self.subZoneText, coords)
			end
			ChatFrameEditBox:Insert(message)
		end
	elseif Atlas_Toggle then
		if IsControlKeyDown() then
			if not tourist:IsInstance(self.zoneText) then
				Atlas_Toggle()
			else
				ToggleWorldMap()
			end
		else
			if tourist:IsInstance(self.zoneText) then
				Atlas_Toggle()
			else
				ToggleWorldMap()
			end
		end
	else
		ToggleWorldMap()
	end
end

LocationFu:RegisterForLoad()