local _G = getfenv(0)

function Skinner:XPerl_Options()
--	self:Debug("XPerl_Options")

--Config                             
	self:keepRegions(XPerl_Options_Party_Anchor, {4,5}) -- N.B. regions 4 & 5 are text
	self:keepRegions(XPerl_Options_Raid_Anchor, {4,5}) -- N.B. regions 4 & 5 are text
    self:keepRegions(XPerl_Options_DropDown_LoadSettings, {4,5}) -- N.B. regions 4 & 5 are text
	XPerl_Options_Player_Gap:SetWidth(XPerl_Options_Player_Gap:GetWidth() - 10)
	self:moveObject(XPerl_Options_Player_Gap, "-", 10, "+", 0)
	self:moveObject(XPerl_Options_Player_BiggerGap, "+", 4, "+", 0)
	self:skinEditBox(XPerl_Options_Player_Gap)
	self:moveObject(XPerl_Options_Party_Gap, "-", 6, "+", 0)
	self:moveObject(XPerl_Options_Party_BiggerGap, "+", 6, "+", 0)
	self:skinEditBox(XPerl_Options_Party_Gap)
	XPerl_Options_Raid_Gap:SetWidth(XPerl_Options_Raid_Gap:GetWidth() - 10)
	self:moveObject(XPerl_Options_Raid_Gap, "-", 10, "+", 0)
	self:moveObject(XPerl_Options_Raid_BiggerGap, "+", 4, "+", 0)
	self:skinEditBox(XPerl_Options_Raid_Gap)

	self:applySkin(XPerl_ColourPicker)
	self:applySkin(XPerl_Options_TextureSelect)
	self:applySkin(XPerl_OptionsQuestionDialog)
	self:keepRegions(XPerl_Options_Title, {1})
	self:applySkin(XPerl_Options)

	-- hook these to stop the colour changing
	self:HookScript(XPerl_ColourPicker, "OnShow", function() end)
	self:HookScript(XPerl_Options_TextureSelect, "OnShow", function() end)
	self:HookScript(XPerl_OptionsQuestionDialog, "OnShow", function() end)
	self:HookScript(XPerl_Options, "OnShow", function() end)
	
end
     
function Skinner:XPerl_Player()
--	self:Debug("XPerl_Player")

--Player
	self:applySkin(XPerl_PlayerportraitFrame)
	self:applySkin(XPerl_PlayernameFrame)
	self:applySkin(XPerl_PlayerlevelFrame)
	self:applySkin(XPerl_PlayerclassFrame)
	self:applySkin(XPerl_PlayerstatsFrame)
	self:applySkin(XPerl_PlayergroupFrame)

end

function Skinner:XPerl_Target()
--	self:Debug("XPerl_Target")

--Target
	self:applySkin(XPerl_TargetnameFrame)
	self:applySkin(XPerl_TargetportraitFrame)
	self:applySkin(XPerl_TargetlevelFrame)
	self:applySkin(XPerl_TargetcreatureTypeFrame)
	self:applySkin(XPerl_TargettypeFramePlayer)
	self:applySkin(XPerl_TargetbossFrame)
	self:applySkin(XPerl_TargetstatsFrame)
	XPerl_TargeteliteFrame:SetAlpha(0)

	XPerl_TargetnameFrame:SetFrameLevel(XPerl_TargetnameFrame:GetFrameLevel() + 1)
	
	-- use text label
	XPerlConfig.ShowTargetElite = 1

--Focus
	self:applySkin(XPerl_FocusnameFrame)
	self:applySkin(XPerl_FocusportraitFrame)
	self:applySkin(XPerl_FocuslevelFrame)
	self:applySkin(XPerl_FocustypeFramePlayer)
	self:applySkin(XPerl_FocusbossFrame)
	self:applySkin(XPerl_FocuscreatureTypeFrame)
	self:applySkin(XPerl_FocusstatsFrame)
	XPerl_FocuseliteFrame:SetAlpha(0)
	
	-- use text label
	XPerlConfig.ShowFocusElite = 1
	
end

function Skinner:XPerl_TargetTarget()
--	self:Debug("XPerl_TargetTarget")

--TargetTarget
	self:applySkin(XPerl_TargetTargetnameFrame)
	self:applySkin(XPerl_TargetTargetlevelFrame)
	self:applySkin(XPerl_TargetTargetstatsFrame)
	self:applySkin(XPerl_TargetTargetTargetnameFrame)
	self:applySkin(XPerl_TargetTargetTargetlevelFrame)
	self:applySkin(XPerl_TargetTargetTargetstatsFrame)

end
 
function Skinner:XPerl_Party()
--	self:Debug("XPerl_Party")

--Party
	self:applySkin(XPerl_party1portraitFrame)
	self:applySkin(XPerl_party2portraitFrame)
	self:applySkin(XPerl_party3portraitFrame)
	self:applySkin(XPerl_party4portraitFrame)
	self:applySkin(XPerl_party1nameFrame)
	self:applySkin(XPerl_party2nameFrame)
	self:applySkin(XPerl_party3nameFrame)
	self:applySkin(XPerl_party4nameFrame)
	self:applySkin(XPerl_party1levelFrame)
	self:applySkin(XPerl_party2levelFrame)
	self:applySkin(XPerl_party3levelFrame)
	self:applySkin(XPerl_party4levelFrame)
	self:applySkin(XPerl_party1statsFrame)
	self:applySkin(XPerl_party2statsFrame)
	self:applySkin(XPerl_party3statsFrame)
	self:applySkin(XPerl_party4statsFrame)

--Party Target
	self:applySkin(XPerl_party1targetFrame)
	self:applySkin(XPerl_party2targetFrame)
	self:applySkin(XPerl_party3targetFrame)
	self:applySkin(XPerl_party4targetFrame)

end
	
function Skinner:XPerl_PlayerPet()
--	self:Debug("XPerl_PlayerPet")

--Player Pet
	self:applySkin(XPerl_Player_PetportraitFrame)
	self:applySkin(XPerl_Player_PetnameFrame)
	self:applySkin(XPerl_Player_PetlevelFrame)
	self:applySkin(XPerl_Player_PethappyFrame)
	self:applySkin(XPerl_Player_PetstatsFrame)

end
        
function Skinner:XPerl_PartyPet()
--	self:Debug("XPerl_PartyPet")

--Party Pet
	self:applySkin(XPerl_partypet1nameFrame)
	self:applySkin(XPerl_partypet2nameFrame)
	self:applySkin(XPerl_partypet3nameFrame)
	self:applySkin(XPerl_partypet4nameFrame)
	self:applySkin(XPerl_partypet1statsFrame)
	self:applySkin(XPerl_partypet2statsFrame)
	self:applySkin(XPerl_partypet3statsFrame)
	self:applySkin(XPerl_partypet4statsFrame)
end

function Skinner:XPerl_RaidHelper()
--	self:Debug("XPerl_RaidHelper")

	self:applySkin(XPerl_Frame)
	self:applySkin(XPerl_Assists_Frame)
	self:applySkin(XPerl_Player_TargettingFrame)
	self:applySkin(XPerl_Target_AssistFrame)

	self:skinTanks()
	self:SecureHook("XPerl_MTRosterChanged", "skinTanks")
	
	self:skinRaid()
	self:SecureHook("XPerl_RaidTitles", "skinRaid")

end

function Skinner:XPerl_RaidMonitor()
--	self:Debug("XPerl_RaidMonitor")

	self:applySkin(XPerl_RaidMonitor_Frame)

end

function Skinner:XPerl_RaidAdmin()
--	self:Debug("XPerl_RaidAdmin")

	self:applySkin(XPerl_AdminFrame)

end

function Skinner:XPerl_RaidPets()
--	self:Debug("XPerl_RaidPets")

	self:skinRaidPets()
	self:SecureHook("XPerl_RaidPets_Titles", "skinRaidPets")
	
end

function Skinner:skinTanks()

	for i = 1, XPerlConfigHelper.MaxMainTanks do
		local MTTUB = _G["XPerl_MTTargetsUnitButton"..i]
		if MTTUB and not MTTUB.skinned then 
			self:applySkin(MTTUB) 
			self:applySkin(_G[MTTUB:GetName().."Target"]) 
			self:applySkin(_G[MTTUB:GetName().."TargetTarget"])
			MTTUB.skinned = true 
		end
	end
	
end

function Skinner:skinRaid()

	for i = 1, 9 do
		for j = 1, 5 do
			local XPRGUB = _G["XPerl_Raid_Grp"..i.."UnitButton"..j]
			if XPRGUB and not XPRGUB.skinned then
				self:applySkin(_G[XPRGUB:GetName().."nameFrame"])
				self:applySkin(_G[XPRGUB:GetName().."statsFrame"])
				XPRGUB.skinned = true
			end
		end
	end

end

function Skinner:skinRaidPets()

	for i = 1, GetNumRaidMembers() do
		local XPRGPUB = _G["XPerl_Raid_GrpPetsUnitButton"..i]
		if XPRGPUB and not XPRGPUB.skinned then
			self:applySkin(XPRGPUB) 
			XPRGPUB.skinned = true
		end
	end

end
