local _G = getfenv(0)

function Skinner:Dewdrop()

	self:SecureHook(AceLibrary("Dewdrop-2.0"), "Open", function(parent, ...)
--		self:Debug("DewdropOpen: [%s]", parent)
		self:Skin_Dewdrop()
		end)
	
	self:Skin_Dewdrop()

end

local dewdropsSkinned = {}

function Skinner:Skin_Dewdrop()
	if not self.db.profile.Tooltips.skin then return end

--	self:Debug("Skin_Dewdrop")

	local i = 1
	while _G["Dewdrop20Level"..i] do
--		self:Debug("Dewdrop20Level"..i)
		local frame = _G["Dewdrop20Level"..i]
		if not dewdropsSkinned["Dewdrop20Level"..i] then
			dewdropsSkinned["Dewdrop20Level"..i] = true
			frame:SetBackdropColor(self.db.profile.Backdrop.r, self.db.profile.Backdrop.g, self.db.profile.Backdrop.b, self.db.profile.Backdrop.a)
			self:applySkin(frame)
			-- hook this to stop the Backdrop colours from being changed 
			self:Hook(frame, "SetBackdropColor", function(r, g, b, a) end, true)
			-- hide the backdrop frame
			self:getChild(frame, 1):Hide()
		end
		i = i + 1
		frame.tfade:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -4, -math.ceil(frame:GetHeight()))
	end
	
	-- hook the OnEnter script for the buttons and use that to skin from
	local i = 1
	while _G["Dewdrop20Button"..i] do
--		self:Debug("DB found: [%s]", i)
		if not self:IsHooked(_G["Dewdrop20Button"..i], "OnEnter") then
			self:HookScript(_G["Dewdrop20Button"..i], "OnEnter", "DB_OnEnter")
		end
		i = i + 1
	end
	
end

function Skinner:DB_OnEnter()
--	self:Debug("DB_OnEnter: [%s]", this:GetName())

	self.hooks[this].OnEnter()
	
	if not this.disabled then
		if this.hasSlider then
--			self:Debug("DB has Slider: [%s]", this:GetName())
			self:applySkin(sliderFrame)
		elseif this.hasEditBox then
--			self:Debug("DB has EditBox: [%s]", this:GetName())
			self:applySkin(editBoxFrame)
--			self:skinEditBox(editBoxFrame.editBox)
		elseif this.hasArrow then
--			self:Debug("DB has Arrow: [%s]", this:GetName())
			self:Skin_Dewdrop()
		end
	end

end
