for i = 1, 4 do
	_G["WorldMapParty"..i.."Icon"]:SetTexture("Interface\\AddOns\\Sisterhelpers\\Textures\\Normal")
end

function WorldMapUnit_Update(self)
	local icon = self.icon
	local id = self:GetID()
	local unit, subgroup, fileName

	if GetNumRaidMembers() > 0 then
		unit = "raid"..id
		_, _, subgroup, _, _, fileName = GetRaidRosterInfo(id)
		icon:SetTexture("Interface\\AddOns\\Sisterhelpers\\Textures\\".."Group"..subgroup)
	else
		unit = "party"..id
		_, fileName = UnitClass(unit)
	end

	local color = RAID_CLASS_COLORS[fileName]
	if unit and UnitAffectingCombat(unit) then
		icon:SetVertexColor(0.8, 0, 0) 					-- flash red
	elseif unit and UnitIsDeadOrGhost(unit) then
		icon:SetVertexColor(0.2, 0.2, 0.2) 				-- flash gray
	elseif unit and PlayerIsPVPInactive(unit) then
		icon:SetVertexColor(0.5, 0.2, 0) 				-- flash some color
	elseif unit and color then
		icon:SetVertexColor(color.r, color.g, color.b)
	else
		icon:SetVertexColor(0.8, 0.8, 0.8)
	end
end


local function colorCode(eclass)
	local colorRGB = RAID_CLASS_COLORS[eclass]
	if colorRGB then
		return format("|CFF%2x%2x%2x", colorRGB.r*255, colorRGB.g*255, colorRGB.b*255)
	else
		return NORMAL_FONT_COLOR_CODE
	end
end

function WorldMapUnit_OnEnter(self, motion)
	-- Adjust the tooltip based on which side the unit button is on
	local x, y = self:GetCenter()
	local parentX, parentY = self:GetParent():GetCenter()
	if ( x > parentX ) then
		WorldMapTooltip:SetOwner(self, "ANCHOR_LEFT")
	else
		WorldMapTooltip:SetOwner(self, "ANCHOR_RIGHT")
	end

	-- See which POI's are in the same region and include their names in the tooltip
	local unitButton
	local newLineString = ""
	local tooltipText = ""
	local name, subgroup, class, fileName, nameText, server

	-- Check player
	if ( MouseIsOver(WorldMapPlayer) ) then
		name = UnitName(WorldMapPlayer.unit)
		if ( PlayerIsPVPInactive(WorldMapPlayer.unit) ) then
			tooltipText = format(PLAYER_IS_PVP_AFK, name)
		else
			_, fileName = UnitClass(WorldMapPlayer.unit)
			tooltipText = "---> "..colorCode(fileName)..name.."|r".." <---"
		end
		newLineString = "\n"
	end
	-- Check party
	for i=1, MAX_PARTY_MEMBERS do
		unitButton = _G["WorldMapParty"..i]
		if ( unitButton:IsVisible() and MouseIsOver(unitButton) ) then
			name = UnitName(unitButton.unit)
			if ( PlayerIsPVPInactive(unitButton.unit) ) then
				tooltipText = tooltipText..newLineString..format(PLAYER_IS_PVP_AFK, name)
			else
				class, fileName = UnitClass(unitButton.unit)
				tooltipText = tooltipText..newLineString..class.." "..colorCode(fileName)..name.."|r"
			end
			newLineString = "\n"
		end
	end
	-- Check Raid
	for i=1, MAX_RAID_MEMBERS do
		unitButton = _G["WorldMapRaid"..i]
		if ( unitButton:IsVisible() and MouseIsOver(unitButton) ) then
			if ( unitButton.name ) then
				-- Handle players not in your raid or party, but on your team
				if ( PlayerIsPVPInactive(unitButton.name) ) then
					tooltipText = tooltipText..newLineString..format(PLAYER_IS_PVP_AFK, unitButton.name)
				else
					tooltipText = tooltipText..newLineString..unitButton.name
				end
			else
				if ( PlayerIsPVPInactive(unitButton.unit) ) then
					tooltipText = tooltipText..newLineString..format(PLAYER_IS_PVP_AFK, UnitName(unitButton.unit))
				else
					nameText, _, subgroup, _, class, fileName = GetRaidRosterInfo(i)
					_, _, name, server = string.find(nameText, "([^%-]+)%-(.+)")
					if name and server then
						name = colorCode(fileName)..name.."|r".."|CFFFFFFFF-|r|CFFFFD200"..server.."|r"
					else
						name = colorCode(fileName)..nameText.."|r"
					end
					tooltipText = tooltipText..newLineString..subgroup.."파티: "..class.." "..name
				end
			end
			newLineString = "\n"
		end
	end
	-- Check Vehicles
	local numVehicles = GetNumBattlefieldVehicles()
	for _, v in pairs(MAP_VEHICLES) do
		if ( v:IsVisible() and MouseIsOver(v) ) then
			if ( v.name ) then
				tooltipText = tooltipText..newLineString..v.name
			end
			newLineString = "\n"
		end
	end
	-- Check debug objects
	for i = 1, NUM_WORLDMAP_DEBUG_OBJECTS do
		unitButton = _G["WorldMapDebugObject"..i]
		if ( unitButton:IsVisible() and MouseIsOver(unitButton) ) then
			tooltipText = tooltipText..newLineString..unitButton.name
			newLineString = "\n"
		end
	end
	WorldMapTooltip:SetText(tooltipText)
	WorldMapTooltip:Show()
end