local name = "aquafusion tooltip";
local tag = "af_tooltip";
local version = "6.2";
--AFTT_DEBUG = true;
--Author's Notes------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
--[[
	Description:	Drastically improves the game's default tooltip.
	Author:		AquaFlare7 (AquaFlare7@comcast.net)
--]]


--Frame Library-------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

function aftt_toggleAnchorWindows()
	if (AF_ToolTip_AnchorGUI:IsVisible() and
	AF_ToolTip_AnchorWorld:IsVisible() and
	AF_ToolTip_AnchorUnit:IsVisible()) then
		--close them all
		AF_ToolTip_AnchorGUI:Hide();
		AF_ToolTip_AnchorWorld:Hide();
		AF_ToolTip_AnchorUnit:Hide();
	else
		--open them all
		AF_ToolTip_AnchorGUI:Show();
		AF_ToolTip_AnchorWorld:Show();
		AF_ToolTip_AnchorUnit:Show();
	end
end

function aftt_toggleFrame(frameName)
	if (getglobal(frameName):IsVisible()) then
		getglobal(frameName):Hide();
	else
		getglobal(frameName):Show();
	end
end

function aftt_configOptions(configcheckbutton,configsaveTo)
	if (getglobal(configcheckbutton)) then
		if (configsaveTo) then
			--saving option
			if (getglobal(configcheckbutton):GetChecked()) then
				--turning on
				af_tooltips[aftt_localUser][configsaveTo] = getglobal(configcheckbutton):GetName();
			else
				--turning off
				af_tooltips[aftt_localUser][configsaveTo] = nil;
			end
		else
			--loading option
			getglobal(configcheckbutton):SetChecked(1);
		end
	end
end

function aftt_anchorOptions(checkbutton,anchorType)
	--DEFAULT_CHAT_FRAME:AddMessage(checkbutton.." / "..anchorType);
	if (anchorType == "gui") then
		saveTo = "AnchorGUI";
		--clear all gui checkboxes first
			AF_ToolTip_AnchorGUI_topleft:SetChecked(0);
			AF_ToolTip_AnchorGUI_top:SetChecked(0);
			AF_ToolTip_AnchorGUI_topright:SetChecked(0);
			AF_ToolTip_AnchorGUI_left:SetChecked(0);
			AF_ToolTip_AnchorGUI_right:SetChecked(0);
			AF_ToolTip_AnchorGUI_bottomleft:SetChecked(0);
			AF_ToolTip_AnchorGUI_bottom:SetChecked(0);
			AF_ToolTip_AnchorGUI_bottomright:SetChecked(0);
			AF_ToolTip_AnchorGUI_center:SetChecked(0);
			AF_ToolTip_AnchorGUI_mouse:SetChecked(0);
			AF_ToolTip_AnchorGUI_none:SetChecked(0);
	elseif (anchorType == "world") then
		saveTo = "AnchorWorld";
		--clear all unit checkboxes first
			AF_ToolTip_AnchorWorld_topleft:SetChecked(0);
			AF_ToolTip_AnchorWorld_top:SetChecked(0);
			AF_ToolTip_AnchorWorld_topright:SetChecked(0);
			AF_ToolTip_AnchorWorld_left:SetChecked(0);
			AF_ToolTip_AnchorWorld_right:SetChecked(0);
			AF_ToolTip_AnchorWorld_bottomleft:SetChecked(0);
			AF_ToolTip_AnchorWorld_bottom:SetChecked(0);
			AF_ToolTip_AnchorWorld_bottomright:SetChecked(0);
			AF_ToolTip_AnchorWorld_center:SetChecked(0);
			AF_ToolTip_AnchorWorld_mouse:SetChecked(0);
			AF_ToolTip_AnchorWorld_none:SetChecked(0);
	elseif (anchorType == "unit") then
		saveTo = "AnchorUnit";
		--clear all unit checkboxes first
			AF_ToolTip_AnchorUnit_topleft:SetChecked(0);
			AF_ToolTip_AnchorUnit_top:SetChecked(0);
			AF_ToolTip_AnchorUnit_topright:SetChecked(0);
			AF_ToolTip_AnchorUnit_left:SetChecked(0);
			AF_ToolTip_AnchorUnit_right:SetChecked(0);
			AF_ToolTip_AnchorUnit_bottomleft:SetChecked(0);
			AF_ToolTip_AnchorUnit_bottom:SetChecked(0);
			AF_ToolTip_AnchorUnit_bottomright:SetChecked(0);
			AF_ToolTip_AnchorUnit_center:SetChecked(0);
			AF_ToolTip_AnchorUnit_mouse:SetChecked(0);
			AF_ToolTip_AnchorUnit_none:SetChecked(0);
	end

	--set current checkbox
		getglobal(checkbutton):SetChecked(1);
		af_tooltips[aftt_localUser][saveTo] = checkbutton;
end

--onEvent Routine------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

function aftt_onEvent(event,arg1)
	if (event == "ADDON_LOADED" and arg1 == "af_tooltip") then
		aftt_loaded = true;
		aftt_onLoad();
	elseif (event == "CURSOR_UPDATE") then
		aftt_flushArray(blackList);
	elseif (UnitExists("mouseover") and aftt_loaded) then
		aftt_format("mouseover");
		--DEFAULT_CHAT_FRAME:AddMessage("Mouse is over: ".."|cff00ccff"..UnitName("mouseover").."|r");
	end
end

--onLoad Routine------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
function aftt_onLoad()
	--Register Events
		GameTooltip:SetScript("OnUpdate",aftt_forceformat);
		AF_ToolTipFrame:RegisterEvent("CURSOR_UPDATE");

	--Set our constant gui values
		AF_ToolTip_Config_title:SetText(name .. " v" .. version);
		AF_ToolTip_Config_title:SetVertexColor(1.0, 1.0, .2);
		AF_ToolTip_Config:SetBackdropBorderColor(1.0, 1.0, .2);
		AF_ToolTip_Config:SetClampedToScreen(true);

		AF_ToolTip_AnchorGUI_title:SetText('Interface Tooltips');
		AF_ToolTip_AnchorGUI_title:SetVertexColor(1.0, .2, .2);
		AF_ToolTip_AnchorGUI:SetBackdropBorderColor(1.0, .2, .2);
		AF_ToolTip_AnchorGUI:SetClampedToScreen(true);

		AF_ToolTip_AnchorWorld_title:SetText('World Tooltips');
		AF_ToolTip_AnchorWorld_title:SetVertexColor(.2, 1.0, .2);
		AF_ToolTip_AnchorWorld:SetBackdropBorderColor(.2, 1.0, .2);
		AF_ToolTip_AnchorWorld:SetClampedToScreen(true);

		AF_ToolTip_AnchorUnit_title:SetText('Unit Frame Tooltips');
		AF_ToolTip_AnchorUnit_title:SetVertexColor(.2, .2, 1.0);
		AF_ToolTip_AnchorUnit:SetBackdropBorderColor(.2, .2, 1.0);
		AF_ToolTip_AnchorUnit:SetClampedToScreen(true);


	--Create arrays we need
		originalTip = {};
		originalTipR = {};
		originalTipG = {};
		originalTipB = {};
		extraData = {};
		extraDataR = {};
		extraDataG = {};
		extraDataB = {};
		blackList = {};


	--Create update table
		aftt_updateFlag = {
			["Previous"] = "none";
			["Current"] = "none";
			["Reaction"] = 0;
			["EasterEgg"] = 0;
			["PvP"] = 0;
			["RankFlag"] = 0;
			["Target"] = 0;
		}

	--Create user table if it doesnt exist
		aftt_localUser = ("Settings");
		if (not af_tooltips) then
			af_tooltips = {};
		end
		if (not af_tooltips[aftt_localUser]) then
			af_tooltips[aftt_localUser] = {
				["AnchorGUI"] = "AF_ToolTip_AnchorGUI_bottom";
				["AnchorWorld"] = "AF_ToolTip_AnchorWorld_mouse";
				["AnchorUnit"] = "AF_ToolTip_AnchorUnit_topleft";
				["Tapped"] = "AF_ToolTip_Config_Tapped";
				["Target"] = "AF_ToolTip_Config_Target";
			}
			DEFAULT_CHAT_FRAME:AddMessage("|cffffdd00[" .. tag .. "]:|r First time usage settings loaded.");
			AF_ToolTip_Config:Show();
		end
	--Register our slash commands for use
		aftt_slashCommands();

	--Swap Blizzard's tooltip functions out for our own (making sure to backup the old function)
		aftt_Old_GameTooltip_OnEvent = GameTooltip_OnEvent;
		GameTooltip_OnEvent = aftt_GameTooltip_OnEvent;
		aftt_Old_GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor;
		GameTooltip_SetDefaultAnchor = aftt_GameTooltip_SetDefaultAnchor;

	--Set colors
		--loaded from colorChart.lua

	--Output message to let player know AF_ToolTip has loaded, and if there were any missing colors
		DEFAULT_CHAT_FRAME:AddMessage("|cffffdd00[" .. tag .. "]:|r v" .. version .. " " .. aftt_translate_loaded .. ".");
		DEFAULT_CHAT_FRAME:AddMessage("|cffffdd00[" .. tag .. "]:|r Type |cff00ff00/aftt|r for the options menu.");
		DEFAULT_CHAT_FRAME:AddMessage("|cffffdd00[" .. tag .. "]:|r |cff0088FF" .. aftt_color_chart_name .. "|r by |cff0088FF" .. aftt_color_chart_author .. "|r applied.");
		if (aftt_variableChecker_Flag == 1) then
			DEFAULT_CHAT_FRAME:AddMessage("|cffffdd00[" .. tag .. "]:|r The currently active color chart file is missing some color definitions. Missing colors will default to white.");
		end

	--Apply our configurable options
		--anchor options
			aftt_anchorOptions(af_tooltips[aftt_localUser]["AnchorGUI"],"gui");
			aftt_anchorOptions(af_tooltips[aftt_localUser]["AnchorWorld"],"world");
			aftt_anchorOptions(af_tooltips[aftt_localUser]["AnchorUnit"],"unit");
		--config options
			aftt_configOptions(af_tooltips[aftt_localUser]["ReactionText"]);
			aftt_configOptions(af_tooltips[aftt_localUser]["Tapped"]);
			aftt_configOptions(af_tooltips[aftt_localUser]["Target"]);
			aftt_configOptions(af_tooltips[aftt_localUser]["PvP"]);
end



--Unit MouseOver Routine----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
function aftt_forceformat()
	if (not currentlyFormatting and UnitExists("mouseover") and string.find(GameTooltipTextLeft1:GetText(),UnitName("mouseover"))) then
		currentlyFormatting = true;
		aftt_formatPlugged("mouseover");
		currentlyFormatting = false;
	end
end



function aftt_getLevelLine()
	if (GameTooltipTextLeft2:GetText()) then
		local levelLine, matched = string.gsub(GameTooltipTextLeft2:GetText(), (aftt_translate_level .. ".*"), "");
		if (matched == 1) then
			levelLine = nil;
			matched = nil;
			return 2;
		else
			if (GameTooltipTextLeft3:GetText()) then
				levelLine, matched = string.gsub(GameTooltipTextLeft3:GetText(), (aftt_translate_level .. ".*"), "");
				if (matched == 1) then
					levelLine = nil;
					matched = nil;
					return 3;
				else
					levelLine = nil;
					matched = nil;
					return nil;
				end
			else
					levelLine = nil;
					matched = nil;
				return nil;
			end
		end
	end
end

function aftt_appendUnique(array,string,index)
	local unique = true;
	if (blackList) then
		for k,v in ipairs (blackList) do
			if (v == string) then
				unique = false;
			end
		end
	end

	if (unique) then
		table.insert(array,string);
		extraDataR[index] = originalTipR[index];
		extraDataG[index] = originalTipG[index];
		extraDataB[index] = originalTipB[index];
	end
	string = nil;
	return array;
end

function aftt_addSafe(string)
	table.insert(blackList,string);
	aftt_add(string);
	string = nil;
end

function aftt_add(string)
	GameTooltip:AddLine(string);
end

function aftt_flushArray(array)
	for i,v in ipairs (array) do
		array[i] = nil;
	end
end

function aftt_flushVariables()
	aftt_flushArray(originalTip);
	aftt_flushArray(extraData);
	levelLine = nil;
	matched = nil;
	countTheLines = nil;
	recountTheLines = nil;
	aftt_text_race = nil;
	aftt_color_race = nil;
	aftt_text_class = nil;
	aftt_color_class = nil;
	aftt_text_elite = nil;
	aftt_color_elite = nil;
	aftt_color_name = nil;
	aftt_color_description = nil;
	aftt_text_reaction = nil;
	aftt_text_level = nil;
	aftt_color_level = nil;
	levelDiff = nil;
	aftt_text_corpse = nil;
	aftt_rank = nil;
	aftt_rankName = nil;
	aftt_rankNumber = nil;
	widestLine = nil;
	aftt_lineCount = nil;
	eDataCurLine = nil;
end

function aftt_formatPlugged(unit)
	--Preformat Jobs-------------------------------------------
	-----------------------------------------------------------
		--Decide what line the level is on
			levelLine = aftt_getLevelLine();

		--is there anything extra on the tooltip (such as other addon messages etc)?
		--first count the lines and then reset the unit and count the lines again to
		--see if there is a difference (saving the original tooltip data)

		countTheLines = GameTooltip:NumLines();

		for i=1, countTheLines do
			originalTip[i] = getglobal("GameTooltipTextLeft"..i):GetText();
		end

		GameTooltip:ClearLines();
		GameTooltip:SetUnit(unit);

		recountTheLines = GameTooltip:NumLines();
		if (recountTheLines < countTheLines) then
			--save the extra lines into an array
			for i=recountTheLines+1,countTheLines do
				originalTipR[i], originalTipG[i], originalTipB[i] = getglobal("GameTooltipTextLeft"..i):GetTextColor();
				--DEFAULT_CHAT_FRAME:AddMessage("|cffff0000"..originalTipR[i].."|r |cff00ff00"..originalTipG[i].."|r |cff0000ff"..originalTipB[i].."|r");
				extraData = aftt_appendUnique(extraData,originalTip[i],i);
			end
		end

	--Data Collection------------------------------------------
	-----------------------------------------------------------
		--unit race
			if (UnitRace(unit) and UnitIsPlayer(unit)) then
				--race, it is a player
					aftt_text_race = UnitRace(unit);
			elseif (UnitPlayerControlled(unit)) then
				--creature family, its is a pet
					aftt_text_race = UnitCreatureFamily(unit);
					aftt_color_race = aftt_color_race_mob;
			else
				--creature type, it is a mob
					if (UnitCreatureType(unit) == aftt_translate_notspecified) then
						aftt_text_race = ""
						aftt_color_race = aftt_color_race_mob;
					else
						aftt_text_race = UnitCreatureType(unit);
						aftt_color_race = aftt_color_race_mob;
					end
			end
			if (aftt_text_race == nil) then
				aftt_text_race = ("");
			else
				aftt_text_race = (aftt_text_race .. " ");
			end
				aftt_color_race = "FFFFFF";

		--unit class
			if (UnitClass(unit) and UnitIsPlayer(unit)) then
				aftt_text_class = (UnitClass(unit) .. " ");
				if (UnitClass(unit) == aftt_translate_mage) then
					aftt_color_class = aftt_color_class_mage;
				elseif (UnitClass(unit) == aftt_translate_warlock) then
					aftt_color_class = aftt_color_class_warlock;
				elseif (UnitClass(unit) == aftt_translate_priest) then
					aftt_color_class = aftt_color_class_priest;
				elseif (UnitClass(unit) == aftt_translate_druid) then
					aftt_color_class = aftt_color_class_druid;
				elseif (UnitClass(unit) == aftt_translate_shaman) then
					aftt_color_class = aftt_color_class_shaman;
				elseif (UnitClass(unit) == aftt_translate_paladin) then
					aftt_color_class = aftt_color_class_paladin;
				elseif (UnitClass(unit) == aftt_translate_rogue) then
					aftt_color_class = aftt_color_class_rogue;
				elseif (UnitClass(unit) == aftt_translate_hunter) then
					aftt_color_class = aftt_color_class_hunter;
				elseif (UnitClass(unit) == aftt_translate_warrior) then
					aftt_color_class = aftt_color_class_warrior;
				else
					aftt_color_class = aftt_color_unknown;
				end
			else
				aftt_text_class = "";
				aftt_color_class = aftt_color_unknown;
			end

		--unit elite
			if (UnitClassification(unit) and UnitClassification(unit) ~= "normal" and UnitHealth(unit) > 0) then
				if (UnitClassification(unit) == "elite") then
					aftt_text_elite = ("(" .. aftt_translate_elite .. ")");
					aftt_color_elite = aftt_color_elite_elite;
				elseif (UnitClassification(unit) == "worldboss") then
					aftt_text_elite = ("(" .. aftt_translate_worldboss .. ")");
					aftt_color_elite = aftt_color_elite_worldboss;
				elseif (UnitClassification(unit) == "rare") then
					aftt_text_elite = ("(" .. aftt_translate_rare .. ")");
					aftt_color_elite = aftt_color_elite_rare;
				elseif (UnitClassification(unit) == "rareelite") then
					aftt_text_elite = ("(" .. aftt_translate_rareelite .. ")");
					aftt_color_elite = aftt_color_elite_rareelite;
				else
					aftt_text_elite = ("(" .. UnitClassification(unit) .. ")");
					aftt_color_elite = aftt_color_unknown;
				end
			else
				aftt_text_elite = "";
				aftt_color_elite = aftt_color_unknown;
			end

		--unit name, description and bg color
			if (UnitPlayerControlled(unit)) then
				if (UnitCanAttack(unit, "player") and UnitCanAttack ("player",unit)) then
					--red, hostile, both can attack
						GameTooltip:SetBackdropColor(aftt_background_color["Player_Hostile"]["red"], aftt_background_color["Player_Hostile"]["green"], aftt_background_color["Player_Hostile"]["blue"]);
						aftt_color_name = aftt_color_name_hostile;
						aftt_color_description = aftt_color_description_hostile;
						aftt_text_reaction = aftt_translate_hostile;
				elseif (not UnitCanAttack(unit, "player") and UnitCanAttack("player",unit)) then
					--yellow, neutral, only I can attack
						GameTooltip:SetBackdropColor(aftt_background_color["Player_Neutral"]["red"], aftt_background_color["Player_Neutral"]["green"], aftt_background_color["Player_Neutral"]["blue"]);
						aftt_color_name = aftt_color_name_neutral;
						aftt_color_description = aftt_color_description_neutral;
						aftt_text_reaction = aftt_translate_neutral;
				elseif (UnitCanAttack(unit, "player") and not UnitCanAttack("player",unit)) then
					--purple, caution, only they can attack
						GameTooltip:SetBackdropColor(aftt_background_color["Player_Caution"]["red"], aftt_background_color["Player_Caution"]["green"], aftt_background_color["Player_Caution"]["blue"]);
						aftt_color_name = aftt_color_name_caution;
						aftt_color_description = aftt_color_description_caution;
						aftt_text_reaction = aftt_translate_caution;
				elseif (not UnitCanAttack(unit, "player") and not UnitCanAttack("player",unit)) then
					if (UnitIsPVP(unit)) then
						--green, friendly pvp, neither can attack
							GameTooltip:SetBackdropColor(aftt_background_color["Player_Friendly_PvP"]["red"], aftt_background_color["Player_Friendly_PvP"]["green"], aftt_background_color["Player_Friendly_PvP"]["blue"]);
							aftt_color_name = aftt_color_name_pvp;
							aftt_color_description = aftt_color_description_pvp;
							aftt_text_reaction = aftt_translate_friendly;
					else
						--blue, friendly, neither can attack
							GameTooltip:SetBackdropColor(aftt_background_color["Player_Friendly"]["red"], aftt_background_color["Player_Friendly"]["green"], aftt_background_color["Player_Friendly"]["blue"]);
							aftt_color_name = aftt_color_name_friendly;
							aftt_color_description = aftt_color_description_friendly;
							aftt_text_reaction = aftt_translate_friendly;
					end
				end
			elseif (UnitReaction(unit,"player") and UnitReaction(unit,"player") <= 3) then
				--red, they are hostile
					GameTooltip:SetBackdropColor(aftt_background_color["Mob_Hostile"]["red"], aftt_background_color["Mob_Hostile"]["green"], aftt_background_color["Mob_Hostile"]["blue"]);
					aftt_color_name = aftt_color_name_hostile;
					aftt_text_reaction = aftt_translate_hostile;
					aftt_color_description = aftt_color_description_hostile
			elseif (UnitReaction(unit,"player") and UnitReaction(unit,"player") == 4) then
				--yellow, they are neutral
					GameTooltip:SetBackdropColor(aftt_background_color["Mob_Neutral"]["red"], aftt_background_color["Mob_Neutral"]["green"], aftt_background_color["Mob_Neutral"]["blue"]);
					aftt_color_name = aftt_color_name_neutral;
					aftt_text_reaction = aftt_translate_neutral;
					aftt_color_description = aftt_color_description_neutral
			else
				if (UnitIsPVP(unit)) then
					--green, pvp enabled friend
						GameTooltip:SetBackdropColor(aftt_background_color["Mob_Friendly_PvP"]["red"], aftt_background_color["Mob_Friendly_PvP"]["green"], aftt_background_color["Mob_Friendly_PvP"]["blue"]);
						aftt_color_name = aftt_color_name_pvp;
						aftt_color_description = aftt_color_description_pvp
				else
					--blue, they are friendly
						GameTooltip:SetBackdropColor(aftt_background_color["Mob_Friendly"]["red"], aftt_background_color["Mob_Friendly"]["green"], aftt_background_color["Mob_Friendly"]["blue"]);
						aftt_color_name = aftt_color_name_friendly;
						aftt_color_description = aftt_color_description_friendly;
				end
				aftt_text_reaction = aftt_translate_friendly;
			end

		--unit tapped?
			if (af_tooltips[aftt_localUser]["Tapped"]) then
				if (UnitIsTapped(unit)and (not UnitIsTappedByPlayer(unit))) then
					aftt_color_name = aftt_color_name_tapped_by_other;
					aftt_color_description = aftt_color_description_tapped_by_other;
					aftt_text_reaction = aftt_translate_tapped;
				elseif (UnitIsTappedByPlayer(unit)) then
					GameTooltip:SetBackdropColor(aftt_background_color["Mob_Hostile"]["red"], aftt_background_color["Mob_Hostile"]["green"], aftt_background_color["Mob_Hostile"]["blue"]);
					aftt_color_name = aftt_color_name_tapped_by_me;
					aftt_color_description = aftt_color_description_tapped_by_me;
					aftt_text_reaction = aftt_translate_hostile;
				end
			end

		--unit level and level difference color
			if (UnitLevel(unit) and UnitLevel(unit) >= 1) then
				aftt_text_level = UnitLevel(unit);
			else
				aftt_text_level = "??";
			end
			aftt_text_level = (aftt_translate_level .. " " .. aftt_text_level .. " ");
			local levelDiff = UnitLevel(unit) - UnitLevel("player");
			if (UnitFactionGroup(unit) ~= UnitFactionGroup("player")) then
				if ( levelDiff >= 5 or UnitLevel(unit) == -1) then
					aftt_color_level = aftt_color_level_impossible
				elseif ( levelDiff >= 3 ) then
					aftt_color_level = aftt_color_level_hard;
				elseif ( levelDiff >= -2 ) then
					aftt_color_level = aftt_color_level_normal;
				elseif ( -levelDiff <= GetQuestGreenRange() ) then
					aftt_color_level = aftt_color_level_easy;
				else
					aftt_color_level = aftt_color_level_trivial;
				end
			else
					aftt_color_level = aftt_color_level_same_faction;			
			end

		--[[ pvp honor rank
			if (aftt_updateFlag["RankFlag"] == 0) then
				if (UnitPVPRank(unit)) then
				    aftt_rankName, aftt_rankNumber = GetPVPRankInfo(UnitPVPRank("mouseover"), "mouseover");
				end
				if (aftt_rankName == nil) then
				    aftt_rankName = "";			
				else
					aftt_rankName = ("[" .. aftt_rankName .. "] ");
				end
				if (aftt_rankNumber == nil or aftt_rankNumber < 1) then
				    aftt_rankNumber = "";
				else
					aftt_rankNumber = ("[" .. aftt_rankNumber .. "] ");				
				end

				if (af_tooltips[aftt_localUser]["Rank"] == 1) then
					aftt_rank = aftt_rankName;
				elseif (af_tooltips[aftt_localUser]["Rank"] == 2) then
					aftt_rank = aftt_rankNumber;
				else
					aftt_rank = "";
				end

				aftt_updateFlag["RankFlag"] = 1;
			else
				if (aftt_rank == nil) then
					aftt_rank = "";
				end
			end
		--]]

		--unit is corpse
			if (UnitHealth(unit) == 0) then
				aftt_text_corpse = aftt_translate_corpse;
				aftt_color_class = aftt_color_corpse;
				aftt_color_race = aftt_color_corpse;
				aftt_color_elite = aftt_color_corpse;
				aftt_color_name = aftt_color_corpse;
				aftt_color_description = aftt_color_corpse;
				aftt_color_level = aftt_color_corpse;
			else
				aftt_text_corpse = "";
			end

	--Output Name Data-----------------------------------------
	-----------------------------------------------------------
		if (af_tooltips[aftt_localUser]["ReactionText"]) then
			GameTooltipTextLeft1:SetText("|cff" .. aftt_color_name .. UnitName(unit) .. " (" .. aftt_text_reaction .. ")|r")
		else
			GameTooltipTextLeft1:SetText("|cff" .. aftt_color_name .. UnitName(unit) .. "|r");
		end

	--Output Level Line Data-----------------------------------
	-----------------------------------------------------------
		local levelLine, matched;
		if (GameTooltipTextLeft2:GetText() == nil) then
			GameTooltip:Hide();
		else
			levelLine = aftt_getLevelLine();
		end
		if (levelLine) then
			getglobal("GameTooltipTextLeft" .. levelLine):SetText("|cff" .. aftt_color_level .. aftt_text_level .. "|r" .. "|cff" .. aftt_color_race .. aftt_text_race .. "|r" .. "|cff" .. aftt_color_class .. aftt_text_class .. "|r" .. "|cff" .. aftt_color_elite .. aftt_text_elite .. "|r" .. "|cff" .. aftt_color_corpse .. aftt_text_corpse .. "|r");
			if (levelLine == 3) then
				GameTooltipTextLeft2:SetText("|cff" .. aftt_color_description .. GameTooltipTextLeft2:GetText() .. "|r")
			end
		end

	--Append Easter Eggs---------------------------------------
	-----------------------------------------------------------
		if (GetRealmName() == "Spinebreaker" and (UnitName(unit) == "Aquaflare" or
		UnitName(unit) == "Gamebreaker" or UnitName(unit) == "Layke")) then
			aftt_addSafe("|cff" .. aftt_color_name .. aftt_translate_author.."|r");
		end

	--Show/Hide PvP--------------------------------------------
	-----------------------------------------------------------
		aftt_lineCount = 1;
		for i = 3, 10 do
			aftt_getLine = getglobal("GameTooltipTextLeft" .. aftt_lineCount);
			if (aftt_getLine:GetText()) then
				local pvpLine, matchPVP;
				pvpLine, matchPVP = string.gsub(aftt_getLine:GetText(), (aftt_translate_pvp .. ".*"), "");
				if (matchPVP == 1) then
					aftt_getLine:SetText("");
					break;
				else
					aftt_lineCount = aftt_lineCount + 1;
				end
			end
		end
		if (af_tooltips[aftt_localUser]["PvP"]) then
			if (UnitIsPVP(unit)) then
				aftt_addSafe("|cffFFFFFFPvP|r");
			end
		end

	--Show/Hide Target-----------------------------------------
	-----------------------------------------------------------
		if (af_tooltips[aftt_localUser]["Target"] and UnitName("mouseovertarget") ~= "Unknown") then
			aftt_addSafe("|cff" .. aftt_color_target .. "Target: " .. UnitName("mouseovertarget") .. "|r");
		end

	--Add Extra Data-------------------------------------------
	-----------------------------------------------------------
		if (extraData) then
			eDataCurLine = GameTooltip:NumLines() + 1;
			for i,v in ipairs (extraData) do
				GameTooltip:AddLine(v);
				--getglobal("GameTooltipTextLeft"..eDataCurLine):SetTextColor(extraDataR[i],extraDataG[i],extraDataB[i]);
				eDataCurLine = eDataCurLine + 1;
			end
		end

	--Re Initialize Tooltip------------------------------------
	-----------------------------------------------------------
		GameTooltip:Show();

	--Garbage Man----------------------------------------------
	-----------------------------------------------------------
		aftt_flushVariables();
end