--Changing Anchors Routine--------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
function aftt_getType()
	local type;
	if (UnitExists("mouseover") and GetMouseFocus():GetName() == "WorldFrame") then
		--this is a world unit
		if (AFTT_DEBUG) then DEFAULT_CHAT_FRAME:AddMessage("World Unit"); end
		type = "world";
	elseif (UnitName("mouseover") and not UnitExists("mouseover") and GetMouseFocus():GetName() == "WorldFrame") then
		--world doodad
		if (AFTT_DEBUG) then DEFAULT_CHAT_FRAME:AddMessage("World Doodad"); end
		type = "world";
	elseif (UnitName("mouseover") and UnitExists("mouseover")) then
		--interface unit
		if (AFTT_DEBUG) then DEFAULT_CHAT_FRAME:AddMessage("Interface Unit"); end
		type = "unit"
	else
		--interface control
		if (AFTT_DEBUG) then DEFAULT_CHAT_FRAME:AddMessage("Interface Control"); end
		type = "gui";
	end
	return type;
end

function aftt_GameTooltip_SetDefaultAnchor(tooltip, parent)
	if (aftt_getType() == "gui") then
		--mousing over a gui element - lets anchor it down

		if (AF_ToolTip_AnchorGUI_topleft:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOPLEFT", "AF_ToolTip_AnchorGUI", "TOPLEFT", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_top:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOP", "AF_ToolTip_AnchorGUI", "TOP", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_topright:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOPRIGHT", "AF_ToolTip_AnchorGUI", "TOPRIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_left:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("LEFT", "AF_ToolTip_AnchorGUI", "LEFT", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_right:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("RIGHT", "AF_ToolTip_AnchorGUI", "RIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_bottomleft:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOMLEFT", "AF_ToolTip_AnchorGUI", "BOTTOMLEFT", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_bottom:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOM", "AF_ToolTip_AnchorGUI", "BOTTOM", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_bottomright:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOMRIGHT", "AF_ToolTip_AnchorGUI", "BOTTOMRIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_center:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("CENTER", "AF_ToolTip_AnchorGUI", "CENTER", 0, 0);

		elseif (AF_ToolTip_AnchorGUI_mouse:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_CURSOR");

		elseif (AF_ToolTip_AnchorGUI_none:GetChecked()) then
			aftt_Old_GameTooltip_SetDefaultAnchor(tooltip, parent);
		end
	elseif (aftt_getType() == "world") then

		--mousing over a world element - lets anchor it down

		if (AF_ToolTip_AnchorWorld_topleft:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOPLEFT", "AF_ToolTip_AnchorWorld", "TOPLEFT", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_top:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOP", "AF_ToolTip_AnchorWorld", "TOP", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_topright:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOPRIGHT", "AF_ToolTip_AnchorWorld", "TOPRIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_left:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("LEFT", "AF_ToolTip_AnchorWorld", "LEFT", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_right:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("RIGHT", "AF_ToolTip_AnchorWorld", "RIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_bottomleft:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOMLEFT", "AF_ToolTip_AnchorWorld", "BOTTOMLEFT", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_bottom:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOM", "AF_ToolTip_AnchorWorld", "BOTTOM", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_bottomright:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOMRIGHT", "AF_ToolTip_AnchorWorld", "BOTTOMRIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_center:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("CENTER", "AF_ToolTip_AnchorWorld", "CENTER", 0, 0);

		elseif (AF_ToolTip_AnchorWorld_mouse:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_CURSOR");

		elseif (AF_ToolTip_AnchorWorld_none:GetChecked()) then
			aftt_Old_GameTooltip_SetDefaultAnchor(tooltip, parent);
		end
	elseif (aftt_getType() == "unit") then

		--mousing over a unit interface element

		if (AF_ToolTip_AnchorUnit_topleft:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOPLEFT", "AF_ToolTip_AnchorUnit", "TOPLEFT", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_top:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOP", "AF_ToolTip_AnchorUnit", "TOP", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_topright:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("TOPRIGHT", "AF_ToolTip_AnchorUnit", "TOPRIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_left:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("LEFT", "AF_ToolTip_AnchorUnit", "LEFT", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_right:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("RIGHT", "AF_ToolTip_AnchorUnit", "RIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_bottomleft:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOMLEFT", "AF_ToolTip_AnchorUnit", "BOTTOMLEFT", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_bottom:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOM", "AF_ToolTip_AnchorUnit", "BOTTOM", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_bottomright:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("BOTTOMRIGHT", "AF_ToolTip_AnchorUnit", "BOTTOMRIGHT", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_center:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_NONE");
			tooltip:SetPoint("CENTER", "AF_ToolTip_AnchorUnit", "CENTER", 0, 0);

		elseif (AF_ToolTip_AnchorUnit_mouse:GetChecked()) then
			tooltip:SetOwner(parent, "ANCHOR_CURSOR");

		elseif (AF_ToolTip_AnchorUnit_none:GetChecked()) then
			aftt_Old_GameTooltip_SetDefaultAnchor(tooltip, parent);
		end
	end
end