ToolsOptionCore = {
	Version = "07.07.01_R4",
	headerCount = 0,
	select = 0,
	baseHeight = 24,
	options = {},
	dotbuttons = {},
	dotbutton = {
		{	tooltip = "닫기",
			func = function() ToolsOptionFrame:Hide() end
		},
		{	tooltip = "메모리 찌꺼기 청소",
			func = function() collectgarbage("collect") end
		},
		{	tooltip = "UI 재실행",
			onload = function()
				StaticPopupDialogs["TOOLS_RELOADUI"] = {
					text = "UI를 재실행 하시겠습니까?",
					button1 = YES,
					button2 = NO,
					OnAccept = function() ReloadUI() end,
					timeout = 0,
					hideOnEscape = 1
				}
			end,
			func = function()StaticPopup_Show("TOOLS_RELOADUI") end
		},
	}
}

local opt = ToolsOptionCore
function opt:gra(f,r,g,b,a,r1,g1,b1,a1,inset, type)
	inset = inset or 5
	local t = f:CreateTexture(nil, "BACKGROUND")
	t:SetPoint("TOPLEFT", f, "TOPLEFT", inset, -inset)
	t:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -inset, inset)
	t:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
	t:SetBlendMode("BLEND")
	f:SetBackdropColor(0,0,0,0)
	t:SetGradientAlpha(type and "HORIZONTAL" or "VERTICAL", r or 0, g or 0, b or 0, a or 1, r1 or 1, g1 or 1, b1 or 1, a1 or 0.4)
end
function opt:Backdrop(frame, bg, edge, edgesize, l, r, t, b)
	frame:SetBackdrop({
		bgFile = bg or "Interface\\ChatFrame\\ChatFrameBackground",
		edgeFile = edge or "Interface/Tooltips/UI-Tooltip-Border",
		tile = true, tileSize = 5, edgeSize = edgesize or 16,
		insets={left = l or 5, right = r or l or 5, top = t or l or 5, bottom = b or l or 5}
		})
end
function opt:SetOnEnter(frame, tooltip, func)
	frame:SetScript("OnEnter", function()
		if func then
			func()
		end
		self.helptext:SetText(tooltip or "")
	end)
end
function opt:SetOnLeave(frame, func)
	frame:SetScript("OnLeave", function()
		if func then
			func()
		end
		self.helptext:SetText("")
	end)
end
function opt:CreateDotButton()
	for i = 1, #self.dotbutton do
		self.dotbuttons[i] = CreateFrame("Button", nil, ToolsOptionFrame.title)
		self.dotbuttons[i]:SetWidth(20)
		self.dotbuttons[i]:SetHeight(20)
		self:Backdrop(self.dotbuttons[i], nil, "")
		self.dotbuttons[i]:SetBackdropColor(0,1,0,0.3)
		if i == 1 then 
			self.dotbuttons[i]:SetPoint("RIGHT", ToolsOptionFrame.title, "RIGHT", 0, 0)
		else
			self.dotbuttons[i]:SetPoint("RIGHT", self.dotbuttons[i-1], "LEFT", 0, 0)
		end
		if self.dotbutton[i].onload then
			self.dotbutton[i].onload()
		end
		self.dotbuttons[i]:SetScript("OnClick", function()
			self.dotbutton[i].func()
		end)
		self.dotbuttons[i]:SetScript("OnEnter", function()
			GameTooltip:SetOwner(this, "ANCHOR_BOTTOMLEFT")
			GameTooltip:AddLine(self.dotbutton[i].tooltip,0.7,0.75,1)
			GameTooltip:Show()
			this:SetBackdropColor(0,1,0,0.8)
		end)
		self.dotbuttons[i]:SetScript("OnLeave", function()
			GameTooltip:Hide()
			this:SetBackdropColor(0,1,0,0.3)
		end)
	end
end
function opt:OnLoad()
	self.onenter = {1, 1, 1, .3}
	self.onleave = {0,0,0,0}
	self.onselect = {0, .5, 1, .5}
	local f = CreateFrame("Frame", "ToolsOptionFrame", UIParent)
	f:SetWidth(600)
	f:SetHeight(400)
	f:SetFrameStrata("LOW")
	self:Backdrop(f, nil, "", 0, 0)
	f:SetBackdropBorderColor(1,1,1,1)
	f:SetBackdropColor(0,0,0,0.5)
	f:SetPoint("CENTER", UIParent)
	f:SetMovable(1)
	f:SetClampedToScreen(1)
	f:SetFrameLevel(3)
	f:SetFrameStrata("MEDIUM")
	f:RegisterEvent("ADDON_LOADED")
	f:SetScript("OnEvent", function()
		if arg1 == "ToolsOption" then
			self:OptionCall()
		end
	end)
	local title = CreateFrame("Frame", nil, f)
	f.title = title
	title:SetPoint("TOPLEFT", f)
	self:gra(title, 0, .5, 1, .5,0.25,0.75,0.25,0.6,  0, 1)
	title:SetWidth(600)
	title:SetHeight(20)
	title:EnableMouse(true)
	title:SetFrameLevel(f:GetFrameLevel()+10)
	title.text = title:CreateFontString(nil, "OVERLAY","ChatFontNormal")
	title.text:SetPoint("LEFT", title)
	title.text:SetText("Tool's Option "..self.Version)
	title:RegisterForDrag("LeftButton")
	title:SetScript("OnDragStart", function()
		this:GetParent():StartMoving()
	end)
	title:SetScript("OnDragStop", function()
		this:GetParent():StopMovingOrSizing()
	end)
	local scroll1bg = CreateFrame("Frame", nil, f)
	scroll1bg:SetPoint("TOPLEFT", f, "TOPLEFT", 14,-54)
	scroll1bg:SetWidth(154)
	scroll1bg:SetHeight(332)
	self:Backdrop(scroll1bg)
	scroll1bg:SetBackdropColor(0,0,0,0.5)
	local scroll1 = CreateFrame("ScrollFrame","ToolsOptionHeaderScroll",f,"UIPanelScrollFrameTemplate")
	scroll1:SetPoint("TOPLEFT", f, "TOPLEFT", 20,-60)
	scroll1:SetWidth(120)
	scroll1:SetHeight(320)
	self.scrollHdr = CreateFrame("Frame",nil,f)
	self.scrollHdr:SetWidth(120)
	self.scrollHdr:SetHeight(420)
	scroll1:SetScrollChild(self.scrollHdr)
	local scroll2bg = CreateFrame("Frame", nil, f)
	scroll2bg:SetPoint("TOPLEFT", f, "TOPLEFT", 168,-54)
	scroll2bg:SetWidth(420)
	scroll2bg:SetHeight(332)
	self:Backdrop(scroll2bg)
	scroll2bg:SetBackdropColor(0,0,0,0.5)
	local scroll2 = CreateFrame("ScrollFrame","ToolsOptionFrameScroll",f,"UIPanelScrollFrameTemplate")
	scroll2:SetPoint("TOPLEFT", f, "TOPLEFT", 172,-60)
	scroll2:SetWidth(390)
	scroll2:SetHeight(320)
	self.scrollOpt = CreateFrame("Frame",nil,f)
	self.scrollOpt:SetWidth(390)
	self.scrollOpt:SetHeight(420)
	scroll2:SetScrollChild(self.scrollOpt)
	self.helptext = f:CreateFontString(nil, "OVERLAY")
	self.helptext:SetFont("Fonts\\2002B.ttf", 16, "OUTLINE")
	self.helptext:SetText("")
	self.helptext:SetVertexColor(0,1,0)
	self.helptext:SetPoint("TOPRIGHT", title, "BOTTOMRIGHT", 0, -5)
	self:CreateDotButton()
end
function opt:CreateHeader(value)
	self.headerCount = self.headerCount + 1
	local h = self.baseHeight
	self["headerButton"..self.headerCount] = CreateFrame("Button", nil, self.scrollHdr)
	local v = self["headerButton"..self.headerCount]
	v.optionFrame = CreateFrame("Frame", nil, self.scrollOpt)
	v.optionFrame:SetWidth(390)
	v.optionFrame:SetHeight(self.headerCount*h)
	v.optionFrame:SetPoint("TOPLEFT", self.scrollOpt)
	v.optionFrame:Hide()
	v.optionFrame.id = self.headerCount
	v:SetPoint("TOPLEFT", self.scrollHdr, "TOPLEFT", 0, self.headerCount*-h+h)
	v:SetWidth(120)
	v:SetHeight(h)
	self:CreateFont({text=value.text}, v, true)
	v.id = self.headerCount
	self:Backdrop(v, nil, "", nil, 0)
	self.scrollHdr:SetHeight(self.headerCount*h)
	v:SetBackdropColor(0,0,0,0)
	self:SetOnEnter(v, value.tooltip, function()
		if self.select ~= this.id then 
			this:SetBackdropColor(unpack(self.onenter))
		end
	end)
	self:SetOnLeave(v,  function()
		if self.select == this.id then 
			this:SetBackdropColor(unpack(self.onselect))
		else
			this:SetBackdropColor(unpack(self.onleave))
		end
	end)
	v:SetScript("PostClick", function()
		if self.select == this.id then return end
		self.select = this.id
		this:SetBackdropColor(unpack(self.onselect))
		this.optionFrame:Show()
		self.scrollOpt:SetHeight(this.optionFrame:GetHeight())
		ToolsOptionFrameScroll:SetScrollChild(self.scrollOpt)
		for i = 1, self.headerCount do
			if i ~= this.id then
				self["headerButton"..i]:SetBackdropColor(0,0,0,0)
				self["headerButton"..i].optionFrame:Hide()
			end
		end
	end)
	if value.onshow then
		v.optionFrame:SetScript("OnShow", function()
			value:onshow(this.id)
		end)
	end
	if value.onhide then
		v.optionFrame:SetScript("OnHide", function()
			value:onhide(this.id)
		end)
	end
	return self.headerCount, v.optionFrame
end
opt:OnLoad()

function opt:CreateFont(v, f, title)
	local text = f:CreateFontString(nil, "OVERLAY")
	if title then
		text:SetPoint("CENTER", f)
		text:SetFont("Fonts\\2002B.ttf", 16, "OUTLINE")
	else
		text:SetPoint("LEFT", f, "LEFT", 10, 0)
		text:SetFont("Fonts\\2002B.ttf", 14, "OUTLINE")
	end
	text:SetText(v.text)
	return text
end
function opt:CreateOptBase()
	self.frame.count = self.frame.count + 1
	self.frame.obj[self.frame.count] = CreateFrame("Frame", nil, self.frame)
	self.frame.obj[self.frame.count]:SetWidth(self.frame:GetWidth())
	self.frame.obj[self.frame.count]:SetHeight(self.baseHeight+4)
	self.frame.obj[self.frame.count].id = self.frame.count
	if self.frame.count == 1 then
		self.frame.obj[self.frame.count]:SetPoint("TOPLEFT", self.frame, "TOPLEFT", 0, 0)
	else
		self.frame.obj[self.frame.count]:SetPoint("TOPLEFT", self.frame.obj[self.frame.count-1], "BOTTOMLEFT", 0, -4)
	end
	return self.frame.obj[self.frame.count]
end
function opt:ClearColorFunc(v)
	if ColorPickerFrame:IsShown() and not v then ColorPickerFrame:Hide() end
	if v then return end
	ColorPickerFrame.opacityFunc = nil
	ColorPickerFrame.swatchFunc = nil
	ColorPickerFrame.cancelFunc = nil
end
function opt:SetRefresh(frame, v)
	self.frame.refreshcount = self.frame.refreshcount + 1
	self.frame.refresh[self.frame.refreshcount] = frame
	self.frame.refresh[self.frame.refreshcount].type = v.type
	self.frame.refresh[self.frame.refreshcount].func = v.get
	if v.values then
		self.frame.refresh[self.frame.refreshcount].values = v.values
	end
end
function opt:Refresh(id)
--ToolsOptionCore:Refresh(3)
	local id = id or self.select
	local frame = self["headerButton"..id]
	for i = 1, #frame.optionFrame.refresh do
		local f = frame.optionFrame.refresh[i] 
		if f.type == "SLIDER" then
			f.refresh = true
			f:SetValue(f.func() or 1)
			f.refresh = nil
			f:CheckDisable()
		elseif f.type == "CHECKBUTTON" then
			f:SetChecked(f.func())
			f:CheckDisable()
		elseif f.type == "COLORPICKER" then
			f:SetBackdropColor(unpack(f.func()))
			f:CheckDisable()
		elseif f.type == "DROPDOWN" then
			f.text:SetText(f.values[f.func() or 1].text or "")
			f:CheckDisable()
		elseif f.type == "EDITBOX" then
			f:SetText(f.func() or "")
			f:CheckDisable()
		elseif f.type == "RADIOBUTTON" then
			for i = 1, #f do
				for i = 1, #f do
					if i ~= f.func() then
						f[i]:SetChecked(nil)
					else
						f[i]:SetChecked(true)
					end
					f[i]:CheckDisable()
				end
			end
		end
	end
end
function opt:AddCheckFunc(f, v, func)
	if v.disable then
		f.CheckDisable = function()
			if v:disable() then
				if v.type == "DROPDOWN" then
					getglobal(f:GetName().."Button"):EnableMouse(nil)
				elseif v.type == "COLORPICKER" then
					if f.resetbtn then
						f.resetbtn:EnableMouse(nil)
						f.resetbtn:SetAlpha(0.4)
					end
				elseif v.type == "SLIDER" then
					f.inputbox:EnableMouse(nil)
					f.inputbox:SetTextColor(0.8,0.8,0.8)
				end
				f:EnableMouse(nil)
				f:SetAlpha(0.4)
				f.titleText:SetVertexColor(0.6,0,0)
			else
				if v.type == "DROPDOWN" then
					getglobal(f:GetName().."Button"):EnableMouse(true)
				elseif v.type == "COLORPICKER" then
					if f.resetbtn then
						f.resetbtn:EnableMouse(true)
						f.resetbtn:SetAlpha(1)
					end
				elseif v.type == "SLIDER" then
					f.inputbox:EnableMouse(true)
					f.inputbox:SetTextColor(1,1,0)
				end
				f:EnableMouse(true)
				f:SetAlpha(1)
				f.titleText:SetVertexColor(1,1,1)
			end
		end
	else
		f.CheckDisable = function() end
	end
end
function opt:CreateObject(frame, value)
	self.frame = frame
	frame.refresh = {}
	frame.refreshcount = 0
	frame.obj = {}
	frame.count = 0
	frame.radiogroup = {}
	frame.radiogroupcount = 0
	frame.dropdowncount = 0
	frame.dropdowndata = {}
	frame.inputcount = 0
	for _,v in pairs(value) do
		v.type = strupper(v.type) or nil
		local localframe = opt:CreateOptBase()
		if v.type == "TITLE" then
			self:CreateFont(v, localframe, true)
			self:gra(localframe,0.25,0.75,0.5,0.2,0.25,0.75,0.25,0.6, 0,true)
		elseif v.type == "SLIDER" then
			local slider = CreateFrame("Slider", "T_OPT"..frame.id.."-SLIDER-"..frame.count, localframe, "OptionsSliderTemplate")
			slider.titleText = self:CreateFont(v, localframe)
			slider:SetPoint("RIGHT", localframe, "RIGHT", -30,0)
			slider:SetMinMaxValues(unpack(v.minmax))
			slider:SetValueStep(v.step)
			slider:SetValue(v:get())
			slider.format = "%"..(strlen(v.step) > 1 and (strlen(v.step)-2)/10 or 0.1).."f"

			slider.inputbox = CreateFrame("EDITBOX", "T_OPT"..frame.id.."-SLIDER_INPUT-"..frame.inputcount, frame)
			slider.inputbox:ClearAllPoints()
			slider.inputbox:SetPoint("RIGHT", slider, "LEFT", -30, 0)
			slider.inputbox:SetWidth(40)
			slider.inputbox:SetHeight(self.baseHeight)
			slider.inputbox:SetAutoFocus(nil)
			slider.inputbox:SetTextColor(1,1,0)
			slider.inputbox:SetFontObject("ChatFontNormal")
			slider.inputbox:SetScript("OnEditFocusLost", function() this:HighlightText(0, 0) end)
			slider.inputbox:SetScript("OnEditFocusGained", function() this:HighlightText() end)

			local getv = function(val)
				if not select(2, strsplit(".", val)) then
					return val
				else
					return format(slider.format,val)
				end
			end
			slider.inputbox:SetText(getv(tonumber(slider:GetValue())))
			slider.inputbox:SetScript("OnEscapePressed", function()
				this:SetText(getv(tonumber(slider:GetValue())) or "")
				this:ClearFocus()
			end)

			slider.inputbox:SetScript("OnEnterPressed", function()
				if type(tonumber(this:GetText())) ~= "number" then 
					slider:SetValue(slider:GetValue())
					this:ClearFocus()
					return 
				end
				slider:SetValue(getv(tonumber(this:GetText())))
				this:ClearFocus()
			end)

			local left = CreateFrame("Frame", nil, slider)
			local right = CreateFrame("Frame", nil, slider)
			
			for i = 1, 2 do
				local btn = i == 1 and left or right
				btn:SetWidth(20)
				btn:SetHeight(10)
				self:Backdrop(btn, nil, "", 0, 0)
				btn:SetBackdropColor(0, 0, 0, 0)
				btn:EnableMouse(true)
				self:SetOnEnter(btn, v.tooltip..(i == 1 and " -" or " +")..v.step, function() slider[i == 1 and "lowtext" or "hightext"]:SetVertexColor(0,1,0,1) end)
				self:SetOnLeave(btn, function() slider[i == 1 and "lowtext" or "hightext"]:SetVertexColor(1,1,1,1) end)
				btn:SetScript("OnMouseDown", function()	slider:SetValue(slider:GetValue() + (i == 1 and -v.step or v.step)) end)
			end
			left:SetPoint("RIGHT", slider, "LEFT", 0, 0)			
			right:SetPoint("LEFT", slider, "RIGHT", 0, 0)

			slider.hightext = getglobal(slider:GetName().."High")
			slider.lowtext = getglobal(slider:GetName().."Low")
			slider.lowtext:ClearAllPoints()
			slider.lowtext:SetPoint("RIGHT", left)
			slider.lowtext:SetText(v.minmax[1])
			slider.hightext:ClearAllPoints()
			slider.hightext:SetPoint("LEFT", right)
			slider.hightext:SetText(v.minmax[2])

			self:SetOnEnter(slider, v.tooltip)
			self:SetOnLeave(slider)
			slider:SetScript("OnValueChanged", function ()
				if not this.refresh then
					v.set(this:GetValue())
				end
				this.inputbox:SetText(getv(tonumber(this:GetValue())))
			end)
			self:SetRefresh(slider, v)
			self:AddCheckFunc(slider, v)
		elseif v.type == "CHECKBUTTON" then
			local btn = CreateFrame("CheckButton", nil, localframe, "UICheckButtonTemplate")
			btn.titleText = self:CreateFont(v, localframe)
			btn:SetPoint("RIGHT", localframe)
			btn:SetChecked(v:get())
			self:SetOnEnter(btn, v.tooltip)
			self:SetOnLeave(btn)
			btn:SetScript("OnClick", function()
				v.set(this:GetChecked())
			end)
			self:SetRefresh(btn, v)
			self:AddCheckFunc(btn, v)
		elseif v.type == "RADIOBUTTON" then
			frame.radiogroupcount = frame.radiogroupcount + 1
			frame.radiogroup[frame.radiogroupcount] = {}
			local f = frame.radiogroup[frame.radiogroupcount]
			local titleText = self:CreateFont(v, localframe)
			local count = 1
			local col = v.col or 2
			for i = 1, ceil(#v.values/col) do
				localframe = opt:CreateOptBase(frame)
				for j = 1, col do
					if count <= #v.values then
						f[count] = CreateFrame("CheckButton", "T_OPT"..frame.id.."-"..frame.radiogroupcount.."-RADIO-"..count, localframe, "UIRadioButtonTemplate")
						f[count].text = getglobal(f[count]:GetName().."Text")
						f[count].text:SetText(v.values[count])
						f[count].grp = frame.radiogroupcount
						f[count].id = count
						f[count].titleText = titleText
						f[count]:SetPoint("LEFT", localframe, "LEFT", (j-1)*(localframe:GetWidth()/col)+20, 0)
						self:SetOnEnter(f[count], v.tooltips and v.tooltips[count] or "")
						self:SetOnLeave(f[count])
						f[count]:SetScript("OnClick", function()
							for i = 1, #f do
								if i ~= this.id then
									f[i]:SetChecked(nil)
									f[i].text:SetTextColor(1,0.8,0)
								else
									f[i]:SetChecked(true)
									f[i].text:SetTextColor(1,1,0)
								end
							end
							v.set(this.id)
						end)
						self:AddCheckFunc(f[count], v)
						count = count + 1
					end
				end
			end
			self:SetRefresh(f, v)
			f[v:get()]:SetChecked(true)
			f[v:get()].text:SetTextColor(1,1,0)
		elseif v.type == "COLORPICKER" then
			local pickerBG =  CreateFrame("Frame", nil, localframe)
			local picker = CreateFrame("Button", nil, localframe)
			picker.titleText = self:CreateFont(v, localframe)
			picker:SetWidth(16)
			picker:SetHeight(16)
			picker:SetPoint("RIGHT", localframe, "RIGHT",-10, 0)
			pickerBG:SetWidth(24)
			pickerBG:SetHeight(24)
			self:Backdrop(pickerBG, "Interface/Tooltips/UI-Tooltip-Background")
			pickerBG:SetBackdropColor(0,0,0,0.3)
			pickerBG:SetPoint("CENTER", picker)
			self:Backdrop(picker, nil, "", nil, 0)
			picker:SetBackdropColor(unpack(v:get()))
			if v.default then
				picker.resetbtn = CreateFrame("Frame", nil, localframe)
				picker.resetbtn:SetWidth(60)
				picker.resetbtn:SetHeight(24)
				picker.resetbtn.text = picker.resetbtn:CreateFontString(nil, "OVERLAY","ChatFontNormal")
				picker.resetbtn.text:SetPoint("CENTER", picker.resetbtn)
				picker.resetbtn.text:SetText("초기화")
				picker.resetbtn:SetPoint("RIGHT", picker, "LEFT", -25, 0)
				picker.resetbtn:EnableMouse(true)
				self:SetOnEnter(picker.resetbtn, "색상을 초기화 합니다", function() this.text:SetVertexColor(1,1,0,1) end)
				self:SetOnLeave(picker.resetbtn, function() this.text:SetVertexColor(1,1,1,1) end)
				picker.resetbtn:SetScript("OnMouseDown", function()
					self:ClearColorFunc()
					picker:SetBackdropColor(unpack(v.default))
					v.set({r = v.default[1], g = v.default[2], b = v.default[3], a = v.default[4]})
				end)
				self:Backdrop(picker.resetbtn, "Interface/Tooltips/UI-Tooltip-Background")
				picker.resetbtn:SetBackdropColor(unpack(v.default))
			end
			self:SetOnEnter(picker, v.tooltip)
			self:SetOnLeave(picker)
			picker:SetScript("OnClick", function()
				--self:ClearColorFunc()
				ColorPickerFrame:Hide()
				ColorPickerFrame.func = function() end
				self.picker = picker
				local r,g,b,a = unpack(v:get())
				ColorPickerFrame:SetColorRGB(r, g, b)
				picker.previousValues = {r = r, g = g, b = b, a = a}
				ColorPickerFrame.hasOpacity = nil
				if v.hasOpacity then
					ColorPickerFrame.opacity = 1 - a
					ColorPickerFrame.hasOpacity = true
					ColorPickerFrame.opacityFunc = function()
						local color = {ColorPickerFrame:GetColorRGB()}
						self.picker:SetBackdropColor(color[1], color[2], color[3], 1 - OpacitySliderFrame:GetValue())
						v.set({r = color[1], g = color[2], b = color[3], a = 1 - OpacitySliderFrame:GetValue()})
						--self:ClearColorFunc(true)
					end
				end
				ColorPickerFrame.func = function()
					local alpha = v.hasOpacity and 1 - OpacitySliderFrame:GetValue() or 1
					local color = {ColorPickerFrame:GetColorRGB()}
					self.picker:SetBackdropColor(color[1], color[2], color[3], alpha)
					v.set({r = color[1], g = color[2], b = color[3], a = alpha})
					--self:ClearColorFunc(true)
				end
				ColorPickerFrame.cancelFunc = function()
					self.picker:SetBackdropColor(picker.previousValues.r,
								picker.previousValues.g,
								picker.previousValues.b,
								picker.previousValues.a)
					v.set(picker.previousValues)
					--self:ClearColorFunc()
				end
				ColorPickerFrame:Show()
			end)
			self:SetRefresh(picker, v)
			self:AddCheckFunc(picker, v)
		elseif v.type == "DROPDOWN" then
			frame.dropdowncount = frame.dropdowncount + 1
			local dropdown = CreateFrame("Frame", "T_OPT"..frame.id.."-DROPDOWN-"..frame.dropdowncount, localframe, "UIDropDownMenuTemplate")
			dropdown.titleText = self:CreateFont(v, localframe)
			dropdown:SetPoint("RIGHT", localframe, "RIGHT", -115, 0)
			dropdown.text = getglobal(dropdown:GetName().."Text")
			local function init()
				for k, value in pairs(v.values) do
					value.func = function ()
						UIDropDownMenu_SetSelectedValue(dropdown, this.value)
						v.set(k)
					end
					value.checked = v:get() == k and true or nil
					UIDropDownMenu_AddButton(value)
				end
			end
			if v:get() then
				dropdown.text:SetText(v.values[v:get()].text)
			end
			dropdown.text:SetFontObject(GameFontNormalSmall)
			UIDropDownMenu_Initialize(dropdown, init)
			dropdown.button = getglobal(dropdown:GetName().."Button")
			self:SetOnEnter(dropdown.button, v.tooltip)
			self:SetOnLeave(dropdown.button)
			self:SetRefresh(dropdown, v)
			self:AddCheckFunc(dropdown, v)
		elseif v.type == "EDITBOX" then
			frame.inputcount = frame.inputcount + 1
			local input = CreateFrame("EDITBOX", "T_OPT"..frame.id.."-INPUT-"..frame.inputcount, frame, "InputBoxTemplate")
			input.titleText = self:CreateFont(v, localframe)
			input:SetPoint("RIGHT", localframe, "RIGHT", -10, 0)
			input:SetWidth(200)
			input:SetHeight(self.baseHeight)
			input:SetText(v:get() or "")
			input:SetAutoFocus(nil)
			input:SetScript("OnEscapePressed", function()
				this:SetText(v:get() or "")
				this:ClearFocus()
			end)
			input:SetScript("OnEnterPressed", function()
				v.set(this:GetText())
				this:ClearFocus()
			end)
			self:SetRefresh(input, v)
			self:AddCheckFunc(input, v)
		end
	end
	frame:SetWidth(frame.count*self.baseHeight)
	self:Refresh(frame.id)
end

function opt:RegesterOption(info)
	if not info.Header then return end
	local id, frame = self:CreateHeader(info.Header)
	self:CreateObject(frame, info.option)
	return id
end

function opt:Insert(v)
	tinsert(self.options, v)
end

function opt:OptionCall()
	for i = 1, #self.options do
		if IsAddOnLoaded(self.options[i]) then
			getglobal(self.options[i].."_OptionInit")()
		end
	end
end