ToolsQuickLoot = {
	["Interface\\TargetingFrame\\TargetDead"] = "Interface\\Icons\\INV_Misc_Bag_17",
	["Interface\\LootFrame\\FishingLoot-Icon"] = "Interface\\Icons\\INV_Misc_Fish_10",
	Loot = LootFrame,
	FrameBorder = {bgFile = "Interface/Tooltips/UI-Tooltip-Background",
			edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
			tile = true, tileSize = 5, edgeSize = 16,
			insets={left = 4, right = 4, top = 4, bottom = 4}}
}

function ToolsQuickLoot:OnLoad()
	UIPanelWindows["LootFrame"] = nil

	LootCloseButton:RegisterForDrag("LeftButton")
	LootCloseButton:SetScript("OnDragStart", function() LootFrame:StartMoving() end)
	LootCloseButton:SetScript("OnDragStop", function() LootFrame:StopMovingOrSizing() end)
	LootCloseButton:SetScript("OnEnter", function() 
		GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
		GameTooltip:SetText("|CFF00AAFF클릭 : |CFFFFFFFF닫기\n|CFF00AAFF드래그 : |CFFFFFFFF이동")
	end)
	LootCloseButton:SetScript("OnLeave", function()
		GameTooltip:Hide()
	end)

	hooksecurefunc("LootFrame_OnShow", function() ToolsQuickLoot:CheckPoint() end)
	hooksecurefunc("LootFrame_PageDown", function() ToolsQuickLoot:LootFrame_Size() end)
	hooksecurefunc("LootFrame_PageUp", function() ToolsQuickLoot:LootFrame_Size() end)

	for _,v in pairs({self.Loot:GetRegions()}) do
		if v.SetText then
			if v:GetText() == ITEMS then
				self.Text = v
				v:ClearAllPoints()
				v:SetPoint("TOP", self.Loot, "TOP", 0, -17)
				v:SetTextHeight(16)
			else
				v:SetText("")
			end
		end
		if v.SetTexture then
			v:Hide()
		end
	end

	self.Loot:SetFrameStrata("HIGH")
	self.Loot:SetBackdrop(self.FrameBorder)
	self.Loot:SetWidth(164)

	self.Bg = LootFrame:CreateTexture(nil, "BORDER")
	self.Bg:SetPoint("TOPLEFT", self.Loot, "TOPLEFT", 5, -5)
	self.Bg:SetPoint("BOTTOMRIGHT", self.Loot, "BOTTOMRIGHT", -5, 5)
	self.Bg:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
	self.Bg:SetBlendMode("BLEND")
	self.Bg:SetGradientAlpha("VERTICAL", 0, 0, 0, 1, .4, .4, .4, .8)

	self.PortraitBg = CreateFrame("Frame", nil, self.Loot)
	self.PortraitBg:SetPoint("TOPRIGHT", self.Loot, "TOPLEFT", 0, -5)
	self.PortraitBg:SetBackdrop(self.FrameBorder)
	self.PortraitBg:SetWidth(42)
	self.PortraitBg:SetHeight(42)
	self.PortraitBg:SetBackdropColor(0,0,0,1)

	LootCloseButton:ClearAllPoints()
	LootCloseButton:SetPoint("CENTER", self.PortraitBg, "CENTER", 0, 0)
	LootCloseButton:GetNormalTexture():SetTexCoord(0.06,0.94,0.09,0.94)
	LootCloseButton:GetHighlightTexture():SetTexture("")

	LootFrameUpButton:ClearAllPoints()
	LootFrameDownButton:ClearAllPoints()
	LootFrameDownButton:SetPoint("TOPLEFT", LootFrame, "TOPRIGHT", 0, 2)
	LootFrameUpButton:SetPoint("BOTTOMLEFT", LootFrame, "BOTTOMRIGHT", 0, -2)

	LootButton1:ClearAllPoints()
	LootButton1:SetPoint("TOPLEFT", LootFrame, "TOPLEFT", 8, -8)
end
function ToolsQuickLoot:CheckPoint()
	self:LootFrame_Size()
	local x, y = GetCursorPosition()
	local scale = self.Loot:GetEffectiveScale()

	x = x / scale
	y = y / scale

	x = (x > GetScreenWidth() - self.Loot:GetWidth()) and GetScreenWidth() - self.Loot:GetWidth() or x - 25
	y = (y < self.height) and self.height or y + 25

	self.Loot:ClearAllPoints()
	self.Loot:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y)
	self:CheckTexture()
	self:SetText()
end
function ToolsQuickLoot:CheckTexture()
	LootCloseButton:SetNormalTexture(self[LootFramePortraitOverlay:GetTexture()])
	LootCloseButton:SetPushedTexture(self[LootFramePortraitOverlay:GetTexture()])
end
function ToolsQuickLoot:SetText()
	self.Text:SetText((self.Loot.numLootItems == 0) and "꽝! 다음기회를" or "")
end
function ToolsQuickLoot:LootFrame_SizeCalc()
	if self.Loot.page == 1 then
		if self.Loot.numLootItems > 4 then
			return 3
		end
		return self.Loot.numLootItems
	else
		return (self.Loot.numLootItems > (3 * self.Loot.page)) and 3 or self.Loot.numLootItems - (3 * (self.Loot.page-1))
	end
end
function ToolsQuickLoot:LootFrame_Size()
	self.height = (self.Loot.numLootItems == 0) and 52 or (41 * self:LootFrame_SizeCalc()) + 12
	self.Loot:SetHeight(self.height)
end
function ToolsQuickLoot:FindBagSlot(item)
	for i=0, NUM_BAG_FRAMES do
		for j=1, GetContainerNumSlots(i) do
			if GetContainerItemLink(i, j) and string.find(GetContainerItemLink(i, j), item) then
				self.finditemslot = {i,j}
				return
			end
		end
	end
	self.finditemslot = nil
end
ToolsQuickLoot:OnLoad()