local GlobalAddonName, BH = ...

local GetTime, IsEncounterInProgress, RAID_CLASS_COLORS, GetInstanceInfo, GetSpellCharges, CombatLogGetCurrentEventInfo = GetTime, IsEncounterInProgress, RAID_CLASS_COLORS, GetInstanceInfo, GetSpellCharges, CombatLogGetCurrentEventInfo
local string_gsub, wipe, tonumber, pairs, ipairs, string_trim, format, floor, ceil, abs, type, sort = string.gsub, table.wipe, tonumber, pairs, ipairs, string.trim, format, floor, ceil, abs, type, sort
local UnitIsDeadOrGhost, UnitIsConnected, UnitName, UnitCreatureFamily, UnitIsDead, UnitIsGhost, UnitGUID, UnitInRange, UnitIsWarModeActive = UnitIsDeadOrGhost, UnitIsConnected, UnitName, UnitCreatureFamily, UnitIsDead, UnitIsGhost, UnitGUID, UnitInRange, UnitIsWarModeActive

local RaidInCombat, ClassColorNum, GetDifficultyForCooldownReset, DelUnitNameServer, NumberInRange = BH.F.RaidInCombat, BH.F.classColorNum, BH.F.GetDifficultyForCooldownReset, BH.F.delUnitNameServer, BH.F.NumberInRange
local GetEncounterTime, UnitCombatlogname, GetUnitInfoByUnitFlag, ScheduleTimer, CancelTimer, GetRaidDiffMaxGroup, table_wipe2, dtime = BH.F.GetEncounterTime, BH.F.UnitCombatlogname, BH.F.GetUnitInfoByUnitFlag, BH.F.ScheduleTimer, BH.F.CancelTimer, BH.F.GetRaidDiffMaxGroup, BH.F.table_wipe, BH.F.dtime

local GetSpellLevelLearned = GetSpellLevelLearned

local VBH, VBH_CDE = nil

local module = BH:New("ExCD2",BH.L.cd2)
local BHLib,L = BH.lib,BH.L

module._C = {}
module.db.bhspellDB = {
{ 31821,	"PALADIN",					nil, 	  {31821,180,8},			    nil,			    nil,							},	--Владение аурами
{ 31884,    "PALADIN",					nil,   	 {31884,120,20},	            nil,			    nil,							},	--Гнев карателя
{ 62618,	 "PRIEST",					nil,	 {62618,180,10},			    nil,	   		    nil,							},	--Слово силы: Барьер
{271466,     "PRIEST",					nil,	 {271466,180,0},				nil,				nil,							},	--Luminous Barrier
{ 64843,	 "PRIEST",					nil,				nil,	  {64843,180,8},				nil,							},	--Божественный гимн
{265202,     "PRIEST",					nil,				nil,	 {265202,720,0},				nil,							},	--Holy Word: Salvation
{ 98008,	 "SHAMAN",					nil,				nil,			    nil,      {98008,180,6},							},	--Тотем духовной связи
{108280,     "SHAMAN",					nil,				nil,				nil,	{108280,180,10},							},	--Тотем целительного прилива
{115310,       "MONK",					nil,				nil,				nil,	 {115310,180,0},							},	--Восстановление сил
{   740,      "DRUID",					nil,				nil,				nil,				nil,  		{740,180,8},		},	--Спокойствие
{ 33891,      "DRUID",					nil,				nil,				nil,				nil,  	 {33891,180,30},		},	--Спокойствие
{ 97462,	"WARRIOR",	     {97462,180,10},				nil,			    nil,			    nil,							},	--Ободряющий клич
{196718,"DEMONHUNTER",					nil, 	 {196718,180,8},				nil,												},	--Мрак=
{ 20707,	"WARLOCK",		  {20707,600,0},				nil,				nil,				nil,							},	--Камень души
--{  id,	    class,		      all specs,		      spec1, spec2={spellid,cd,duration},      spec3,          spec4		    },	--name

}

local encounterID = L.encounterID -- pour forcer le reset sur skitra
module.db.bhCmirror = module._C
module.db.bhdbCountDef = #module.db.bhspellDB
module.db.bhclassNames = BH.GDB.ClassList

module.db.bhspecByClass = {}
for class,classData in pairs(BH.GDB.ClassSpecializationList) do -- a supp BH.GDB.ClassSpecializationList
	local newData = {0}
	for i=1,#classData do
		newData[#newData + 1] = classData[i]
	end
	module.db.bhspecByClass[class] = newData
end

module.db.bhspecInDBase = {
	[71] = 4,	[72] = 5,	[73] = 6,
	[65] = 4,	[66] = 5,	[70] = 6,
	[256] = 4,	[257] = 5,	[258] = 6,
	[265] = 4,	[266] = 5,	[267] = 6,
	[250] = 4,	[251] = 5,	[252] = 6,
	[102] = 4,	[103] = 5,	[104] = 6,	[105] = 7,
	[268] = 4,	[269] = 5,	[270] = 6,
	[262] = 4,	[263] = 5,	[264] = 6,
	[577] = 4,	[581] = 5,
	[0] = 3,
}
module.db.bhspell_talentsList = {}  -- supp dans inspect ???
module.db.bhtestMode = nil
module.db.bhisEncounter = nil

local cdsNav_wipe,cdsNav_set = nil
do
	local cdsNavData = {}
	local nilData = {}
	module.db.bhcdsNav = setmetatable({}, {
		__index = function (t,k) 
			return cdsNavData[k] or nilData
		end
	})
	function cdsNav_wipe()
		wipe(cdsNavData)
	end
	function cdsNav_set(playerName,spellID,pos)
		local e = cdsNavData[playerName]
		if not e then
			e = {}
			cdsNavData[playerName] = e
		end
		e[spellID] = pos
	end
end

do
	local sessionData = {}
	local nilData = {}
	module.db.bhsession_gGUIDs = setmetatable({}, {
		__index = function (t,k) 
			return sessionData[k] or nilData
		end,
		__newindex = function (t,k,v)
			local e = sessionData[k]
			if not e then
				e = {}
				sessionData[k] = e
			end
			local reason = true
			if type(v) == 'table' then
				reason = v[2]
				v = v[1]
			end
			if v > 0 then
				e[v] = reason
			else
				e[-v] = nil
			end
		end
	})	
	module.db.bhsession_gGUIDs_DEBUG = sessionData

	function module:ClearSessionDataReason(name,reason1,reason2,reason3,reason4)
		local e = sessionData[name]
		if not e then
			return
		end
		for k,v in pairs(e) do
			if v == reason1 or v == reason2 or v == reason3 or v == reason4 then
				e[k] = nil
			end
		end
	end
end

module.db.bhspell_isTalent = {
		[271466]=true,	
		[265202]=true,	
		[33891]=true,	
}

module.db.bhspell_isAzeriteTalent = {} -- utilise reset cd htt

module.db.bhspell_durationByTalent_fix = {	--Изменение длительности талантом\глифом   вид: [спелл] = {spellid глифа\таланта, изменение времени (-10;10;*0.5;*1.5)}	
	[31884] = {286229,5,53376,"*1.25"},
}

module.db.bhspell_cdByTalent_fix = {		--Изменение кд талантом\глифом   вид: [спелл] = {spellid глифа\таланта, изменение времени (-60;60);spellid2,time2;spellid3,time3;...}	
	[740] = {197073,-60,296320,"*0.80"},
	[64843] = {296320,"*0.80"},
	[31884] = {296320,"*0.80"},
	[108280] = {296320,"*0.80"}, -- ha???
	[115310] = {296320,"*0.80"},
}
module.db.bhspell_cdByTalent_scalable_data = {  -- au cas ou pour shadowland
	[296320] = {
		[1] = "*0.80",
	},
}
module.db.bhspell_cdByTalent_isScalable = { -- au cas ou pour shadowland
	[296320] = true,
}
module.db.bhtierSetsSpells = {}	--[specID.tierID.tierMark] = {2P Bonus Spell ID, 4P Bonus Spell ID}
module.db.bhtierSetsList = {}	-- [itemID] = specID.tierID.tierMark

module.db.bhspell_talentReplaceOther = {		--Спелы, показ которых нужно убрать при наличии таланта (талант заменяет эти спелы) [spellID] = [talent Spell ID]
	[62618]=271466,
}

module.db.bhspell_speed_list = {		--Спелы, которым менять время действия на основании спелхасты
	[740]=true,
	[64843]=true,
}
module.db.bhspell_afterCombatReset = {	--Принудительный сброс кд после боя с боссом (для спелов с кд менее 5 мин., 3мин после 6.1)
	[31884]=true,
}

module.db.bhspell_runningSameSpell = {}	--même nom de spell

do
	local sameSpellsData = {
		{295373,299349,299353},	--The Crucible of Flame
		{295186,298628,299334},	--Worldvein Resonance
		{302731,302982,302983},	--Ripple in Space
		{298357,299372,299374},	--Memory of Lucid Dreams
		{293019,298080,298081},	--Azeroth's Undying Gift
		{294926,300002,300003},	--Anima of Life and Death
		{298168,299273,299275},	--Aegis of the Deep
		{295746,300015,300016},	--Nullification Dynamo
		{293031,300009,300010},	--Sphere of Suppression
		{296197,299932,299933},	--The Well of Existence
		{296094,299882,299883},	--Artifice of Time
		{293032,299943,299944},	--Life-Binder's Invocation
		{296072,299875,299876},	--The Ever-Rising Tide
		{296230,299958,299959},	--Vitality Conduit
		{295258,299336,299338},	--Essence of the Focusing Iris
		{295840,299355,299358},	--Condensed Life-Force
		{297108,298273,298277},	--Blood of the Enemy
		{295337,299345,299347},	--Purification Protocol
		{298452,299376,299378},	--The Unbound Force
	}
	for i=1,#sameSpellsData do
		local list = sameSpellsData[i]
		for j=1,#list do
			module.db.bhspell_runningSameSpell[ list[j] ] = list
		end
	end
end

module.db.bhspell_startCDbyAuraApplied = {	--Заклинания, кд которых запускается только при наложении ауры (вида [aura_spellID] = CD_spellID)
	[117679]=33891,
}
module.db.bhspell_startCDbyAuraApplied_fix = {}
for _,spellID in pairs(module.db.bhspell_startCDbyAuraApplied) do module.db.bhspell_startCDbyAuraApplied_fix[spellID] = true end

module.db.bhspell_battleRes = {		--sort de rez "pierre demo"
	[20707]=true,
}
module.db.bhisResurectDisabled = nil
module.db.bhspell_isRacial = {		--tableau appeller pour ne pas ajouter les racials
	[68992]="Worgen",[20589]="Gnome",[20594]="Dwarf",[121093]="Draenei",[59545]="Draenei",[59543]="Draenei",[59548]="Draenei",[59542]="Draenei",[59544]="Draenei",[59547]="Draenei",[28880]="Draenei",
	[58984]="NightElf",[107079]="Pandaren",[59752]="Human",[69041]="Goblin",[69070]="Goblin",[69046]="Goblin",[7744]="Undead",[20577]="Undead",[20572]="Orc",[33697]="Orc",[33702]="Orc",[20549]="Tauren",
	[26297]="Troll",[28730]="BloodElf",[69179]="BloodElf",[129597]="BloodElf",[80483]="BloodElf",[155145]="BloodElf",[25046]="BloodElf",[50613]="BloodElf",[202719]="BloodElf",[256948]="VoidElf",
	[260364]="Nightborne",[255647]="LightforgedDraenei",[255654]="HighmountainTauren",[274738]="MagharOrc",[265221]="DarkIronDwarf",
}

module.db.bhdef_col = {			--Стандартные положения в колонках
	["97462;1"]=1,["31821;2"]=1,["64843;3"]=1,["62618;2"]=1,["98008;4"]=1,["108280;4"]=1,["20707;1"]=1,["115310;4"]=1,["740;5"]=1,["196718;1"]=1,["265202;1"]=1,["31884;2"]=1,
	["31891;5"]=1,["271466;2"]=1,
}

module.db.bhplayerName = nil

module.db.bhplugin = {}

module.db.bhnotAClass = { r = 0.8, g = 0.8, b = 0.8, colorStr = "ffcccccc" }

local colorSetupFrameColorsNames = {"Default","Active","Cooldown"}
local colorSetupFrameColorsObjectsNames = {"Text","Background","TimeLine"}
local globalGUIDs = nil

module.db.bhmaxLinesInCol = 50
module.db.bhmaxColumns = 3

module.db.bhcolsDefaults = {
	iconSize = 16,
	iconGray = true,
	iconPosition = 1,
	textureFile = BH.F.barImg,
	textureBorderSize = 0,
	fontSize = 12,
	fontName = BH.F.defFont,
	frameLines = 15,
	frameAlpha = 100,
	frameScale = 100,
	frameWidth = 130,
	frameColumns = 1,
	frameBetweenLines = 0,
	frameBlackBack = 0,
	methodsStyleAnimation = 1,
	methodsTimeLineAnimation = 1,
	methodsSortingRules = 1,
	methodsAlphaNotInRangeNum = 90,
	
	textureBorderColorR = 0,	textureBorderColorG = 0,	textureBorderColorB = 0,	textureBorderColorA = 1,
	
	textureColorTextDefaultR = 1,	textureColorTextDefaultG = 1,	textureColorTextDefaultB = 1,
	textureColorTextActiveR = 1,	textureColorTextActiveG = 1,	textureColorTextActiveB = 1,
	textureColorTextCooldownR = 1,	textureColorTextCooldownG = 1,	textureColorTextCooldownB = 1,

	textureColorBackgroundDefaultR = 0,	textureColorBackgroundDefaultG = 1,	textureColorBackgroundDefaultB = 0,
	textureColorBackgroundActiveR = 0,	textureColorBackgroundActiveG = 1,	textureColorBackgroundActiveB = 0,
	textureColorBackgroundCooldownR = 1,	textureColorBackgroundCooldownG = 0,	textureColorBackgroundCooldownB = 0,

	textureColorTimeLineDefaultR = 0,	textureColorTimeLineDefaultG = 1,	textureColorTimeLineDefaultB = 0,
	textureColorTimeLineActiveR = 0,	textureColorTimeLineActiveG = 1,	textureColorTimeLineActiveB = 0,
	textureColorTimeLineCooldownR = 1,	textureColorTimeLineCooldownG = 0,	textureColorTimeLineCooldownB = 0,
	
	textureAlphaBackground = 0.3,
	textureAlphaTimeLine = 0.8,
	textureAlphaCooldown = 1,
	
	textureSmoothAnimationDuration = 50,
	
	textTemplateLeft = "%name%",
	textTemplateRight = "%time%",
	textTemplateCenter = "",
	
	blacklistText = "",
	whitelistText = "",
}

module.db.bhcolsInit = {
	iconGeneral = true,
	textureGeneral = true,
	methodsGeneral = true,
	frameGeneral = true,
	fontGeneral = true,
	textGeneral = true,
	blacklistGeneral = true,
	visibilityGeneral = true,
	
	iconGray = true,
	textureAnimation = true,
	
	fontOutline = true,
	fontShadow = false,
	
	--textureSmoothAnimation = true,
}

module.db.bhstatus_UnitsToCheck = {}
module.db.bhstatus_UnitIsDead = {}
module.db.bhstatus_UnitIsDisconnected = {}
module.db.bhstatus_UnitIsOutOfRange = {}

-- Local functions vaules; other upvaules

local UpdateAllData,SortAllData = nil
local SaveCDtoVar = nil
local CLEUstartCD = nil
local RaidResurrectSpecialCheck,RaidResurrectSpecialText,RaidResurrectSpecialStatus = nil

local L_Offline,L_Dead = L.cd2StatusOffline, L.cd2StatusDead
local _C, _db, _mainFrame = module._C, module.db

local status_UnitsToCheck,status_UnitIsDead,status_UnitIsDisconnected,status_UnitIsOutOfRange = module.db.bhstatus_UnitsToCheck,module.db.bhstatus_UnitIsDead,module.db.bhstatus_UnitIsDisconnected,module.db.bhstatus_UnitIsOutOfRange

do
	local frame = CreateFrame("Frame",nil,UIParent)
	module.frame = frame
	frame:SetPoint("CENTER",UIParent, "CENTER", 0, 0)
	frame:EnableMouse(true)
	frame:SetMovable(true)
	frame:RegisterForDrag("LeftButton")
	frame:SetScript("OnDragStart", function(self) 
		if self:IsMovable() then 
			self:StartMoving() 
		end 
	end)
	frame:SetScript("OnDragStop", function(self)
		self:StopMovingOrSizing()
		VBH.ExCD2.Left = self:GetLeft()
		VBH.ExCD2.Top = self:GetTop()
	end)
	frame.texture = frame:CreateTexture(nil, "BACKGROUND")
	frame.texture:SetColorTexture(0,0,0,0.3)
	frame.texture:SetAllPoints()
	module:RegisterHideOnPetBattle(frame)
	
	frame.colFrame = {}
	
	--upvaule
	_mainFrame = frame
end

local function BarUpdateText(self)
	local barParent = self.parent
		
	local textLeft = barParent.textTemplateLeft
	local textRight = barParent.textTemplateRight
	local textCenter = barParent.textTemplateCenter
	
	local barData = self.data

	local time = (self.curr_end or 0) - GetTime() + 1

	if barData.specialTimer then
		local newTime = barData.specialTimer()
		time = newTime and newTime+1 or time
	end
	
	local name = barData.name
	local spellName = barData.spellName
	
	local longtime,shorttime = nil
	
	if time > 3600 then
		longtime = "1+hour"
		shorttime = "1+hour"
	elseif time < 1 then
		longtime = ""
		shorttime = ""
	else
		longtime = format("%1.1d:%2.2d",time/60,time%60)
		if time < 11 then
			shorttime = format("%.01f",time - 1)
		elseif time < 60 then
			shorttime = format("%d",time)
		else
			shorttime = longtime
		end
	end
	
	if barData.specialAddText then
		name = name .. (barData.specialAddText() or "")
	end
	
	local name_time = time > 0.999 and longtime or name
	local name_stime = time > 0.999 and shorttime or name
	local offStatus = self.disStatus or ""
	local chargesCount = self.curr_charges and "("..self.curr_charges..")" or ""
	
	textLeft = string_gsub(textLeft,"%%time%%",longtime)
	textLeft = string_gsub(textLeft,"%%stime%%",shorttime)
	textLeft = string_gsub(textLeft,"%%name%%",name)
	textLeft = string_gsub(textLeft,"%%name_time%%",name_time)
	textLeft = string_gsub(textLeft,"%%name_stime%%",name_stime)
	textLeft = string_gsub(textLeft,"%%spell%%",spellName)
	textLeft = string_gsub(textLeft,"%%status%%",offStatus)
	textLeft = string_gsub(textLeft,"%%charge%%",chargesCount)
	textRight = string_gsub(textRight,"%%time%%",longtime)
	textRight = string_gsub(textRight,"%%stime%%",shorttime)
	textRight = string_gsub(textRight,"%%name%%",name)
	textRight = string_gsub(textRight,"%%name_time%%",name_time)
	textRight = string_gsub(textRight,"%%name_stime%%",name_stime)
	textRight = string_gsub(textRight,"%%spell%%",spellName)
	textRight = string_gsub(textRight,"%%status%%",offStatus)
	textRight = string_gsub(textRight,"%%charge%%",chargesCount)
	textCenter = string_gsub(textCenter,"%%time%%",longtime)
	textCenter = string_gsub(textCenter,"%%stime%%",shorttime)
	textCenter = string_gsub(textCenter,"%%name%%",name)
	textCenter = string_gsub(textCenter,"%%name_time%%",name_time)
	textCenter = string_gsub(textCenter,"%%name_stime%%",name_stime)
	textCenter = string_gsub(textCenter,"%%spell%%",spellName)
	textCenter = string_gsub(textCenter,"%%status%%",offStatus)
	textCenter = string_gsub(textCenter,"%%charge%%",chargesCount)
	
	self.textLeft:SetText(string_trim(textLeft))
	self.textRight:SetText(string_trim(textRight))
	self.textCenter:SetText(string_trim(textCenter))

	if barParent.optionIconName then
		self.textIcon:SetText(barData.name)
	end
end

local function BarAnimation(self)
	local bar = self.bar
	local t = GetTime()
	
	if t > bar.curr_end then
		bar:Stop()
	else
		local width = (t - bar.curr_start) / bar.curr_dur
		if width > 1 then
			width = 1
		elseif width < 0 then
			width = 0
		end
		bar.timeline:SetShown(width ~= 0)
		bar.timeline:SetWidth(width * bar.timeline.width)
		
		bar.spark:SetPoint("CENTER",bar.statusbar,"LEFT", (t-bar.curr_start) / bar.curr_dur * bar.timeline.width,0)
	end
	self.c = self.c + 1
	if self.c > 3 then
		self.c = 0
		
		bar:UpdateText()
	end
end

local function BarAnimation_Reverse(self)
	local bar = self.bar
	local t = GetTime()
	
	if t > bar.curr_end then
		bar:Stop()
	else
		local width = (bar.curr_end - t) / bar.curr_dur
		if width > 1 then
			width = 1
		elseif width < 0 then
			width = 0
		end
		bar.timeline:SetShown(width ~= 0)
		bar.timeline:SetWidth(width * bar.timeline.width)
		
		bar.spark:SetPoint("CENTER",bar.statusbar,"LEFT", (bar.curr_dur - (t-bar.curr_start)) / bar.curr_dur * bar.timeline.width,0)
	end
	self.c = self.c + 1
	if self.c > 3 then
		self.c = 0
		
		bar:UpdateText()
	end
end

local function BarAnimation_NoAnimation(self)
	local bar = self.bar
	local t = GetTime()
	
	if t > bar.curr_end then
		bar:Stop()
	end
	self.c = self.c + 1
	if self.c > 3 then
		self.c = 0
		
		bar:UpdateText()
	end
end

local function StopBar(self)
  	self.anim:Stop()
  	self.spark:Hide()
 	self:UpdateStatus()
 	if VBH.ExCD2.SortByAvailability then
 		SortAllData()
 	end
 	UpdateAllData()
end

local function UpdateBar(self)
	local data = self.data
	if not data then
		self:Hide()
		return
	end
	if not self:IsVisible() then
		self:Show()
	end
	local parent = self.parent
	
	self.iconTexture:SetTexture(data.icon)
	self:UpdateText()
	if parent.optionIconName then
		self.textIcon:SetText(data.name)
	end
end

local function BarStateAnimation(self)
	local bar = self.bar
	local progress = self:GetProgress()
	local b = bar.curr_anim_b
	if b then
		bar.background:SetVertexColor(b.r + bar.curr_anim_b_r*progress,b.g + bar.curr_anim_b_g*progress,b.b + bar.curr_anim_b_b*progress,bar.curr_anim_b_a)
	end
	local l = bar.curr_anim_l
	if l then
		bar.timeline:SetVertexColor(l.r + bar.curr_anim_l_r*progress,l.g + bar.curr_anim_l_g*progress,l.b + bar.curr_anim_l_b*progress,bar.curr_anim_l_af+bar.curr_anim_l_a*progress)
	end
	local t = bar.curr_anim_t
	if t then
		bar.textLeft:SetTextColor(t.r + bar.curr_anim_t_r*progress,t.g + bar.curr_anim_t_g*progress,t.b + bar.curr_anim_t_b*progress)
		bar.textRight:SetTextColor(t.r + bar.curr_anim_t_r*progress,t.g + bar.curr_anim_t_g*progress,t.b + bar.curr_anim_t_b*progress)
		bar.textCenter:SetTextColor(t.r + bar.curr_anim_t_r*progress,t.g + bar.curr_anim_t_g*progress,t.b + bar.curr_anim_t_b*progress)
		bar.textIcon:SetTextColor(t.r + bar.curr_anim_t_r*progress,t.g + bar.curr_anim_t_g*progress,t.b + bar.curr_anim_t_b*progress)
	end
end
local function BarStateAnimationFinished(self)
	self.bar.afterAnimFix = true
	self.bar:UpdateStatus()
end

local function UpdateBarStatus(self,isTitle)
	local data = self.data
	if not data then
		return
	end
	if self.isTitle then
		self:UpdateStyle()
		self.isTitle = nil
	end
	if data.specialUpdateData then		--For templates
		data.specialUpdateData(data)
	end
	local parent = self.parent
	local currTime = GetTime()
	local lastUse = data.lastUse

	local active = lastUse + data.duration
	local cooldown = lastUse + data.cd
	
	if parent.methodsDisableActive then
		active = 0
	end
	
	local isActive = (active - currTime) > 0
	local isCooldown = (cooldown - currTime) > 0
	local t = (isActive and active) or (isCooldown and cooldown)
	
	local isDisabled = data.disabled
	if isDisabled then
		isCooldown = true
	end
	if data.specialStatus then
		local var1,var2,var3,var4 = data.specialStatus()
		if var2 then
			if var1 then
				isCooldown = true
				lastUse = var2
				t = var2 + var3
			else
				isCooldown = false
				t = nil	
				if var4 then
					data.charge = var2
					data.cd = var3
				end			
			end
		end
		data.isCharge = var4
	end
	
	self.curr_charges = nil

	local isCharge = nil
	if data.isCharge then
		if data.charge then
			if data.charge <= currTime and (data.charge+data.cd) > currTime then
				isCharge = true
				
				isCooldown = false
				
				self.curr_charges = 1
			elseif data.charge > currTime and not isActive then
				lastUse = data.charge - data.cd
				t = data.charge
				
				isCooldown = true
				
				self.curr_charges = 0
			end
		else
			self.curr_charges = 2
		end
	end
	
	if isCharge and not isActive then
		self.curr_start = data.charge
		self.curr_end = data.charge+data.cd
		self.curr_dur = data.cd
		
		if parent.optionTimeLineAnimation == 1 then
			self.timeline:SetShown(false)
		else
			self.timeline:SetShown(true)
			self.timeline:SetWidth(self.timeline.width)
		end
		self.timeline.SetWidth = self.timeline.IsShown	--Do I really want this shit?
		self.timeline.SetShown = self.timeline.IsShown
		self.spark:Show()
		self.anim:Play()
	elseif t then
		self.curr_start = lastUse
		self.curr_end = t
		self.curr_dur = t - lastUse
		
		self.timeline.SetWidth = self.timeline._SetWidth
		self.timeline.SetShown = self.timeline._SetShown
	
		self.spark:Show()
		self.anim:Play()
	else
		self.curr_start = 0
		self.curr_end = 1
		self.curr_dur = 1
		
		self.timeline.SetWidth = self.timeline._SetWidth
		self.timeline.SetShown = self.timeline._SetShown

	  	self.spark:Hide()
	  	self.anim:Stop()
	  	
	  	if isDisabled then
	  		self.timeline:Hide()
	  	else
	  		if parent.optionTimeLineAnimation == 1 then
	  			self.timeline:Hide()
	  		else
	 			self.timeline:SetWidth(self.timeline.width)
	 			self.timeline:Show()
	 		end
	 	end
	end
	
	local doStandartColors = true
	if parent.optionSmoothAnimation and not self.afterAnimFix then
		doStandartColors = false
		if not parent.optionClassColorBackground then
			local ctFrom, ctTo = nil
			if isActive then
				ctTo = parent.optionColorBackgroundActive
			elseif isCooldown then
				ctTo = parent.optionColorBackgroundCooldown
			else
				ctTo = parent.optionColorBackgroundDefault
			end
			
			if self.curr_anim_state == 1 then
				ctFrom = parent.optionColorBackgroundActive
			elseif self.curr_anim_state == 2 then
				ctFrom = parent.optionColorBackgroundCooldown
			else
				ctFrom = parent.optionColorBackgroundDefault
			end
			
			self.curr_anim_b = ctFrom
			self.curr_anim_b_r = ctTo.r - ctFrom.r
			self.curr_anim_b_g = ctTo.g - ctFrom.g
			self.curr_anim_b_b = ctTo.b - ctFrom.b
			self.curr_anim_b_a = parent.optionAlphaBackground
		else
			self.curr_anim_b = nil
			local colorTable = data.classColor
			self.background:SetVertexColor(colorTable.r,colorTable.g,colorTable.b,parent.optionAlphaBackground)
		end
		if not parent.optionClassColorTimeLine then
			local ctFrom, ctTo = nil
			if isActive then
				ctTo = parent.optionColorTimeLineActive
			elseif isCooldown then
				ctTo = parent.optionColorTimeLineCooldown
			else
				ctTo = parent.optionColorTimeLineDefault
			end
			
			if self.curr_anim_state == 1 then
				ctFrom = parent.optionColorTimeLineActive
				self.curr_anim_l_af = 1
				self.curr_anim_l_a = parent.optionAlphaTimeLine - 1
			elseif self.curr_anim_state == 2 then
				ctFrom = parent.optionColorTimeLineCooldown
				self.curr_anim_l_af = 1
				self.curr_anim_l_a = parent.optionAlphaTimeLine - 1
			else
				ctFrom = parent.optionColorTimeLineDefault
				self.curr_anim_l_af = 0
				self.curr_anim_l_a = parent.optionAlphaTimeLine
			end
			if not parent.optionAnimation then
				self.curr_anim_l_af = 0
				self.curr_anim_l_a = 0
			end
			
			self.curr_anim_l = ctFrom
			self.curr_anim_l_r = ctTo.r - ctFrom.r
			self.curr_anim_l_g = ctTo.g - ctFrom.g
			self.curr_anim_l_b = ctTo.b - ctFrom.b
		else
			self.curr_anim_l = data.classColor
			if self.curr_anim_state == 1 then
				self.curr_anim_l_af = 1
				self.curr_anim_l_a = parent.optionAlphaTimeLine - 1
			elseif self.curr_anim_state == 2 then
				self.curr_anim_l_af = 1
				self.curr_anim_l_a = parent.optionAlphaTimeLine - 1
			else
				self.curr_anim_l_af = 0
				self.curr_anim_l_a = parent.optionAlphaTimeLine
			end
			if not parent.optionAnimation then
				self.curr_anim_l_af = 0
				self.curr_anim_l_a = 0
			end
			self.curr_anim_l_r = 0
			self.curr_anim_l_g = 0
			self.curr_anim_l_b = 0
		end
		if not parent.optionClassColorText then
			local ctFrom, ctTo = nil
			if isActive then
				ctTo = parent.optionColorTextActive
			elseif isCooldown then
				ctTo = parent.optionColorTextCooldown
			else
				ctTo = parent.optionColorTextDefault
			end
			
			if self.curr_anim_state == 1 then
				ctFrom = parent.optionColorTextActive
			elseif self.curr_anim_state == 2 then
				ctFrom = parent.optionColorTextCooldown
			else
				ctFrom = parent.optionColorTextDefault
			end
			
			self.curr_anim_t = ctFrom
			self.curr_anim_t_r = ctTo.r - ctFrom.r
			self.curr_anim_t_g = ctTo.g - ctFrom.g
			self.curr_anim_t_b = ctTo.b - ctFrom.b
		else
			self.curr_anim_t = nil
			local colorTable = data.classColor
			self.textLeft:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
			self.textRight:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
			self.textCenter:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
			self.textIcon:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
		end
		
		if isActive and self.curr_anim_state ~= 1 then
			self.curr_anim_state = 1
			self.anim_state:Stop()
			self.anim_state:Play()
		elseif isCooldown and self.curr_anim_state ~= 2 then
			self.curr_anim_state = 2
			self.anim_state:Stop()
			self.anim_state:Play()
		elseif not isCooldown and not isActive and self.curr_anim_state then
			self.curr_anim_state = nil
			self.anim_state:Stop()
			self.anim_state:Play()
		else
			doStandartColors = true
		end
	end
	if doStandartColors then
		local colorTable = nil
		if parent.optionClassColorBackground then
			colorTable = data.classColor
		else
			if isActive then
				colorTable = parent.optionColorBackgroundActive
			elseif isCooldown then
				colorTable = parent.optionColorBackgroundCooldown
			else
				colorTable = parent.optionColorBackgroundDefault
			end
		end
		self.background:SetVertexColor(colorTable.r,colorTable.g,colorTable.b,parent.optionAlphaBackground)
		
		if parent.optionClassColorTimeLine then
			colorTable = data.classColor
		else
			if isActive then
				colorTable = parent.optionColorTimeLineActive
			elseif isCooldown then
				colorTable = parent.optionColorTimeLineCooldown
			else
				colorTable = parent.optionColorTimeLineDefault
			end
		end
		self.timeline:SetVertexColor(colorTable.r,colorTable.g,colorTable.b,parent.optionAlphaTimeLine)
		
		if parent.optionClassColorText then
			colorTable = data.classColor
		else
			if isActive then
				colorTable = parent.optionColorTextActive
			elseif isCooldown then
				colorTable = parent.optionColorTextCooldown
			else
				colorTable = parent.optionColorTextDefault
			end
		end	
		self.textLeft:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
		self.textRight:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
		self.textCenter:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
		self.textIcon:SetTextColor(colorTable.r,colorTable.g,colorTable.b)
	end
	self.afterAnimFix = nil
	
	if parent.optionGray then
		if isCooldown and not isActive then
			self.iconTexture:SetDesaturated(true)
		else
			self.iconTexture:SetDesaturated(nil)
		end
	end
	
	if parent.optionCooldown then
		-- BIG NOTE:
		-- Cooldown widget is currently bugged
		-- You can set time ( CD_end_time - Now_time ) only for number that is bigger than UI session (ie after reloadUI UI session timer will be 0)
		-- No way for fix :(
	
		if isActive then
			self.cooldown:Show()
			self.cooldown:SetReverse(true)
			self.cooldown:SetCooldown(self.curr_start,self.curr_end-self.curr_start)
		elseif isCooldown then
			self.cooldown:Show()
			self.cooldown:SetReverse(false)
			if isDisabled then
				self.cooldown:SetCooldown(currTime,0)
			else
				self.cooldown:SetCooldown(self.curr_start,self.curr_dur)
			end
		else
			self.cooldown:Hide()
		end
	end
	
	local alpha = 1
	if parent.methodsAlphaNotInRange then
		if data.outofrange then
			alpha = parent.methodsAlphaNotInRangeNum
			self:SetAlpha(alpha)
		else
			self:SetAlpha(1)
		end
	end
	
	if (parent.optionAlphaCooldown or 1) < 1 then
		if isCooldown and not isActive then
			self:SetAlpha(parent.optionAlphaCooldown)
		else
			self:SetAlpha(alpha)
		end
	end
	
	if isDisabled == 2 then
		self.disStatus = L_Offline
	elseif isDisabled == 1 then
		self.disStatus = L_Dead
	else
		self.disStatus = nil
	end
	
	self:UpdateText()
end

local function BarCreateTitle(self)
	local parent = self.parent

	local height = parent.iconSize or 24

	self.statusbar:ClearAllPoints()	self.statusbar:SetHeight(height)
	self.icon:ClearAllPoints()	self.icon:SetSize(height,height)
	
	self.textLeft:SetText("")
	self.textRight:SetText("")
	self.textCenter:SetText("")
	self.textIcon:SetText("")
	
	if parent.optionIconPosition == 2 then
		self.icon:Show()
		self.statusbar:SetPoint("LEFT",self,0,0)
		self.statusbar:SetPoint("RIGHT",self,-height,0)
		self.icon:SetPoint("RIGHT",self,0,0)
		
		self.textRight:SetPoint("LEFT",self,0,0)

		self.textRight:SetTextColor(1,1,1)
		self.textRight:SetText(self.data.spellName)
	elseif parent.optionIconPosition == 1 then
		self.icon:Show()
		self.statusbar:SetPoint("LEFT",self,height,0)
		self.statusbar:SetPoint("RIGHT",self,0,0)
		self.icon:SetPoint("LEFT",self,0,0)
		
		self.textLeft:SetTextColor(1,1,1)
		self.textLeft:SetText(self.data.spellName)		
	end
	
	self.curr_start = 0
	self.curr_end = 1
	self.curr_dur = 1

  	self.spark:Hide()
  	self.anim:Stop()
  	
 	self.timeline:Hide()
  	
  	self.background:SetVertexColor(0,0,0,parent.optionAlphaTimeLine)
  	
  	self.iconTexture:SetTexture(self.data.icon)
  	self.cooldown:Hide()
  	
  	self:SetAlpha(1)
  	self:Show()
  	
  	self.isTitle = true
end

local function LineIconOnHover(self)
	local parent = self:GetParent()
	if not parent.data then	return end
	GameTooltip:SetOwner(self, "ANCHOR_LEFT")
	GameTooltip:SetHyperlink("spell:"..parent.data.db[1])
	GameTooltip:Show()
end
local function LineIconOnClick(self)
	local parent = self:GetParent()
	if not parent.data then	return end
	if parent.data.specialClick then
		parent.data.specialClick(parent.data)
		return
	end	
	local time = parent.data.lastUse + parent.data.cd - GetTime()
	if time < 0 then return end
	local text = parent.data.name.." - "..parent.data.spellName..": "..format("%1.1d:%2.2d",time/60,time%60)
	local chat_type = BH.F.chatType(true)
	SendChatMessage(text,chat_type)
end
local function LineIconOnClickWhisper(self)
	local parent = self:GetParent()
	if not parent.data then	return end
	if parent.data.specialClick then
		parent.data.specialClick(parent.data)
		return
	end	
	local time = parent.data.lastUse + parent.data.cd - GetTime()
	if time > 0 then return end
	local spellLink = GetSpellLink(parent.data.db[1])
	if not spellLink or spellLink == "" then
		spellLink = parent.data.spellName
	end
	local text = "Use "..spellLink
	local chat_type = BH.F.chatType(true)
	SendChatMessage(text,"WHISPER",nil,parent.data.fullName)
end
local function LineIconOnClickBoth(self)
	local parent = self:GetParent()
	if not parent.data then	return end
	local time = parent.data.lastUse + parent.data.cd - GetTime()
	if time > 0 then 
		return LineIconOnClick(self)
	else
		return LineIconOnClickWhisper(self)
	end
end

local function UpdateBarStyle(self)
	local parent = self.parent

	local width = parent.barWidth or 100
	local height = parent.iconSize or 24
	
	self:SetSize(width,height)
	
	self.textLeft:ClearAllPoints()	self.textLeft:SetSize(0,height)	
	self.textRight:ClearAllPoints()	self.textRight:SetSize(0,height)
	self.textCenter:ClearAllPoints()self.textCenter:SetSize(0,height)
					self.textIcon:SetSize(height,height)
	self.icon:ClearAllPoints()	self.icon:SetSize(height,height)
	self.statusbar:ClearAllPoints()	self.statusbar:SetHeight(height)
					self.spark:SetSize(10,height+10)
					self.cooldown:SetSize(height,height)
		
	local iconSize = height			
	if parent.optionIconPosition == 3 or parent.optionIconTitles then
		self.icon:Hide()
		self.statusbar:SetPoint("LEFT",self,0,0)
		self.statusbar:SetPoint("RIGHT",self,0,0)
		iconSize = 0
	elseif parent.optionIconPosition == 2 then
		self.icon:Show()
		self.statusbar:SetPoint("LEFT",self,0,0)
		self.statusbar:SetPoint("RIGHT",self,-height,0)
		self.icon:SetPoint("RIGHT",self,0,0)
	else
		self.icon:Show()
		self.statusbar:SetPoint("LEFT",self,height,0)
		self.statusbar:SetPoint("RIGHT",self,0,0)
		self.icon:SetPoint("LEFT",self,0,0)
	end

	self.timeline.width = width - iconSize
	self.timeline:SetSize(width - iconSize,height)
	
	if parent.optionIconHideBlizzardEdges then
		self.iconTexture:SetTexCoord(.1,.9,.1,.9)
	else
		self.iconTexture:SetTexCoord(0,1,0,1)
	end
	
	if parent.optionHideSpark then
		self.spark:SetTexture("")
	else
		self.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
	end
	
	local fontOutlineFix = parent.fontOutline and 3 or 0
	if parent.textTemplateLeft:find("time%%") then
		self.textLeft:SetPoint("LEFT",self.statusbar,1,0)
		self.textRight:SetPoint("RIGHT",self.statusbar,-1+fontOutlineFix,0)
		self.textRight:SetPoint("LEFT",self.textLeft,"RIGHT",0,0)
	else
		self.textRight:SetPoint("RIGHT",self.statusbar,-1+fontOutlineFix,0)
		self.textLeft:SetPoint("LEFT",self.statusbar,1,0)
		self.textLeft:SetPoint("RIGHT",self.textRight,"LEFT",0,0)
	end
	
	self.textCenter:SetPoint("LEFT",self.statusbar,0,0)
	self.textCenter:SetPoint("RIGHT",self.statusbar,0,0)
	
	self.barWidth = width
	
	local textureFile = parent.textureFile or module.db.bhcolsDefaults.textureFile
	local isValidTexture = self.background:SetTexture(textureFile)
	if not isValidTexture then
		textureFile = module.db.bhcolsDefaults.textureFile
		self.background:SetTexture(textureFile)
	end
	self.timeline:SetTexture(textureFile)
	
	local isValidFont = nil
	
	self.textLeft:SetFont(parent.fontLeftName,parent.fontLeftSize,parent.fontLeftOutline and "OUTLINE")
	self.textRight:SetFont(parent.fontRightName,parent.fontRightSize,parent.fontRightOutline and "OUTLINE")
	self.textCenter:SetFont(parent.fontCenterName,parent.fontCenterSize,parent.fontCenterOutline and "OUTLINE")
	self.textIcon:SetFont(parent.fontIconName,parent.fontIconSize,parent.fontIconOutline and "OUTLINE")

	local fontOffset = 0
	fontOffset = parent.fontLeftShadow and 1 or 0	self.textLeft:SetShadowOffset(1*fontOffset,-1*fontOffset)
	fontOffset = parent.fontRightShadow and 1 or 0	self.textRight:SetShadowOffset(1*fontOffset,-1*fontOffset)
	fontOffset = parent.fontCenterShadow and 1 or 0	self.textCenter:SetShadowOffset(1*fontOffset,-1*fontOffset)
	fontOffset = parent.fontIconShadow and 1 or 0	self.textIcon:SetShadowOffset(1*fontOffset,-1*fontOffset)
	
	self.iconTexture:SetDesaturated(nil)
	
	self:SetAlpha(1)
	
	self.cooldown:Hide()
	self.cooldown:SetHideCountdownNumbers(parent.optionCooldownHideNumbers and true or false)
	self.cooldown:SetDrawEdge(parent.optionCooldownShowSwipe and true or false)

	self.textIcon:SetText("")
	
	if parent.optionAnimation then
		if parent.optionStyleAnimation == 1 then
			self.anim:SetScript("OnLoop",BarAnimation_Reverse)
		else
			self.anim:SetScript("OnLoop",BarAnimation)
		end
	else
		self.anim:SetScript("OnLoop",BarAnimation_NoAnimation)
		self.spark:SetTexture("")
		self.timeline:Hide()
	end
	
	if parent.methodsIconTooltip then
		self.icon:SetScript("OnEnter",LineIconOnHover)
		self.icon:SetScript("OnLeave",GameTooltip_Hide)
	else
		self.icon:SetScript("OnEnter",nil)
		self.icon:SetScript("OnLeave",nil)	
	end
	
	
	if parent.methodsLineClick and parent.methodsLineClickWhisper then
		self.clickFrame:SetScript("OnClick",LineIconOnClickBoth)
		self.clickFrame:Show()	
	elseif parent.methodsLineClick then
		self.clickFrame:SetScript("OnClick",LineIconOnClick)
		self.clickFrame:Show()
	elseif parent.methodsLineClickWhisper then
		self.clickFrame:SetScript("OnClick",LineIconOnClickWhisper)
		self.clickFrame:Show()		
	else
		self.clickFrame:SetScript("OnClick",nil)
		self.clickFrame:Hide()	
	end
	
	local borderSize = parent.textureBorderSize
	if borderSize == 0 then
		self.border.top:Hide()
		self.border.bottom:Hide()
		self.border.left:Hide()
		self.border.right:Hide()
	else
		self.border.top:ClearAllPoints()
		self.border.bottom:ClearAllPoints()
		self.border.left:ClearAllPoints()
		self.border.right:ClearAllPoints()
		
		self.border.top:SetPoint("TOPLEFT",self,"TOPLEFT",-borderSize,borderSize)
		self.border.top:SetPoint("BOTTOMRIGHT",self,"TOPRIGHT",borderSize,0)
	
		self.border.bottom:SetPoint("BOTTOMLEFT",self,"BOTTOMLEFT",-borderSize,-borderSize)
		self.border.bottom:SetPoint("TOPRIGHT",self,"BOTTOMRIGHT",borderSize,0)
	
		self.border.left:SetPoint("TOPLEFT",self,"TOPLEFT",-borderSize,0)
		self.border.left:SetPoint("BOTTOMRIGHT",self,"BOTTOMLEFT",0,0)
	
		self.border.right:SetPoint("TOPLEFT",self,"TOPRIGHT",0,0)
		self.border.right:SetPoint("BOTTOMRIGHT",self,"BOTTOMRIGHT",borderSize,0)
	
		self.border.top:SetColorTexture(parent.textureBorderColorR,parent.textureBorderColorG,parent.textureBorderColorB,parent.textureBorderColorA)
		self.border.bottom:SetColorTexture(parent.textureBorderColorR,parent.textureBorderColorG,parent.textureBorderColorB,parent.textureBorderColorA)
		self.border.left:SetColorTexture(parent.textureBorderColorR,parent.textureBorderColorG,parent.textureBorderColorB,parent.textureBorderColorA)
		self.border.right:SetColorTexture(parent.textureBorderColorR,parent.textureBorderColorG,parent.textureBorderColorB,parent.textureBorderColorA)
	
		self.border.top:Show()
		self.border.bottom:Show()
		self.border.left:Show()
		self.border.right:Show()
	end
	
	self.anim_state.timer:SetDuration(parent.optionSmoothAnimationDuration)
	
	if module.db.bhplugin and type(module.db.bhplugin.UpdateBarStyle)=="function" then
		module.db.bhplugin.UpdateBarStyle(self)
	end
end

local function CreateBar(parent)
	local self = CreateFrame("Frame",nil,parent)
	
	self.parent = parent
	
	local statusbar = CreateFrame("StatusBar", nil, self)
	statusbar:SetPoint("TOPRIGHT")
	statusbar:SetPoint("BOTTOMLEFT")
	self.statusbar = statusbar
	
	local timeline = statusbar:CreateTexture(nil, "BACKGROUND")
	timeline:SetPoint("LEFT")
	timeline._SetWidth = timeline.SetWidth
	timeline._SetShown = timeline.SetShown
	self.timeline = timeline
	
	local spark = statusbar:CreateTexture(nil, "BACKGROUND", nil, 3)
	spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
	spark:SetBlendMode("ADD")
	spark:SetPoint("CENTER",statusbar,"RIGHT", 0,0)
	spark:SetAlpha(0.5)
	spark:Hide()
	self.spark = spark
	
	local anim = self:CreateAnimationGroup()
	anim:SetLooping("REPEAT")
	anim.c = 0
	anim.timer = anim:CreateAnimation()
	anim.timer:SetDuration(0.04)
	anim:SetScript("OnLoop",BarAnimation)
	anim.bar = self
	self.anim = anim
	
	local anim_state = self:CreateAnimationGroup()
	anim_state.timer = anim_state:CreateAnimation()
	anim_state.timer:SetDuration(0.5)
	anim_state:SetScript("OnUpdate",BarStateAnimation)
	anim_state:SetScript("OnFinished",BarStateAnimationFinished)
	anim_state.bar = self
	self.anim_state = anim_state
	
	local icon = CreateFrame("Frame",nil,self)
	icon:SetPoint("TOPLEFT", 0, 0)
	local iconTexture = icon:CreateTexture(nil, "BACKGROUND")
	iconTexture:SetAllPoints()
	self.icon = icon
	self.iconTexture = iconTexture
	
	local cooldown = CreateFrame("Cooldown", nil, icon, "CooldownFrameTemplate")
	cooldown:SetDrawEdge(false)
	--cooldown:SetAllPoints()
	cooldown:SetPoint("CENTER")
	cooldown:SetHideCountdownNumbers(false)
	cooldown:SetDrawEdge(false)
	cooldown:SetDrawSwipe(true)
	self.cooldown = cooldown
	
	local background = self:CreateTexture(nil, "BACKGROUND", nil, -7)
	background:SetAllPoints()
	self.background = background
	
	self.textLeft = BHLib:Text(self.statusbar,nil,nil,"GameFontNormal"):Size(0,0):Point(1,0):Color()
	self.textRight = BHLib:Text(self.statusbar,nil,nil,"GameFontNormal"):Size(40,0):Point("TOPRIGHT",1,0):Right():Color()
	self.textCenter = BHLib:Text(self.statusbar,nil,nil,"GameFontNormal"):Size(0,0):Point(0,0):Center():Color()
	self.textIcon = BHLib:Text(icon,nil,nil,"GameFontNormal"):Size(0,0):Point(0,0):Center():Bottom():Color()
	
	self.textIcon:SetDrawLayer("ARTWORK",3)
	
	--6.1 multilinetext fix
	self.textLeft:SetMaxLines(1)
	self.textRight:SetMaxLines(1)
	self.textCenter:SetMaxLines(1)
	
	self.border = {}
	self.border.top = self:CreateTexture(nil, "BACKGROUND")
	self.border.bottom = self:CreateTexture(nil, "BACKGROUND")
	self.border.left = self:CreateTexture(nil, "BACKGROUND")
	self.border.right = self:CreateTexture(nil, "BACKGROUND")
	
	self.clickFrame = CreateFrame("Button",nil,self)
	self.clickFrame:SetAllPoints()
	self.clickFrame:Hide()
	
	self.Stop = StopBar
	self.Update = UpdateBar
	self.UpdateStyle = UpdateBarStyle
	self.UpdateText = BarUpdateText
	self.UpdateStatus = UpdateBarStatus
	self.CreateTitle = BarCreateTitle
	
	return self
end

local function FixFontsOnLoad(self)
	local defGameFont = GameFontWhite:GetFont()
	for i=1,#self.lines do
		local bar = self.lines[i]
		
		bar.textLeft:SetFont(defGameFont,self.fontLeftSize - 1)
		bar.textRight:SetFont(defGameFont,self.fontRightSize - 1)
		bar.textCenter:SetFont(defGameFont,self.fontCenterSize - 1)
		bar.textIcon:SetFont(defGameFont,self.fontIconSize - 1)

		bar:UpdateStyle()
	end
	return true
end

for i=1,module.db.bhmaxColumns do
	local columnFrame = CreateFrame("Frame",nil,module.frame)
	module.frame.colFrame[i] = columnFrame
	columnFrame:EnableMouse(false)
	columnFrame:SetMovable(false)
	columnFrame:RegisterForDrag("LeftButton")
	columnFrame:SetScript("OnDragStart", function(self) 
		if self:IsMovable() then 
			self:StartMoving() 
		end 
	end)
	columnFrame:SetScript("OnDragStop", function(self)
		self:StopMovingOrSizing()
		VBH.ExCD2.colSet[i].posX = self:GetLeft()
		VBH.ExCD2.colSet[i].posY = self:GetTop()
	end)	
	columnFrame.texture = columnFrame:CreateTexture(nil, "BACKGROUND")
	columnFrame.texture:SetColorTexture(0,0,0,0)
	columnFrame.texture:SetAllPoints()
	
	columnFrame.lockTexture = columnFrame:CreateTexture(nil, "BACKGROUND")
	columnFrame.lockTexture:SetColorTexture(0,0,0,0)
	columnFrame.lockTexture:SetAllPoints()

	columnFrame.lines = {}
	
	columnFrame.BlackList = {}
	
	module:RegisterHideOnPetBattle(columnFrame)

	BHLib:FixPreloadFont(columnFrame,FixFontsOnLoad)
end

do
	local isInCombat = false
	local isInEncounter = false
	function module:updateCombatVisibility()
		local _, zoneType = GetInstanceInfo()
		local inRaid = IsInRaid()
		for i=1,module.db.bhmaxColumns do
			local columnFrame = module.frame.colFrame[i]
			
			local state = columnFrame.optionIsEnabled
		
			if not columnFrame.methodsOnlyInCombat then
			
			elseif isInCombat and columnFrame.optionIsEnabled then
				state = state and true
			elseif not isInCombat then
				state = false
			end
			
			if zoneType == "arena" then
				if not columnFrame.visibilityArena then
					state = false
				end
			elseif zoneType == "party" then
				if not columnFrame.visibility5ppl then
					state = false
				end			
			elseif zoneType == "pvp" then
				if not columnFrame.visibilityBG then
					state = false
				end				
			elseif zoneType == "raid" then
				if not columnFrame.visibilityRaid then
					state = false
				end				
			elseif zoneType == "scenario" then
				if not columnFrame.visibility3ppl then
					state = false
				end				
			else
				if not columnFrame.visibilityWorld then
					state = false
				end				
			end
			
			if (columnFrame.visibilityPartyType == 2 and not inRaid) or (columnFrame.visibilityPartyType == 1 and inRaid) then
				state = false
			end
			
			columnFrame:SetShown(state)
		end
		if not VBH.ExCD2.SplitOpt then
			if VBH.ExCD2.colSet[module.db.bhmaxColumns+1].methodsOnlyInCombat then
				if isInCombat then
					module.frame:Show()
				else
					module.frame:Hide()
				end
			elseif module.frame.IsEnabled then
				module.frame:Show()
			end
		end
	end
	function module:toggleCombatVisibility(currState,callType)
		local isInstance, instanceType = IsInInstance()
		if instanceType == "arena" or instanceType == "pvp" then
			currState = true
		elseif instanceType == "raid" or instanceType == "party" then
			if callType == 1 then
				isInEncounter = currState
			elseif callType == 2 then
				currState = currState or isInEncounter
			end
		elseif callType == 1 then
			return	--ignore encounters not in raid/party
		end
		isInCombat = currState
		module:updateCombatVisibility()
	end
end

do
	local lastSaving = GetTime() - 15
	function SaveCDtoVar(overwrite)
		local currTime = GetTime()
		if ((currTime - lastSaving) < 30 and not overwrite) or module.db.bhtestMode then 
			return 
		end
		wipe(VBH.ExCD2.Save)
		for i=1,#_C do
			local unitSpellData = _C[i]
			if unitSpellData.lastUse + unitSpellData.cd - currTime > 0 then
				VBH.ExCD2.Save[ (unitSpellData.fullName or "?")..(unitSpellData.db[1] or 0) ] = {unitSpellData.lastUse,unitSpellData.cd}
			else
				VBH.ExCD2.Save[ (unitSpellData.fullName or "?")..(unitSpellData.db[1] or 0) ] = nil
			end	
		end
	end
end

local function AfterCombatResetFunction(isArena)
	
	for i=1,#_C do
		local unitSpellData = _C[i]
		local uSpecID = module.db.bhspecInDBase[globalGUIDs[unitSpellData.fullName] or 0]
		if not unitSpellData.db[uSpecID] and unitSpellData.db[3] then
			uSpecID = 3
		end

		if (unitSpellData.cd > 0 and (module.db.bhspell_afterCombatReset[unitSpellData.db[1]] or (unitSpellData.db[uSpecID] and unitSpellData.db[uSpecID][2] >= (isArena and 0 or 180) or unitSpellData.cd >= (isArena and 0 or 180)))) and (isArena) then
			unitSpellData.lastUse = 0 
			unitSpellData.charge = nil 
			
			if unitSpellData.bar and unitSpellData.bar.data == unitSpellData then
				unitSpellData.bar:UpdateStatus()
			end
		end
	end
	SaveCDtoVar(true)
end

local function TestMode(h)
	if not h then
		for i=1,#_C do
			local data = _C[i]
			local uSpecID = module.db.bhspecInDBase[VBH.ExCD2.gnGUIDs[data.fullName] or 0]
			if not data.db[uSpecID] then
				uSpecID = 3
			end
			if data.db[uSpecID] then
				if fastrandom(0,100) < 80 then
					data.cd = data.db[uSpecID][2]
					data.lastUse = GetTime() - fastrandom(0,data.db[uSpecID][2]) - fastrandom()
					data.duration = data.db[uSpecID][3]
				end
			end
		end
	else
		for i=1,#_C do
			local data = _C[i]
			data.lastUse = 0
			data.duration = 0
		end
	end
	UpdateAllData()
	SortAllData()
end

do
	local inColsCount = {}
	
	--Upvaules
	local maxColumns = _db.bhmaxColumns
	local maxLinesInCol = _db.bhmaxLinesInCol
	local specInDBase = _db.bhspecInDBase
	local spell_isTalent = _db.bhspell_isTalent	
	local session_gGUIDs = _db.bhsession_gGUIDs	
	local spell_talentReplaceOther = _db.bhspell_talentReplaceOther
	local def_col = _db.bhdef_col
	local columnsTable = _mainFrame.colFrame	
	local playerName = BH.SDB.charName
	
	local saveDataTimer = 0
	local lastBattleResChargesStatus = nil
	
	local function sort_a(a,b) return (a.sort or 0) < (b.sort or 0) end
	local function sort_b(a,b) if a.sorting == b.sorting then return (a.sort or 0) < (b.sort or 0) else return (a.sorting or 0) < (b.sorting or 0) end end
	local function sort_ar(a,b) return (a.sort or 0) > (b.sort or 0) end
	local function sort_br(a,b) if a.sorting == b.sorting then return (a.sort or 0) > (b.sort or 0) else return (a.sorting or 0) > (b.sorting or 0) end end
	
	local oneSpellPerCol = {} for i=1,maxColumns do oneSpellPerCol[i]={} end
	local reviewID = 0
	
	function SortAllData()
		if VBH.ExCD2.SortByAvailability then
			local currTime = GetTime()
			local SortByAvailabilityActiveToTop = VBH.ExCD2.SortByAvailabilityActiveToTop
		  	for i=1,#_C do
		  		local data = _C[i]
				local cd = data.lastUse + data.cd - currTime
				
				local charge = data.charge
				if data.isCharge and charge then
					if charge <= currTime and (charge+data.cd) > currTime then
						cd = -1
					elseif charge > currTime then
						cd = charge - currTime
					end
				end
				
				if data.disabled then
					cd = cd > 0 and cd or 49999
				end
				if cd > 0 then
					cd = cd + 50000
				end
				
				local dur = 0
				if SortByAvailabilityActiveToTop then
					dur = data.lastUse + data.duration - currTime
					if dur < 0 then
						dur = 0
					end
				end
				data.sorting = dur > 0 and dur or cd > 0 and cd or 0
				
				local columnFrame = columnsTable[data.column]
				if columnFrame.methodsNewSpellNewLine then
					data.sorting = (data.sort2 or data.db[1]) * 100000 + data.sorting
				end
		  	end
		  	if not VBH.ExCD2.ReverseSorting then
		  		sort(_C,sort_b)
		  	else
		  		sort(_C,sort_br)
		  	end
		elseif not VBH.ExCD2.ReverseSorting then
		  	sort(_C,sort_a)
		else
		  	sort(_C,sort_ar)
		end
	end
	
	local function TalentReplaceOtherCheck(spellID,name)
		local spellData = spell_talentReplaceOther[spellID]
		if type(spellData) == 'number' then
			return session_gGUIDs[name][spellData]
		else
			for i=1,#spellData do
				if session_gGUIDs[name][ spellData[i] ] then
					return true
				end
			end
		end
		return false
	end
	
	function UpdateAllData()
		reviewID = reviewID + 1
		--print('UpdateAllData',GetTime())
		local isTestMode = _db.bhtestMode
		local CDECol = VBH.ExCD2.CDECol
		local currTime = GetTime()
		for i=1,#_C do
			local data = _C[i]
			local db = data.db
			local name = data.fullName
			local spellID = db[1]
			
			local specID = globalGUIDs[name] or 0
			local unitSpecID = specInDBase[specID] or 3
			
			if isTestMode or (VBH_CDE[spellID] and 
			(db[unitSpecID] or (not db[unitSpecID] and db[3])) and 
			(not spell_isTalent[spellID] or session_gGUIDs[name][spellID]) and 
			(not spell_talentReplaceOther[spellID] or not TalentReplaceOtherCheck(spellID,name)) and
			(not data.specialCheck or data.specialCheck(data,currTime))
			) then 
				data.vis = true
				
				local col = 1
				if db[unitSpecID] then
					col = VBH.ExCD2.CDECol[db[unitSpecID][1]..";"..(unitSpecID-2)] or def_col[db[unitSpecID][1]..";"..(unitSpecID-2)] or 1
				elseif db[3] then
					col = VBH.ExCD2.CDECol[db[3][1]..";1"] or def_col[db[3][1]..";1"] or 1
				end
				data.column = col
				local columnFrame = columnsTable[col]
				local isOnCD = not isCharge and (data.lastUse + data.cd) > currTime
				
				if columnFrame.optionShownOnCD and not ((isCharge and data.charge and data.charge > currTime) or isOnCD) then
					data.vis = nil
				end
				if columnFrame.methodsHideOwnSpells and data.fullName == playerName then
					data.vis = nil
				end
								
				local whiteList = columnFrame.WhiteList
				if whiteList then
					if not whiteList[data.loweredName] then
						data.vis = nil
					end
				else
					local blackList = columnFrame.BlackList
					if blackList[data.loweredName] or (blackList[spellID] and blackList[spellID][data.loweredName]) then
						data.vis = nil
					end
				end
				
				local prevDisabledStatus = data.disabled
				local isDead = status_UnitIsDead[ name ]
				local isOffline = status_UnitIsDisconnected[ name ]
				if isDead or isOffline then
					data.disabled = isOffline and 2 or 1
				else
					data.disabled = nil
				end
				
				local prevOutOfRange = data.outofrange
				if status_UnitIsOutOfRange[ name ] then
					data.outofrange = true
				else
					data.outofrange = nil
				end
				
				if columnFrame.methodsOneSpellPerCol and data.vis then
					local oneSpellPerColCurr = oneSpellPerCol[col][spellID]
					if not oneSpellPerColCurr then
						oneSpellPerColCurr = {}
						oneSpellPerCol[col][spellID] = oneSpellPerColCurr
					end
					local isOnCD = isOnCD or data.disabled
					if oneSpellPerColCurr[1] ~= reviewID then
						oneSpellPerColCurr[1] = reviewID
						oneSpellPerColCurr[2] = data
						oneSpellPerColCurr[3] = isOnCD
					elseif oneSpellPerColCurr[3] and not isOnCD then
						oneSpellPerColCurr[2].vis = nil
						oneSpellPerColCurr[1] = reviewID
						oneSpellPerColCurr[2] = data
						oneSpellPerColCurr[3] = isOnCD
					elseif data.disabled then
						data.vis = nil
					elseif oneSpellPerColCurr[3] and isOnCD then
						local prevData = oneSpellPerColCurr[2]
						if (prevData.lastUse + prevData.cd) > (data.lastUse + data.cd) then
							prevData.vis = nil
							oneSpellPerColCurr[1] = reviewID
							oneSpellPerColCurr[2] = data
							oneSpellPerColCurr[3] = isOnCD
						else
							data.vis = nil
						end
					else
						data.vis = nil
					end
				end
				
				local bar = data.bar
				if bar and bar.data == data and (data.disabled ~= prevDisabledStatus or data.outofrange ~= prevOutOfRange) then
					data.bar:UpdateStatus()
				end

			else
				data.vis = nil
			end
		end
	end
	module.UpdateAllData = UpdateAllData
	
	local statusTimer1,statusTimer2 = 0,0
	
	function module:timer(elapsed)
		local forceUpdateAllData,forceSortAllData = false,false

		if not _db.bhisEncounter and IsEncounterInProgress() then
			_db.bhisEncounter = true
			local _,_,difficulty = GetInstanceInfo()
			if difficulty == 14 or difficulty == 15 or difficulty == 16 or difficulty == 17 or difficulty == 7 then
				_db.bhisResurectDisabled = true
			end
			module:toggleCombatVisibility(true,1)
		elseif _db.bhisEncounter and not IsEncounterInProgress() then
			_db.bhisEncounter = nil
			_db.bhisResurectDisabled = nil
			if GetDifficultyForCooldownReset() and not module.db.bhdisableCDresetting then
				AfterCombatResetFunction()
				forceUpdateAllData = true
				forceSortAllData = true
			end
			module:toggleCombatVisibility(false,1)
		end
		
		
		---------> Check status
		statusTimer2 = statusTimer2 + elapsed
		if statusTimer2 > 0.25 then
			statusTimer2 = 0
			statusTimer1 = statusTimer1 + 1
			local doOtherChecks = statusTimer1 > 1
			for i=1,#status_UnitsToCheck do
				local unit = status_UnitsToCheck[i]
				local inRange,isRange = UnitInRange(unit)
				local outOfRange = isRange and not inRange
				if status_UnitIsOutOfRange[ unit ] ~= outOfRange then
					forceUpdateAllData = true
				end
				status_UnitIsOutOfRange[ unit ] = outOfRange
				if doOtherChecks then
					local isDead = UnitIsDeadOrGhost(unit)
					if isDead ~= status_UnitIsDead[ unit ] then
						forceUpdateAllData = true
						forceSortAllData = true
					end
					status_UnitIsDead[ unit ] = isDead
					
					local isOffline = not UnitIsConnected(unit)
					if isOffline ~= status_UnitIsDisconnected[ unit ] then
						forceUpdateAllData = true
						forceSortAllData = true
					end
					status_UnitIsDisconnected[ unit ] = not UnitIsConnected(unit)
				end
			end
			if doOtherChecks then
				statusTimer1 = 0
				
				local charges,_,started,duration = GetSpellCharges(20484)
				if charges ~= lastBattleResChargesStatus then
					local charge = nil
					if charges then
						if charges > 0 then
							charge = started
							started = 0
						end
					else
						started = 0
						duration = 0
						charge = nil
					end
					for i=1,#_C do
						local data = _C[i]
						if module.db.bhspell_battleRes[ data.db[1] ] then
							data.lastUse = started
							data.cd = duration
							data.charge = charge

							local bar = data.bar
							if bar and bar.data == data then
								bar:UpdateStatus()
							end
						end
					end
					forceUpdateAllData = true
					forceSortAllData = true
					
					
				end
				lastBattleResChargesStatus = charges
			end
		end
		if forceUpdateAllData then
			UpdateAllData()
		end
		if forceSortAllData then
			SortAllData()
		end
				
		for i=1,maxColumns do 
			inColsCount[i] = 0 
			columnsTable[i].lastSpell = nil
		end
		for i=1,#_C do
			local data = _C[i]
			if data.vis then
				local col = data.column
				local numberInCol = inColsCount[col] + 1
				local spellID = data.db[1]
				
				local barParent = columnsTable[col]
				
				if numberInCol <= barParent.optionLinesMax then
					if barParent.methodsNewSpellNewLine and barParent.lastSpell ~= spellID then
						local fix = 0
						for j=numberInCol,maxLinesInCol do
							local bar_now = barParent.lines[numberInCol + fix]
							if bar_now then
								if bar_now.IsNewLine then
									break
								else
									if bar_now.data then
										bar_now.data = nil
										bar_now:Update()
									end
									fix = fix + 1
								end
							end
						end
						numberInCol = numberInCol + fix
					end
					if barParent.optionIconTitles and barParent.lastSpell ~= spellID then
						local bar = barParent.lines[numberInCol]
						if bar and (bar.data ~= data or not bar.isTitle) then
							bar.data = data
							bar:CreateTitle()
						end
						numberInCol = numberInCol + 1
					end
					if barParent.methodsNewSpellNewLine and barParent.optionIconTitles and barParent.frameColumns > 1 and barParent.lastSpell == spellID then
						local bar_now = barParent.lines[numberInCol]
						if bar_now and bar_now.IsNewLine then
							if bar_now.data then
								bar_now.data = nil
								bar_now:Update()
							end
							numberInCol = numberInCol + 1
						end
					end
	
					barParent.lastSpell = spellID
					
					inColsCount[col] = numberInCol
					local bar = barParent.lines[numberInCol]
					if bar and bar.data ~= data then
						bar.data = data
						
						data.bar = bar
					
						bar:Update()
						bar:UpdateStatus()
					end
				end
			end
		end
		
		for i=1,maxColumns do
			local col = columnsTable[i]
			if col.IsColumnEnabled then
				local y = col.optionLinesMax
				if inColsCount[i] > y then
					inColsCount[i] = y
				end
				local start = inColsCount[i]
				for j=start+1,col.NumberLastLinesActive do
					local bar = col.lines[j]
					if bar and bar.data then
						bar.data = nil
						bar:Update()
					end
				end
				col.NumberLastLinesActive = start
			end
		end
		
		saveDataTimer = saveDataTimer + elapsed
		if saveDataTimer > 2 then
			saveDataTimer = 0
			SaveCDtoVar()
		end
	end
end

local function GetNumGroupMembersFix() 
	local n = GetNumGroupMembers() or 0
	if module.db.bhtestMode then
		return 20
	elseif n == 0 and VBH.ExCD2.NoRaid then 
		return 1
	else
		return n
	end
end

local function GetRaidRosterInfoFix(j) 
	local name, rank, subgroup, level, class, classFileName, zone, online, isDead, role, isML = GetRaidRosterInfo(j)
	if j == 1 and not name and VBH.ExCD2.NoRaid then
		name = UnitName("player")
		class,classFileName = UnitClass("player")
		local _,race = UnitRace("player")
		level = UnitLevel("player")
		isDead = UnitIsDeadOrGhost("player")
		return name,1,classFileName,level,race,true,isDead
	elseif not module.db.bhtestMode then
		local _,race = UnitRace(name or "?")
		return name,subgroup,classFileName,level,race,online,isDead
	elseif module.db.bhtestMode then
		if name then
			local _,race = UnitRace(name)
			return name,subgroup,classFileName,level,race,online,isDead
		end
		local i = math.random(1,11)

		local namesList = {}
		for unitName, specID in pairs(VBH.ExCD2.gnGUIDs) do
			namesList[#namesList+1] = {unitName}
			for className, classSpecs in pairs(module.db.bhspecByClass) do
				if BH.F.table_find(module.db.bhclassNames,className) then	--prevent error at version without DH class
					for spec_i=1,#classSpecs do
						if classSpecs[spec_i] == specID then
							namesList[#namesList][2] = className
						end
					end
				end
			end
		end
		if #namesList == 0 or #namesList < 25 then
			name = L.classLocalizate[module.db.bhclassNames[i]]..tostring(j)
			classFileName = module.db.bhclassNames[i]
		else
			i = math.random(1,#namesList)
			name = namesList[i][1]
			classFileName = namesList[i][2]
		end

		return name,1,classFileName,100,nil,true,false
	end
end

function RaidResurrectSpecialCheck()
	local _,_,difficulty = GetInstanceInfo()
	if difficulty == 14 or difficulty == 15 or difficulty == 16 or difficulty == 7 or difficulty == 17 or difficulty == 8 then
		return true
	end
end
function RaidResurrectSpecialText()
	local charges, maxCharges, started, duration = GetSpellCharges(20484)
	if (charges or 0) > 1 then
		return " ("..charges..")"
	end
end
function RaidResurrectSpecialStatus()
	local charges, maxCharges, started, duration = GetSpellCharges(20484)
	if charges then
		if charges > 0 then
			return false,started,duration,true
		else
			return true,started,duration,false
		end
	end
end

local function UpdateRoster()
	wipe(status_UnitsToCheck)
	wipe(status_UnitIsDead)
	wipe(status_UnitIsDisconnected)
	wipe(status_UnitIsOutOfRange)

	local n = GetNumGroupMembersFix()
	if n > 0 then
		local priorCounter = 0
		local priorNamesToNumber = {}
		if not module.db.bhtestMode then
			for j=1,n do
				local name = GetRaidRosterInfoFix(j)
				if name then
					priorNamesToNumber[#priorNamesToNumber + 1] = name
				end
			end
			sort(priorNamesToNumber)
		end
		
		local classColorsTable = type(CUSTOM_CLASS_COLORS)=="table" and CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
		
		for i=1,#_C do _C[i].sort = nil end
		local gMax = GetRaidDiffMaxGroup()
		local isInRaid = IsInRaid()
		for j=1,n do
			local name,subgroup,class,level,race,online,isDead = GetRaidRosterInfoFix(j)
			if name and subgroup <= gMax then
				for i,spellData in ipairs(module.db.bhspellDB) do
					local SpellID = spellData[1]
					local AddThisSpell = true
					if module.db.bhspell_isRacial[ SpellID ] then
						AddThisSpell = false	
					end
					if not GetSpellInfo(SpellID) then	--non exist, removed spells
						AddThisSpell = false
					end
					if AddThisSpell and (spellData[2] == class or spellData[2] == "ALL") then
						if not BH.F.table_find(status_UnitsToCheck,name) then
							status_UnitsToCheck[#status_UnitsToCheck + 1] = name
							
							status_UnitIsDead[ name ] = isDead
							status_UnitIsDisconnected[ name ] = not online
							
							local inRange,isRange = UnitInRange(name)
							status_UnitIsOutOfRange[ name ] = isRange and not inRange
						end 
						--if SpellID == 1719 then
						--module:AddCLEUSpellDamage(SpellID)
						--end
					
						local alreadyInCds = nil
						priorCounter = priorCounter + 1
						
						local spellColumn = 1
						local _specID = globalGUIDs[name] or 0
						local uSpecID = _db.bhspecInDBase[_specID] or 3
						if spellData[uSpecID] then
							spellColumn = VBH.ExCD2.CDECol[spellData[uSpecID][1]..";"..(uSpecID-2)] or _db.bhdef_col[spellData[uSpecID][1]..";"..(uSpecID-2)] or 1
						elseif spellData[3] then
							spellColumn = VBH.ExCD2.CDECol[spellData[3][1]..";1"] or _db.bhdef_col[spellData[3][1]..";1"] or 1
						end
						local getSpellColumn = _mainFrame.colFrame[spellColumn]
						local prior = nil
						if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
							prior = (VBH.ExCD2.Priority[SpellID] or 15) * 1000000000000 + (SpellID or 0) * 1000000 + (BH.F.table_find(priorNamesToNumber,name) or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 2 then
							prior = (VBH.ExCD2.Priority[SpellID] or 15) * 1000000000000 + (BH.F.table_find(priorNamesToNumber,name) or 0) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 3 then
							prior = (VBH.ExCD2.Priority[SpellID] or 15) * 100000000000000 + (BH.F.table_find(module.db.bhclassNames,class) or 0) * 1000000000000 + (SpellID or 0) * 1000000 + (BH.F.table_find(priorNamesToNumber,name) or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 4 then
							prior = (VBH.ExCD2.Priority[SpellID] or 15) * 100000000000000 + (BH.F.table_find(module.db.bhclassNames,class) or 0) * 1000000000000 + (BH.F.table_find(priorNamesToNumber,name) or 0) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 5 then
							prior = (BH.F.table_find(priorNamesToNumber,name) or 0) * 1000000000000 + (VBH.ExCD2.Priority[SpellID] or 15) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 6 then
							prior = (BH.F.table_find(module.db.bhclassNames,class) or 0) * 100000000000000 + (VBH.ExCD2.Priority[SpellID] or 15) * 1000000000000 + (BH.F.table_find(priorNamesToNumber,name) or 0) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						end
						local secondPrior = (VBH.ExCD2.Priority[SpellID] or 15) * 1000000 + (SpellID or 0)	--used in columns with option 'new spell - new line'
						
						local sName = format("%s%d",name or "?",SpellID or 0)
						local lastUse,nowCd = 0,0
						if VBH.ExCD2.Save[sName] and NumberInRange(VBH.ExCD2.Save[sName][1] + VBH.ExCD2.Save[sName][2] - GetTime(),0,2000,false,true) then
							lastUse,nowCd = VBH.ExCD2.Save[sName][1],VBH.ExCD2.Save[sName][2]
						end
						
						local spellName,_,spellTexture = GetSpellInfo(SpellID)
						spellTexture = spellTexture or "Interface\\Icons\\INV_MISC_QUESTIONMARK"
						spellName = spellName or "unk"
						local shownName = DelUnitNameServer(name)
						
		
						
						for l=3,7 do
							if spellData[l] then
								local h = module.db.bhcdsNav[name][spellData[l][1]]
								if h then
									h.db = spellData
									if lastUse ~= 0 and nowCd ~= 0 and h.lastUse == 0 and h.cd == 0 then
										h.cd = nowCd
										h.lastUse = lastUse
									end
									h.sort = prior
									h.sort2 = secondPrior
									h.spellName = spellName
									h.icon = spellTexture
									h.column = spellColumn
									
									alreadyInCds = true
								end
							end
						end

						if not alreadyInCds then
							_C [#_C + 1] = {
								name = shownName,
								fullName = name,
								loweredName = shownName:lower(),
								icon = spellTexture,
								spellName = spellName,
								db = spellData,
								lastUse = lastUse,
								cd = nowCd,
								duration = 0,
								classColor = classColorsTable[class] or module.db.bhnotAClass,
								sort = prior,
								sort2 = secondPrior,
								column = spellColumn,
							}
						end
					end
				end
				module.db.bhsession_gGUIDs[name] = 1
			end
		end
		
		--WOD Raid resurrect
		
		local findResSpell = BH.F.table_find(module.db.bhspellDB,161642,1)
		if findResSpell then
			local spellData = module.db.bhspellDB[findResSpell]
			local h = module.db.bhcdsNav["*"][spellData[3][1]]
			local prior = 0
			
			priorCounter = priorCounter + 1
			
			local spellColumn = VBH.ExCD2.CDECol["161642;1"] or _db.bhdef_col["161642;1"] or 1
			local getSpellColumn = _mainFrame.colFrame[spellColumn]
			if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
				prior = (VBH.ExCD2.Priority[161642] or 15) * 1000000000000 + 161642 * 1000000 + priorCounter
			elseif getSpellColumn.methodsSortingRules == 2 then
				prior = (VBH.ExCD2.Priority[161642] or 15) * 1000000000000 + 161642 * 10000 + priorCounter
			elseif getSpellColumn.methodsSortingRules == 3 then
				prior = (VBH.ExCD2.Priority[161642] or 15) * 100000000000000 + 161642 * 1000000 + priorCounter
			elseif getSpellColumn.methodsSortingRules == 4 then
				prior = (VBH.ExCD2.Priority[161642] or 15) * 100000000000000 + 161642 * 10000 + priorCounter
			elseif getSpellColumn.methodsSortingRules == 5 then
				prior = (VBH.ExCD2.Priority[161642] or 15) * 10000000000 + 161642 * 10000 + priorCounter
			elseif getSpellColumn.methodsSortingRules == 6 then
				prior = (VBH.ExCD2.Priority[161642] or 15) * 1000000000000 + 161642 * 10000 + priorCounter
			end
			local secondPrior = (VBH.ExCD2.Priority[161642] or 15) * 1000000 + (161642 or 0)
			
			if not h then
				local spellName,_,spellTexture = GetSpellInfo(spellData[1])
				_C [#_C + 1] = {
					name = L.cd2Resurrect,
					fullName = "*",
					loweredName = "*",
					icon = spellTexture,
					spellName = spellName or "unk",
					db = spellData,
					lastUse = 0,
					cd = 0,
					duration = 0,
					classColor = module.db.bhnotAClass,
					sort = prior,
					sort2 = secondPrior,
					column = spellColumn,
					specialCheck = RaidResurrectSpecialCheck,
					specialAddText = RaidResurrectSpecialText,
					specialStatus = RaidResurrectSpecialStatus,
				}
			else
				h.sort = prior
				h.sort2 = secondPrior
				h.column = spellColumn
			end
			module.db.bhsession_gGUIDs["*"] = 1
		end
		
		cdsNav_wipe()

		local pluginFunc = module.db.bhplugin and type(module.db.bhplugin.UpdateRoster)=="function" and module.db.bhplugin.UpdateRoster

		local j = 0
		for i=1,#_C do
			j = j + 1
			local line = _C[j]
			if not line then
				break
			elseif not line.sort then
				tremove(_C,j)
				j = j - 1
			else
				for l=3,7 do 
					if line.db[l] then
						cdsNav_set(line.fullName,line.db[l][1],line)
					end 
				end
				if pluginFunc then
					pluginFunc(line)
				end
			end
		end
	else
		wipe(_C)
		cdsNav_wipe()
	end
	if module.db.bhtestMode then 
		TestMode() 
		
		local offline = status_UnitsToCheck[fastrandom(1,#status_UnitsToCheck)]
		local dead = status_UnitsToCheck[fastrandom(1,#status_UnitsToCheck)]
		
		status_UnitIsDead[dead] = true
		status_UnitIsDisconnected[offline] = true
		
		for j=#status_UnitsToCheck,1,-1 do
			if not UnitName(status_UnitsToCheck[j]) then
				tremove(status_UnitsToCheck, j)
			end
		end
	end
	UpdateAllData()
	SortAllData()
end

do
	
	local function IsAuraActive(unit,spellID)
		for i=1,40 do
			local name,_,_,_,_,_,_,_,_,auraSpellID = UnitAura(unit,i)
			if spellID == auraSpellID then
				return true
			elseif not name then
				return
			end
		end
	end
	function CLEUstartCD(i)
		local currTime = GetTime()
		local data = nil
		if type(i) == "table" then
			data = i
		else
			data = _C[i]
		end
		local fullName = data.fullName
		
		local uSpecID = module.db.bhspecInDBase[globalGUIDs[fullName] or 0]
		if not data.db[uSpecID] and not data.db[3] then
			return
		elseif not data.db[uSpecID] then
			uSpecID = 3
		end
		local spellID = data.db[uSpecID][1]
		--WOD Battle Res
		do
			if _db.bhspell_battleRes[spellID] and _db.bhisResurectDisabled then
				return
			end
		end
		
		data.cd = data.db[uSpecID][2]
		data.duration = data.db[uSpecID][3]
		
		--Talents / Glyphs
		local durationTable = module.db.bhspell_durationByTalent_fix[spellID]
		if durationTable then
			for j=1,#durationTable,2 do
				local talentSpellID = durationTable[j]
				if module.db.bhsession_gGUIDs[fullName][talentSpellID] then
					local timeReduce = durationTable[j+1]
					if type(timeReduce) == 'table' then
						--artifact power old
					elseif tonumber(timeReduce) then
						data.duration = data.duration + timeReduce
					else
						local timeFix = tonumber( string.sub( timeReduce, 2 ) )
						data.duration = data.duration * timeFix
					end
				end
			end
		end
		local cdTable = module.db.bhspell_cdByTalent_fix[spellID]
		if cdTable then
			for j=1,#cdTable,2 do
				local talentSpellID = cdTable[j]
				if module.db.bhsession_gGUIDs[fullName][talentSpellID] then
					local timeReduce
					if module.db.bhspell_cdByTalent_isScalable[talentSpellID] then
						local scale_data = module.db.bhspell_cdByTalent_scalable_data[talentSpellID]
						timeReduce = scale_data[fullName] or scale_data[1]
					else
						timeReduce = cdTable[j+1]
						if type(timeReduce) == 'table' then
							if IsAuraActive(fullName,timeReduce[2]) then
								timeReduce = timeReduce[1]
							else
								timeReduce = 0
							end
						end
					end
					if tonumber(timeReduce) then
						data.cd = data.cd + timeReduce
					else
						local timeFix = tonumber( string.sub( timeReduce, 2 ) )
						data.cd = data.cd * timeFix
					end
				end
			end
		end
		--Charges
		
			data.lastUse = currTime
		
		--Haste/Readiness
		if module.db.bhspell_speed_list[spellID] then
			data.duration = data.duration / (1 + (UnitSpellHaste(fullName) or 0) /100)
		end
		--Dispels
		-- Fixes
		if data.cd > 45000 then data.cd = 45000 end
		if data.duration > 45000 then data.duration = 45000 end
		
		if data.bar and data.bar.data == data then
			data.bar:UpdateStatus()
		end
		
		UpdateAllData()
		SortAllData()
		
		
	end
end

function module:Enable()
	VBH.ExCD2.enabled = true
	if not VBH.ExCD2.SplitOpt then 
		module.frame:Show()
		module:ReloadAllSplits()
	else
		module:ReloadAllSplits()
	end
	
	module.frame.IsEnabled = true

	module:RegisterSlash()
	module:RegisterTimer()
	module:RegisterEvents('SCENARIO_UPDATE','GROUP_ROSTER_UPDATE','COMBAT_LOG_EVENT_UNFILTERED','PLAYER_LOGOUT','ZONE_CHANGED_NEW_AREA','CHALLENGE_MODE_RESET','PLAYER_REGEN_DISABLED','PLAYER_REGEN_ENABLED','ENCOUNTER_START','ENCOUNTER_END')

	UpdateRoster()
end

function module:Disable()
	VBH.ExCD2.enabled = nil
	if not VBH.ExCD2.SplitOpt then 
		module.frame:Hide()
	else
		for i=1,module.db.bhmaxColumns do 
			module.frame.colFrame[i]:Hide()
		end 
	end
	
	module.frame.IsEnabled = false
	
	module:UnregisterSlash()
	module:UnregisterTimer()
	module:UnregisterEvents('SCENARIO_UPDATE','GROUP_ROSTER_UPDATE','COMBAT_LOG_EVENT_UNFILTERED','PLAYER_LOGOUT','ZONE_CHANGED_NEW_AREA','CHALLENGE_MODE_RESET','PLAYER_REGEN_DISABLED','PLAYER_REGEN_ENABLED','ENCOUNTER_START','ENCOUNTER_END')
end

function module.main:ADDON_LOADED()
	VBH = _G.VBH
	VBH.ExCD2 = VBH.ExCD2 or {NoRaid = true}
	if VBH.ExCD2.Left and VBH.ExCD2.Top then
		module.frame:ClearAllPoints()
		module.frame:SetPoint("TOPLEFT",UIParent,"BOTTOMLEFT",VBH.ExCD2.Left,VBH.ExCD2.Top)
	end
	
	VBH.ExCD2.CDE = VBH.ExCD2.CDE or {}
	VBH.ExCD2.CDECol = VBH.ExCD2.CDECol or {}
	if UnitFactionGroup("player") == "Alliance" then	--> BL Faction Fix
		for i,spellData in ipairs(module.db.bhspellDB) do
			if spellData[1] == 2825 then
				spellData[1] = 32182
				spellData[3][1] = 32182
				break
			end
		end
	end
	VBH_CDE = VBH.ExCD2.CDE
	
	if not VBH.ExCD2.colSet then
		VBH.ExCD2.colSet = {}
		for i=1,module.db.bhmaxColumns+1 do
			VBH.ExCD2.colSet[i] = {}
			for optName,optVal in pairs(module.db.bhcolsInit) do
				VBH.ExCD2.colSet[i][optName] = optVal
			end
			if i <= 3 then 
				VBH.ExCD2.colSet[i].enabled = true
			end
		end
	end
	for i=1,module.db.bhmaxColumns+1 do
		VBH.ExCD2.colSet[i] = VBH.ExCD2.colSet[i] or {}
	end
	
	VBH.ExCD2.default_userCD = VBH.ExCD2.default_userCD or {}
	VBH.ExCD2.default_userDuration = VBH.ExCD2.default_userDuration or {}
	do
		for spellID,spellData in pairs(VBH.ExCD2.default_userCD) do
			for i=1,#module.db.bhspellDB do
				if module.db.bhspellDB[i][1] == spellID then
					for j=1,5 do
						if spellData[j] and module.db.bhspellDB[i][2+j] then
							if spellData[j] == module.db.bhspellDB[i][2+j][2] then
								spellData[j] = nil
							else
								module.db.bhspellDB[i][2+j][2] = spellData[j]
							end
						end
					end
				end
			end
		end
	
		for spellID,spellData in pairs(VBH.ExCD2.default_userDuration) do
			for i=1,#module.db.bhspellDB do
				if module.db.bhspellDB[i][1] == spellID then
					for j=1,5 do
						if spellData[j] and module.db.bhspellDB[i][2+j] then
							if spellData[j] == module.db.bhspellDB[i][2+j][3] then
								spellData[j] = nil
							else
								module.db.bhspellDB[i][2+j][3] = spellData[j]
							end
						end
					end
				end
			end
		end
	end
	
	VBH.ExCD2.userDB = VBH.ExCD2.userDB or {}
	for i=1,#VBH.ExCD2.userDB do
		module.db.bhspellDB[i+module.db.bhdbCountDef] = VBH.ExCD2.userDB[i]
	end

	VBH.ExCD2.Priority = VBH.ExCD2.Priority or {}

	VBH.ExCD2.gnGUIDs = VBH.ExCD2.gnGUIDs or {}
	if VBH.ExCD2.gnGUIDs and BH.F.table_len(VBH.ExCD2.gnGUIDs) > 500 then
		wipe(VBH.ExCD2.gnGUIDs)
	end
	globalGUIDs = VBH.ExCD2.gnGUIDs

	if VBH.ExCD2.lock then
		module.frame.texture:SetColorTexture(0, 0, 0, 0)
		module.frame:EnableMouse(false)
		BH.lib.AddShadowComment(module.frame,1)
	else
		module.frame.texture:SetColorTexture(0, 0, 0, 0.3)
		module.frame:EnableMouse(true)
		BH.lib.AddShadowComment(module.frame,nil,L.cd2)
	end
	
	module:SplitExCD2Window() 
	--module:ReloadAllSplits()
	
	VBH.ExCD2.Save = VBH.ExCD2.Save or {}

	if not VBH.ExCD2.enabled then
		if not VBH.ExCD2.SplitOpt then 
			module.frame:Hide() 
		else
			for i=1,module.db.bhmaxColumns do 
				module.frame.colFrame[i]:Hide() 
			end 
		end
	else
		module:Enable()
		ScheduleTimer(UpdateRoster,10)
		ScheduleTimer(module.ReloadAllSplits,10)
		module:RegisterEvents('PLAYER_ENTERING_WORLD')
	end
	
	module.db.bhplayerName = BH.SDB.charName
end

function module.main:PLAYER_ENTERING_WORLD()
	UpdateRoster()
	
	module:UnregisterEvents('PLAYER_ENTERING_WORLD')
end

function module.main:PLAYER_LOGOUT()
	SaveCDtoVar(true)
end

function module.main:SCENARIO_UPDATE()
	AfterCombatResetFunction()
	UpdateAllData()
	SortAllData()
end
module.main.CHALLENGE_MODE_RESET = module.main.SCENARIO_UPDATE

function module.main:PLAYER_REGEN_DISABLED()
	module:toggleCombatVisibility(true,2)
end
function module.main:PLAYER_REGEN_ENABLED()
	module:toggleCombatVisibility(false,2)
end


do
	local scheduledUpdateRoster = nil
	local function funcScheduledUpdate()
		scheduledUpdateRoster = nil
		UpdateRoster()
		module:updateCombatVisibility()
	end
	function module.main:GROUP_ROSTER_UPDATE()
		if not scheduledUpdateRoster then
			scheduledUpdateRoster = ScheduleTimer(funcScheduledUpdate,2)
		end
	end
end

do
	local scheduledUpdateRoster = nil
	local function funcScheduledUpdate()
		scheduledUpdateRoster = nil
		UpdateRoster()
	end
	
	local scheduledVisibility = nil
	local function funcScheduledVisibility()
		scheduledVisibility = nil
		module:updateCombatVisibility()
	end
	
	function module.main:ZONE_CHANGED_NEW_AREA()
		if select(2, IsInInstance()) == "arena" then
			AfterCombatResetFunction(true)
			UpdateAllData()
			SortAllData()
		end
		if not scheduledUpdateRoster then
			scheduledVisibility = ScheduleTimer(funcScheduledVisibility,2)
		end		
		if not scheduledUpdateRoster then
			scheduledUpdateRoster = ScheduleTimer(funcScheduledUpdate,10)
		end
	end
end

function module.main:ENCOUNTER_START(encounterID, encounterName, difficultyID, groupSize)
	if encounterID == 2334 then --reset sur skitra
		module.db.bhdisableCDresetting = true
	end
end
function module.main:ENCOUNTER_END(encounterID, encounterName, difficultyID, groupSize, success)
	if encounterID == 2334 then --reset sur skitra
		module.db.bhdisableCDresetting = nil
	end
end



do
	local eventsView = nil
	--upvaules
	local spell_startCDbyAuraApplied = _db.bhspell_startCDbyAuraApplied
	local spell_startCDbyAuraApplied_fix = _db.bhspell_startCDbyAuraApplied_fix
	local spell_isTalent = _db.bhspell_isTalent
	local spell_runningSameSpell = _db.bhspell_runningSameSpell
	local session_gGUIDs = _db.bhsession_gGUIDs
	local CDList = _db.bhcdsNav
	
	local function IsAuraActive(unit,spellID)
		for i=1,40 do
			local name,_,_,_,_,_,_,_,_,auraSpellID = UnitAura(unit,i)
			if spellID == auraSpellID then
				return true
			elseif not name then
				return
			end
		end
	end	
	
	function module.main:COMBAT_LOG_EVENT_UNFILTERED()
		--dtime()
		local _,event,_,sourceGUID,sourceName,sourceFlags,_,destGUID,destName,destFlags,_,spellID,_,_,missType,overhealing,_,_,_,_,critical = CombatLogGetCurrentEventInfo()

		local func = eventsView[event]
		if func then
			func(self,sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID,critical,missType,overhealing)
		end
		--dtime(BH.Debug,'ExCD2',event)
	end

	function module.main:SPELL_AURA_APPLIED(sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID)
		if sourceName then
			local CDspellID = spell_startCDbyAuraApplied[spellID]
			if CDspellID then
				local line = CDList[sourceName][CDspellID]
				if line then
					CLEUstartCD(line)
				end
			end
		end
	end
	function module.main:SPELL_AURA_REMOVED(sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID)
		if not sourceName then
			return
		end
		local forceSortAllData = false
		if spellID == 206005 then	--Xavius: Dream Simulacrum
			for i=1,#_C do
				local unitSpellData = _C[i]		
				if unitSpellData.fullName == destName then
					unitSpellData.cd = 0
					unitSpellData.duration = 0
					
					if unitSpellData.bar and unitSpellData.bar.data == unitSpellData then
						unitSpellData.bar:UpdateStatus()
						forceSortAllData = true
					end
				end
			end
			UpdateAllData()
		end
		if forceSortAllData then
			SortAllData()
		end
	end
	function module.main:SPELL_CAST_SUCCESS(sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID)
		if not sourceName then
			return
		end
		local forceSortAllData,forceUpdateAllData = nil	
		if spell_startCDbyAuraApplied_fix[spellID] then
			if forceUpdateAllData then UpdateAllData() end
			return
		end

		local line = CDList[sourceName][spellID]
		if line then
			CLEUstartCD(line)
		end

		if spell_isTalent[spellID] then
			if not session_gGUIDs[sourceName][spellID] then
				forceUpdateAllData = true
				session_gGUIDs[sourceName] = {spellID,"talent"}
			end
		end
		
		local modifData = spell_runningSameSpell[spellID]
		if modifData then
			for i=1,#modifData do
				local sameSpellID = modifData[i]
				if sameSpellID ~= spellID then
					local line = CDList[sourceName][ sameSpellID ]
					if line then
						CLEUstartCD(line)
					end
				end
			end
		end
		
		if forceUpdateAllData then
			UpdateAllData()
		end
		if forceSortAllData then
			SortAllData()
		end
	end
		
	eventsView = {
		SPELL_AURA_REMOVED=module.main.SPELL_AURA_REMOVED,
		SPELL_AURA_APPLIED=module.main.SPELL_AURA_APPLIED,
		SPELL_CAST_SUCCESS=module.main.SPELL_CAST_SUCCESS,
		--SWING_MISSED=module.main.SWING_MISSED,
		--SPELL_MISSED=module.main.SPELL_MISSED,   intéressant ^^
		SPELL_SUMMON=module.main.SPELL_SUMMON,
	}
	
end

function module.options:Load()
	self:CreateTilte()

	local SPELL_LINE_HEIGHT = 32
	local SPELL_PER_PAGE = 17
	local SPELL_PAGE_HEIGHT = 480
	
	-- ckeck box 
	self.chkEnable = BHLib:Check(self,L.senable,VBH.ExCD2.enabled,0):Point(550,-26):Size(25,25):OnClick(function(self) 
		if self:GetChecked() then
			module:Enable()
		else
			module:Disable()
		end
	end)
	
	self.chkLock = BHLib:Check(self,L.cd2fix,VBH.ExCD2.lock,0):Point(430,-26):Size(25,25):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.lock = true
			BH.F.LockMove(module.frame,nil,module.frame.texture)
			BH.lib.AddShadowComment(module.frame,1)
			if VBH.ExCD2.SplitOpt then 
				for i=1,module.db.bhmaxColumns do 
					BH.F.LockMove(module.frame.colFrame[i],nil,module.frame.colFrame[i].lockTexture)
					BH.lib.AddShadowComment(module.frame.colFrame[i],1)
				end 
			end
		else
			VBH.ExCD2.lock = nil
			BH.F.LockMove(module.frame,true,module.frame.texture)
			BH.lib.AddShadowComment(module.frame,nil,L.cd2)
			if VBH.ExCD2.SplitOpt then 
				for i=1,module.db.bhmaxColumns do 
					BH.F.LockMove(module.frame.colFrame[i],true,module.frame.colFrame[i].lockTexture)
					BH.lib.AddShadowComment(module.frame.colFrame[i],nil,L.cd2,i,72,"OUTLINE")
				end 
			end
		end
	end)
	
	self.tab = BHLib:Tabs(self,"BHTabButtonTemplate",L.cd2Spells,L.cd2Appearance):Point(10,-50):Size(622,570):SetTo(1)
	self.tab:SetBackdropBorderColor(0,0,0,1)
	self.tab:SetBackdropColor(0,0,0,0)
	
	-- premiére page choix list or choix colonnes
	
	self.tab1tab = BHLib:Tabs(self.tab.tabs[1],0,L.cd2Spells,L.cd2Columns):Size(600,100):Point(0,-25)
	self.tab1tab:SetBackdrop({})
	local function SetFirstTabFrame(self)
		if self._i == 1 then
			module.options.borderList:Show()
			module.options.colsSpells:Hide()
		else
			module.options.borderList:Hide()
			module.options.colsSpells:Show()		
		end
	end
	for i=1,2 do
		local frame = self.tab1tab.tabs[i].button
		frame:ClearAllPoints()
		if i == 1 then
			frame:SetPoint("TOPLEFT",self.tab.tabs[1],"TOPLEFT",10,-4)
		else
			frame:SetPoint("LEFT", self.tab1tab.tabs[1].button, "RIGHT", 0, 0)
		end
		frame._i = i
		frame.additionalFunc = SetFirstTabFrame
	end
	
	-- page list des spells suivi
	
	self.borderList = CreateFrame("Frame",nil,self.tab.tabs[1])
	self.borderList:SetSize(600,SPELL_PAGE_HEIGHT)
	self.borderList:SetPoint("TOP", 10, -40)
	BHLib:Border(self.borderList,2,.24,.25,0,0)
	
	local function SyncUserDB()
		table.wipe(VBH.ExCD2.userDB)
		local j = 1
		for i=module.db.bhdbCountDef+1,#module.db.bhspellDB do
			VBH.ExCD2.userDB[j] = module.db.bhspellDB[i]
			j = j + 1
		end
	end
	
	local function CheckToNil(self)
		self.chk:SetChecked(nil) 
		VBH.ExCD2.CDE[self.sid] = nil
		UpdateRoster()
	end

	function module.options:ReloadSpellsPage()
		local page = module.options
		--local scrollBarValue = page.ScrollBar:GetValue()
		--page.spellsListScrollFrame:SetVerticalScroll(scrollBarValue % SPELL_LINE_HEIGHT) 

		local pos =  1+ 1
		local lineNum,lastLine = 0
		for i=pos,pos+SPELL_PER_PAGE+1 do
			lineNum = lineNum + 1
			if not module.db.bhspellDB[i] then
				for j=lineNum,#page.spellsList do
					page.spellsList[j]:Hide()
				end
				break
			end
			local spellData = module.db.bhspellDB[i]
			local SpellID = spellData[1]
			local line = module.options.spellsList[lineNum]
			lastLine = line
		
			line.chk:SetChecked(VBH.ExCD2.CDE[SpellID])
			local SpellName,_,SpellTexture = GetSpellInfo(SpellID)
			
			line.sid = SpellID
			line.tid = i
			line.icon:SetTexture(SpellTexture or "Interface\\Icons\\INV_MISC_QUESTIONMARK")
			line.spellName:SetFormattedText("|cffffffff|Hspell:%d|h%s|h|r",SpellID, SpellName or "?")
			line.class:SetText(L.classLocalizate[ spellData[2] ] or "?")
			local cR,cG,cB = BH.F.classColorNum(spellData[2])
			line.class:SetTextColor(cR,cG,cB,1)
			
			line.backClassColorR = cR
			line.backClassColorG = cG
			line.backClassColorB = cB
	
			if not SpellName and spellData.user then
				line.chk:Disable()
				line.chk:SetAlpha(0.5)
			else
				line.chk:Enable()
				line.chk:SetAlpha(1)
			end

			line:Show()

			BH.lib.ShowOrHide(line.tooltipFrame,not spellData.user)
			BH.lib.ShowOrHide(line.spellName,not spellData.user)
			BH.lib.ShowOrHide(line.class,not spellData.user)
			BH.lib.ShowOrHide(line.userSpellName,spellData.user)
			BH.lib.ShowOrHide(line.userClass,spellData.user)
			BH.lib.ShowOrHide(line.userRemove,spellData.user)

			line.dropDownPriority:SetText(format("%d",VBH.ExCD2.Priority[SpellID] or 15))

			if spellData.user then
				line.userSpellName:SetText(SpellID or "")

				line.userClass:SetText("|c"..BH.F.classColor(spellData[2])..L.classLocalizate[ spellData[2] ])
				
				line.isUserSpell = true
			else
				line.isUserSpell = nil
			end
			
			if SpellID == 161642 then
				line.additionalTooltip = L.cd2ResurrectTooltip
			else
				line.additionalTooltip = nil
			end
		end
		GameTooltip_Hide()
		BHLib.Tooltip:HideAdd()
		--page.ScrollBar:UpdateButtons()
	end
	
	--self.ScrollBar = BHLib:ScrollBar(self.borderList,"UIPanelScrollUPButtonTemplate"):Size(16,0):Point("TOPRIGHT",-3,-3):Point("BOTTOMRIGHT",-3,3):ClickRange(32):Range(0,20):SetTo(0):OnChange(module.options.ReloadSpellsPage)

	--function self.ScrollBar:UpdateRange()
	--	self:SetMinMaxValues(0,max((#module.db.bhspellDB+1)*SPELL_LINE_HEIGHT-SPELL_PAGE_HEIGHT,0))
	--end
	
	--[[self:SetScript("OnMouseWheel", function(self, delta)
		delta = -delta
		local current = module.options.ScrollBar:GetValue()
		local min_,max_ = module.options.ScrollBar:GetMinMaxValues()
		current = current + (delta * SPELL_LINE_HEIGHT)
		if current > max_ then
			current = max_
		elseif current < min_ then
			current = min_
		end
		module.options.ScrollBar:SetValue(current)
	end)]]
	
	local function SpellsListChkOnClick(self)
		if self:GetChecked() then
			VBH.ExCD2.CDE[self:GetParent().sid] = true
		else
			VBH.ExCD2.CDE[self:GetParent().sid] = nil
		end
		UpdateRoster()
	end
	local function SpellsListOnUpdate(self)
		if MouseIsOver(self) and not BH.lib.ScrollDropDown.DropDownList[1]:IsShown() then
			self.backClassColor:SetGradientAlpha("HORIZONTAL", self.backClassColorR, self.backClassColorG, self.backClassColorB, 0.8, self.backClassColorR, self.backClassColorG, self.backClassColorB, 0)
		else
			self.backClassColor:SetGradientAlpha("HORIZONTAL", self.backClassColorR, self.backClassColorG, self.backClassColorB, 0.4, self.backClassColorR, self.backClassColorG, self.backClassColorB, 0)
		end
	end
	local function SpellsListTooltipFrameOnEnter(self)
		BHLib.Tooltip.Link(self,self:GetParent().spellName:GetText())
		if self:GetParent().additionalTooltip then
			BHLib.Tooltip:Add(nil,{self:GetParent().additionalTooltip})
		end
	end
	local function SpellsListTooltipFrameOnLeave()
		GameTooltip_Hide()
		BHLib.Tooltip:HideAdd()
	end
	local SpellsListDropDownPriorityDataList = {}
	local function SpellsListDropDownPrioritySelectFunc(self,arg)
		local list = self:GetParent().parent
		list:SetText(arg)
		VBH.ExCD2.Priority[list:GetParent().sid] = arg
		BHLib:DropDownClose()
		UpdateRoster()
	end
	for i=1,30 do
		SpellsListDropDownPriorityDataList[i] = {text=i,justifyH="CENTER",arg1=i,func=SpellsListDropDownPrioritySelectFunc}
	end
	local function SpellsListDropDownPriorityOnEnter(self)
		BHLib.Tooltip.Show(self,"ANCHOR_LEFT",L.cd2Priority,{L.cd2PriorityTooltip,1,1,1,true})
	end
	local function SpellsListUserSpellNameOnTextChanged(self,isUser)
		if not isUser then
			return
		end
		local tmp = nil
		local spellID = tonumber(self:GetText())
		local parentLine = self:GetParent()
		if spellID then
			for j=1,#module.db.bhspellDB do
				if module.db.bhspellDB[j][1] == spellID and j ~= parentLine.tid then
					parentLine.chk:Disable()
					parentLine.chk:SetAlpha(0.5)
					return
				end
			end
		end
	
		CheckToNil(parentLine)
		if not spellID then 
			parentLine.chk:Disable()
			parentLine.chk:SetAlpha(0.5)
			return 
		end
		local spellName,_,spellTexture = GetSpellInfo(spellID)
		parentLine.sid = spellID
		parentLine.icon:SetTexture(spellTexture or "Interface\\Icons\\INV_MISC_QUESTIONMARK")
		if not spellName then
			parentLine.chk:Disable()
			parentLine.chk:SetAlpha(0.5)
		else
			parentLine.chk:Enable()
			parentLine.chk:SetAlpha(1)
		end
		module.db.bhspellDB[parentLine.tid][1] = spellID
		SyncUserDB()
	end
	local function SpellsListUserSpellNameOnEnter(self)
		local spellID = tonumber(self:GetText())
		if spellID then
			local spellName = GetSpellInfo(spellID)
			if spellName then
				BHLib.Tooltip.Link(self,format("|Hspell:%d|hspell|h",spellID))
			else
				BHLib.Tooltip.Std(self)
			end
		else
			BHLib.Tooltip.Std(self)
		end
	end

	local SpellsListClassDropDownList = {}
	local function SpellsListUserClassDropDownClick(self,classNum,isAll)
		local parent = self:GetParent().parent
		local parentLine = parent:GetParent()
		local class = isAll and "ALL" or module.db.bhclassNames[classNum]
		CheckToNil(parentLine)
		BHLib:DropDownClose()
		parent:SetText("|c"..BH.F.classColor(class)..L.classLocalizate[ class ])
		module.db.bhspellDB[parentLine.tid][2] = class
		local cR,cG,cB = BH.F.classColorNum(class)
		parentLine.backClassColorR = cR
		parentLine.backClassColorG = cG
		parentLine.backClassColorB = cB
		SyncUserDB()
	end
	for i=1,#module.db.bhclassNames do
		SpellsListClassDropDownList[#SpellsListClassDropDownList + 1] = {
			text = "|c"..BH.F.classColor(module.db.bhclassNames[i])..L.classLocalizate[ module.db.bhclassNames[i] ],
			justifyH = "CENTER",
			arg1 = i,
			func = SpellsListUserClassDropDownClick,
		}
	end
	SpellsListClassDropDownList[#SpellsListClassDropDownList + 1] = {
		text = "|c"..BH.F.classColor("ALL")..L.classLocalizate[ "ALL" ],
		justifyH = "CENTER",
		arg1 = 0,
		arg2 = true,
		func = SpellsListUserClassDropDownClick,
	}	
	
	
	self.spellsListScrollFrame = CreateFrame("ScrollFrame", nil, self.borderList)
	self.spellsListScrollFrame:SetPoint("TOPLEFT")
	self.spellsListScrollFrame:SetPoint("BOTTOMRIGHT")
	
	self.spellsListScrollFrameContent = CreateFrame("Frame", nil, self.spellsListScrollFrame)
	self.spellsListScrollFrameContent:SetPoint("TOPLEFT",0,0)
	self.spellsListScrollFrameContent:SetSize(self.spellsListScrollFrame:GetSize())
	self.spellsListScrollFrame:SetScrollChild(self.spellsListScrollFrameContent)
	
	self.spellsList = {}
	for i=1,(SPELL_PER_PAGE+2) do
		local line = CreateFrame("Frame",nil,self.spellsListScrollFrameContent)
		self.spellsList[i] = line
		line:SetPoint("TOPLEFT",0,-(i-1)*SPELL_LINE_HEIGHT)
		line:SetPoint("RIGHT",-10,0)
		line:SetHeight(SPELL_LINE_HEIGHT)

		line.chk = BHLib:Check(line,"","",0):Point("LEFT",0,0):OnClick(SpellsListChkOnClick)
		line.chk._i = i
		
		line.backClassColor = line:CreateTexture(nil, "BACKGROUND")
		line.backClassColor:SetPoint("LEFT",0,0)
		line.backClassColor:SetSize(250,SPELL_LINE_HEIGHT)
		line.backClassColor:SetColorTexture(1, 1, 1, 1)
		line.backClassColorR = 0
		line.backClassColorG = 0
		line.backClassColorB = 0
		
		line:SetScript("OnUpdate",SpellsListOnUpdate)
	
		line.icon = line:CreateTexture(nil, "ARTWORK")
		line.icon:SetSize(28,28)
		line.icon:SetPoint("LEFT", 35, 0)
		line.icon:SetTexCoord(.1,.9,.1,.9)
		BHLib:Border(line.icon,1,.12,.13,.15,1)
	
		line.tooltipFrame = CreateFrame("Frame",nil,line)
		line.tooltipFrame:SetSize(150,SPELL_LINE_HEIGHT) 
		line.tooltipFrame:SetPoint("LEFT", 70, 0)
		line.tooltipFrame._i = i
		line.tooltipFrame:SetScript("OnEnter", SpellsListTooltipFrameOnEnter)
		line.tooltipFrame:SetScript("OnLeave", SpellsListTooltipFrameOnLeave)

		line.spellName = BHLib:Text(line):Size(155,SPELL_LINE_HEIGHT):Point("LEFT",70,0):Font(BH.F.defFont,12):Shadow()
	
		line.class = BHLib:Text(line):Size(180,SPELL_LINE_HEIGHT):Point("LEFT",235,0):Font(BH.F.defFont,14):Shadow()
	
		line.dropDownPriority = BHLib:DropDown(line,100,15):Size(80):Point("RIGHT",-10,0)
		line.dropDownPriority._i = i
		line.dropDownPriority.List = SpellsListDropDownPriorityDataList
		line.dropDownPriority:SetScript("OnEnter",SpellsListDropDownPriorityOnEnter)
		line.dropDownPriority:SetScript("OnLeave",BHLib.Tooltip.Hide)

		line.userSpellName = BHLib:Edit(line,6,true):Size(145,20):Point("LEFT",70,0):Tooltip(L.cd2SpellID):OnChange(SpellsListUserSpellNameOnTextChanged)
		line.userSpellName._i = i
		line.userSpellName:SetScript("OnEnter",SpellsListUserSpellNameOnEnter)
		line.userSpellName:SetScript("OnLeave",BHLib.Tooltip.Hide)
		
		line.userClass = BHLib:DropDown(line,130,13):Size(140):Point("LEFT",225,0):SetText(L.cd2Class)
		line.userClass._i = i
		line.userClass.List = SpellsListClassDropDownList

		line.userClass:Hide()
	end
	
	
	
	--page spell choix colonnes
	
	self.colsSpells = CreateFrame("Frame",nil,self.tab.tabs[1])
	self.colsSpells:SetSize(600,SPELL_PAGE_HEIGHT)
	self.colsSpells:SetPoint("TOP", 10, -40)
	--BHLib:Border(self.colsSpells,2,.24,.25,.30,1)
	self.colsSpells:Hide()
	
	self.colsSpells.ScrollFrame = CreateFrame("ScrollFrame", nil, self.colsSpells)
	self.colsSpells.ScrollFrame:SetPoint("TOPLEFT")
	self.colsSpells.ScrollFrame:SetPoint("BOTTOMRIGHT")
	
	self.colsSpells.C = CreateFrame("Frame", nil, self.colsSpells) 
	self.colsSpells.C:SetSize(600,SPELL_PAGE_HEIGHT)
	self.colsSpells.ScrollFrame:SetScrollChild(self.colsSpells.C)
	
	local function ColsSpellsUpdate()
		--local val = self.colsSpells.ScrollBar:GetValue()
		--self.colsSpells.ScrollBar:UpdateButtons()
		--module.options.colsSpells.ScrollFrame:SetVerticalScroll( val % 24 )
		local val = floor( 1 ) + 1
		local line = 0
		local count = 0
		for i=1,#module.db.bhspellDB do
			local spellData = module.db.bhspellDB[i]
			local spellID = spellData[1]
			if VBH_CDE[ spellID ] then
				local class = spellData[2]
				local specsCount = module.db.bhspecByClass[class] and #module.db.bhspecByClass[class] or 1
			
				for j=3,3+specsCount do
					if spellData[j] then
						count = count + 1
						if count >= val then
							line = line + 1
							if line > #self.colsSpells.lines then
								return
							end
							local lineFrame = self.colsSpells.lines[line]
							lineFrame:Show()
							
							local spellName,_,spellTexture = GetSpellInfo(spellID)
							lineFrame.icon:SetTexture(spellTexture)
							lineFrame.spellName:SetText(spellName)
							lineFrame.link = "spell:"..(spellData[j][1] or spellID)
							
							for k=1,3 do
								lineFrame.chk[k]:SetChecked(false)
							end
							local checked = VBH.ExCD2.CDECol[spellData[j][1]..";"..(j-2)] or module.db.bhdef_col[spellData[j][1]..";"..(j-2)] or 1
							lineFrame.chk[checked]:SetChecked(true)
							
							lineFrame.spellID = spellData[j][1]
							lineFrame.specNum = j-2
						end
					end
				end
			end
		end
		for i=line+1,#self.colsSpells.lines do
			self.colsSpells.lines[i]:Hide()
		end
	end
	self.colsSpells:SetScript("OnShow",function(self)
		local count = 0
		for i=1,#module.db.bhspellDB do
			local spellData = module.db.bhspellDB[i]
			if VBH_CDE[ spellData[1] ] then
				local class = spellData[2]
				local specsCount = module.db.bhspecByClass[class] and #module.db.bhspecByClass[class] or 1
				for j=3,3+specsCount do
					if spellData[j] then
						count =  count + 1
					end
				end
			end
		end
	
		--self.ScrollBar:SetMinMaxValues(0,max(0,(count+0.2)*24-SPELL_PAGE_HEIGHT))
		ColsSpellsUpdate()
	end)
	--[[self.colsSpells:SetScript("OnMouseWheel", function(self, delta)
		delta = -delta
		local current = module.options.colsSpells.ScrollBar:GetValue()
		local min_,max_ = module.options.colsSpells.ScrollBar:GetMinMaxValues()
		current = current + delta * 24
		if current > max_ then
			current = max_
		elseif current < min_ then
			current = min_
		end
		module.options.colsSpells.ScrollBar:SetValue(current)
	end)]]
	
	--self.colsSpells.ScrollBar = BHLib:ScrollBar(self.colsSpells):Size(16,0):Point("TOPRIGHT",-3,-3):Point("BOTTOMRIGHT",-3,3):Range(0,SPELL_PAGE_HEIGHT):SetTo(0):OnChange(ColsSpellsUpdate)
	--self.colsSpells.ScrollBar.slider:SetObeyStepOnDrag(true)
	
	self.colsSpells.lines = {}
	local function ColsSpellsSpellTooltipOnEnter(self)
		BHLib.Tooltip.Link(self,self:GetParent().link)
	end
	local function ColsSpellsSpellCheckboxClick(self)
		for j=1,3 do
			if j ~= self._i then
				self.array[j]:SetChecked(false)
			end
		end
		if not self:GetChecked() then
			self:SetChecked(true)
		end
		VBH.ExCD2.CDECol[self.main.spellID..";"..self.main.specNum] = self._i
		
		UpdateRoster()
	end
	for i=1,23 do
		local frame = CreateFrame("Frame",nil,self.colsSpells.C)
		self.colsSpells.lines[i] = frame
		frame:SetPoint("TOPLEFT",5,-3-(i-1)*28)
		frame:SetSize(577,28)
		
		frame.icon = frame:CreateTexture(nil, "ARTWORK")
		frame.icon:SetSize(28,28)
		frame.icon:SetPoint("TOPLEFT", 2, 0)
		frame.icon:SetTexCoord(.1,.9,.1,.9)
		BHLib:Border(frame.icon,1,.12,.13,.15,1)
		
		frame.tooltipFrame = CreateFrame("Frame",nil,frame)
		frame.tooltipFrame:SetSize(150,24) 
		frame.tooltipFrame:SetPoint("TOPLEFT", 30, 0)
		frame.tooltipFrame:SetScript("OnEnter", ColsSpellsSpellTooltipOnEnter)
		frame.tooltipFrame:SetScript("OnLeave", GameTooltip_Hide)
		
		frame.spellName = BHLib:Text(frame):Size(156,24):Point(40,0):Font(BH.F.defFont,11):Shadow():Color()
	
		--frame.iconClass = frame:CreateTexture(nil, "ARTWORK")
		--frame.iconClass:SetSize(18,18)
		--frame.iconClass:SetPoint("TOPLEFT", 180, -3)
		
		--frame.iconSpec = frame:CreateTexture(nil, "ARTWORK")
		--frame.iconSpec:SetSize(18,18)
		--frame.iconSpec:SetPoint("TOPLEFT", 200, -3)
		
		frame.chk = {}
		for j=1,3 do
			frame.chk[j] = BHLib:Check(frame,"","",0):Point("LEFT",240 + (j-1) * 25,0):Tooltip(j):OnClick(ColsSpellsSpellCheckboxClick)
			frame.chk[j].array = frame.chk
			frame.chk[j]._i = j
			frame.chk[j].main = frame
		end
	end
	
	--module.options.ScrollBar:UpdateRange()
	module.options:ReloadSpellsPage()
	


	--> OPTIONS TAB2: Customize
	-- self.optColHeader = BHLib:Text(self.tab.tabs[2],L.cd2ColSet):Size(560,20):Point(15,-8)
	
	function self:selectColumnTab()
		local i = self and self.colID or module.options.optColTabs.selected
		module.options.optColTabs.selected = i
		module.options.optColTabs:UpdateTabs()
		
		local isGeneralTab = i == (module.db.bhmaxColumns + 1)
		
		if isGeneralTab then
			VBH.ExCD2.colSet[i].frameGeneral = nil
			VBH.ExCD2.colSet[i].iconGeneral = nil
			VBH.ExCD2.colSet[i].textureGeneral = nil
			VBH.ExCD2.colSet[i].fontGeneral = nil
			VBH.ExCD2.colSet[i].textGeneral = nil
			VBH.ExCD2.colSet[i].methodsGeneral = nil
		end

		module.options.optColSet.chkEnable:SetChecked(VBH.ExCD2.colSet[i].enabled)
		module.options.optColSet.chkGeneral:SetChecked(VBH.ExCD2.colSet[i].frameGeneral)
		
		module.options.optColSet.sliderLinesNum:SetValue(VBH.ExCD2.colSet[i].frameLines or module.db.bhcolsDefaults.frameLines)
		module.options.optColSet.sliderAlpha:SetValue(VBH.ExCD2.colSet[i].frameAlpha or module.db.bhcolsDefaults.frameAlpha)
		module.options.optColSet.sliderScale:SetValue(VBH.ExCD2.colSet[i].frameScale or module.db.bhcolsDefaults.frameScale)
		module.options.optColSet.sliderWidth:SetValue(VBH.ExCD2.colSet[i].frameWidth or module.db.bhcolsDefaults.frameWidth)
		module.options.optColSet.sliderColsInCol:SetValue(VBH.ExCD2.colSet[i].frameColumns or module.db.bhcolsDefaults.frameColumns)
		module.options.optColSet.sliderBetweenLines:SetValue(VBH.ExCD2.colSet[i].frameBetweenLines or module.db.bhcolsDefaults.frameBetweenLines)
		module.options.optColSet.sliderBlackBack:SetValue(VBH.ExCD2.colSet[i].frameBlackBack or module.db.bhcolsDefaults.frameBlackBack)
		
		module.options.optColSet.chkGeneral:doAlphas()
		
		module.options.optColSet.sliderHeight:SetValue(VBH.ExCD2.colSet[i].iconSize or module.db.bhcolsDefaults.iconSize)
		module.options.optColSet.chkGray:SetChecked(VBH.ExCD2.colSet[i].iconGray)
		module.options.optColSet.chkCooldown:SetChecked(VBH.ExCD2.colSet[i].methodsCooldown)	
		module.options.optColSet.chkCooldownHideNumbers:SetChecked(VBH.ExCD2.colSet[i].iconCooldownHideNumbers)	
		module.options.optColSet.chkCooldownShowSwipe:SetChecked(VBH.ExCD2.colSet[i].iconCooldownShowSwipe)	
		module.options.optColSet.chkShowTitles:SetChecked(VBH.ExCD2.colSet[i].iconTitles)	
		module.options.optColSet.chkHideBlizzardEdges:SetChecked(VBH.ExCD2.colSet[i].iconHideBlizzardEdges)	
		module.options.optColSet.chkGeneralIcons:SetChecked(VBH.ExCD2.colSet[i].iconGeneral)
		do
			local defIconPos = VBH.ExCD2.colSet[i].iconPosition or module.db.bhcolsDefaults.iconPosition
			module.options.optColSet.dropDownIconPos:SetText( module.options.optColSet.dropDownIconPos.PosNames[defIconPos])	
		end
		
		module.options.optColSet.chkGeneralIcons:doAlphas()
		
		do
			local texturePos = nil
			for j=1,#BH.F.textureList do
				if BH.F.textureList[j] == (VBH.ExCD2.colSet[i].textureFile or BH.F.barImg) then
					texturePos = j
					break
				end
			end
			if not texturePos and VBH.ExCD2.colSet[i].textureFile then
				texturePos = select(3,string.find(VBH.ExCD2.colSet[i].textureFile,"\\([^\\]*)$"))
			end
			texturePos = texturePos or "Standart"
			module.options.optColSet.dropDownTexture:SetText(L.cd2OtherSetTexture.." ["..texturePos.."]")
		end
		module.options.optColSet.colorPickerBorder.color:SetColorTexture(VBH.ExCD2.colSet[i].textureBorderColorR or module.db.bhcolsDefaults.textureBorderColorR,VBH.ExCD2.colSet[i].textureBorderColorG or module.db.bhcolsDefaults.textureBorderColorG,VBH.ExCD2.colSet[i].textureBorderColorB or module.db.bhcolsDefaults.textureBorderColorB, VBH.ExCD2.colSet[i].textureBorderColorA or module.db.bhcolsDefaults.textureBorderColorA)
		module.options.optColSet.sliderBorderSize:SetValue(VBH.ExCD2.colSet[i].textureBorderSize or module.db.bhcolsDefaults.textureBorderSize)
		module.options.optColSet.chkAnimation:SetChecked(VBH.ExCD2.colSet[i].textureAnimation)
		module.options.optColSet.chkHideSpark:SetChecked(VBH.ExCD2.colSet[i].textureHideSpark)
		module.options.optColSet.chkSmoothAnimation:SetChecked(VBH.ExCD2.colSet[i].textureSmoothAnimation)
		module.options.optColSet.sliderSmoothAnimationDuration:SetValue(VBH.ExCD2.colSet[i].textureSmoothAnimationDuration or module.db.bhcolsDefaults.textureSmoothAnimationDuration)
		module.options.optColSet.chkGeneralColorize:SetChecked(VBH.ExCD2.colSet[i].textureGeneral)
		
		module.options.optColSet.chkGeneralColorize:doAlphas()
			
		do
			local FontNameForDropDown = select(3,string.find(VBH.ExCD2.colSet[i].fontName or module.db.bhcolsDefaults.fontName,"\\([^\\]*)$"))
			module.options.optColSet.dropDownFont:SetText( (FontNameForDropDown or VBH.ExCD2.colSet[i].fontName or module.db.bhcolsDefaults.fontName or "?") )
		end
		module.options.optColSet.sliderFont:SetValue(VBH.ExCD2.colSet[i].fontSize or module.db.bhcolsDefaults.fontSize)
		module.options.optColSet.chkFontOutline:SetChecked(VBH.ExCD2.colSet[i].fontOutline)
		module.options.optColSet.chkFontShadow:SetChecked(VBH.ExCD2.colSet[i].fontShadow)
		do
			module.options.optColSet.chkFontOtherAvailable:SetChecked(VBH.ExCD2.colSet[i].fontOtherAvailable)
			module.options.fontOtherAvailable(VBH.ExCD2.colSet[i].fontOtherAvailable)
			if VBH.ExCD2.colSet[i].fontOtherAvailable then
				module.options.optColSet.nowFont = "fontLeft"
			else
				module.options.optColSet.nowFont = "font"
			end
			module.options.optColSet.fontsTab.selectFunc(module.options.optColSet.fontsTab.tabs[1].button)
		end
		module.options.optColSet.chkGeneralFont:SetChecked(VBH.ExCD2.colSet[i].fontGeneral)
		
		module.options.optColSet.chkGeneralFont:doAlphas()
		
		module.options.optColSet.textLeftTemEdit:SetText(VBH.ExCD2.colSet[i].textTemplateLeft or module.db.bhcolsDefaults.textTemplateLeft)
		module.options.optColSet.textRightTemEdit:SetText(VBH.ExCD2.colSet[i].textTemplateRight or module.db.bhcolsDefaults.textTemplateRight)
		module.options.optColSet.textCenterTemEdit:SetText(VBH.ExCD2.colSet[i].textTemplateCenter or module.db.bhcolsDefaults.textTemplateCenter)
		module.options.optColSet.chkIconName:SetChecked(VBH.ExCD2.colSet[i].textIconName)
		module.options.optColSet.chkGeneralText:SetChecked(VBH.ExCD2.colSet[i].textGeneral)
		
		module.options.optColSet.chkGeneralText:doAlphas()

		module.options.optColSet.chkShowOnlyOnCD:SetChecked(VBH.ExCD2.colSet[i].methodsShownOnCD)
		module.options.optColSet.chkBotToTop:SetChecked(VBH.ExCD2.colSet[i].frameAnchorBottom)
		module.options.optColSet.chkGeneralMethods:SetChecked(VBH.ExCD2.colSet[i].methodsGeneral)
		do
			local defStyleAnimation = VBH.ExCD2.colSet[i].methodsStyleAnimation or module.db.bhcolsDefaults.methodsStyleAnimation
			module.options.optColSet.dropDownStyleAnimation:SetText( module.options.optColSet.dropDownStyleAnimation.Styles[defStyleAnimation])
			local defTimeLineAnimation = VBH.ExCD2.colSet[i].methodsTimeLineAnimation or module.db.bhcolsDefaults.methodsTimeLineAnimation
			module.options.optColSet.dropDownTimeLineAnimation:SetText(module.options.optColSet.dropDownTimeLineAnimation.Styles[defTimeLineAnimation])
			
			local defSortingRules = VBH.ExCD2.colSet[i].methodsSortingRules or module.db.bhcolsDefaults.methodsSortingRules
			module.options.optColSet.dropDownSortingRules:SetText(module.options.optColSet.dropDownSortingRules.Rules[defSortingRules])			
		end
		module.options.optColSet.chkIconTooltip:SetChecked(VBH.ExCD2.colSet[i].methodsIconTooltip)
		module.options.optColSet.chkLineClick:SetChecked(VBH.ExCD2.colSet[i].methodsLineClick)
		module.options.optColSet.chkLineClickWhisper:SetChecked(VBH.ExCD2.colSet[i].methodsLineClickWhisper)
		module.options.optColSet.chkNewSpellNewLine:SetChecked(VBH.ExCD2.colSet[i].methodsNewSpellNewLine)
		module.options.optColSet.chkHideOwnSpells:SetChecked(VBH.ExCD2.colSet[i].methodsHideOwnSpells)
		module.options.optColSet.chkAlphaNotInRange:SetChecked(VBH.ExCD2.colSet[i].methodsAlphaNotInRange)
		module.options.optColSet.sliderAlphaNotInRange:SetValue(VBH.ExCD2.colSet[i].methodsAlphaNotInRangeNum or module.db.bhcolsDefaults.methodsAlphaNotInRangeNum)
		module.options.optColSet.chkDisableActive:SetChecked(VBH.ExCD2.colSet[i].methodsDisableActive)
		module.options.optColSet.chkOneSpellPerCol:SetChecked(VBH.ExCD2.colSet[i].methodsOneSpellPerCol)
		module.options.optColSet.chkOnlyInCombat:SetChecked(VBH.ExCD2.colSet[i].methodsOnlyInCombat)

		module.options.optColSet.chkGeneralMethods:doAlphas()
		
		module.options.optColSet.blacklistEditBox.EditBox:SetText(VBH.ExCD2.colSet[i].blacklistText or module.db.bhcolsDefaults.blacklistText)
		module.options.optColSet.whitelistEditBox.EditBox:SetText(VBH.ExCD2.colSet[i].whitelistText or module.db.bhcolsDefaults.whitelistText)
		module.options.optColSet.chkGeneralBlackList:SetChecked(VBH.ExCD2.colSet[i].blacklistGeneral)		
		
		module.options.optColSet.chkGeneralBlackList:doAlphas()
		
		module.options.optColSet.chkVisibilityPartyTypeAlways:SetChecked(not VBH.ExCD2.colSet[i].visibilityPartyType)
		module.options.optColSet.chkVisibilityPartyTypeParty:SetChecked(VBH.ExCD2.colSet[i].visibilityPartyType == 1)
		module.options.optColSet.chkVisibilityPartyTypeRaid:SetChecked(VBH.ExCD2.colSet[i].visibilityPartyType == 2)
		module.options.optColSet.chkVisibilityZoneArena:SetChecked(not VBH.ExCD2.colSet[i].visibilityDisableArena)
		module.options.optColSet.chkVisibilityZoneBG:SetChecked(not VBH.ExCD2.colSet[i].visibilityDisableBG)
		module.options.optColSet.chkVisibilityZoneScenario:SetChecked(not VBH.ExCD2.colSet[i].visibilityDisable3ppl)
		module.options.optColSet.chkVisibilityZone5ppl:SetChecked(not VBH.ExCD2.colSet[i].visibilityDisable5ppl)
		module.options.optColSet.chkVisibilityZoneRaid:SetChecked(not VBH.ExCD2.colSet[i].visibilityDisableRaid)
		module.options.optColSet.chkVisibilityZoneOutdoor:SetChecked(not VBH.ExCD2.colSet[i].visibilityDisableWorld)
		module.options.optColSet.chkGeneralVisibility:SetChecked(VBH.ExCD2.colSet[i].visibilityGeneral)

		module.options.optColSet.chkGeneralVisibility:doAlphas()

		BH.lib.ShowOrHide(module.options.optColSet.chkEnable,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneral,not isGeneralTab)

		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralIcons,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralColorize,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralFont,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralText,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralMethods,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralVisibility,not isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkGeneralBlackList,not isGeneralTab)
		
		BH.lib.ShowOrHide(module.options.optColSet.chkSortByAvailability,isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkSortByAvailability_activeToTop,isGeneralTab)
		BH.lib.ShowOrHide(module.options.optColSet.chkReverseSorting,isGeneralTab)
		
		module.options.showColorFrame(module.options.colorSetupFrame)
		
		if self then
			module.options.optColSet.templateRestore:Hide()
		end
	end

	self.optColSet = {}
	
	-- menu page apparence choix colone option genrale
	do
		local tmpArr = {}
		for i=1,module.db.bhmaxColumns do
			tmpArr[i] = tostring(i)
		end
		tmpArr[module.db.bhmaxColumns+1] = L.cd2GeneralSet
		self.optColTabs = BHLib:Tabs(self.tab.tabs[2],0,unpack(tmpArr)):Size(600,100):Point(0,-29):SetTo(module.db.bhmaxColumns+1)
	end
	for i=1,module.db.bhmaxColumns+1 do
		self.optColTabs.tabs[i].button.colID = i
		self.optColTabs.tabs[i].button:SetScript("OnClick", self.selectColumnTab)
	end
	
	self.optColTabs:SetBackdropBorderColor(0,0,0,0)
	self.optColTabs:SetBackdropColor(0,0,0,0)
	
	-- creation liste menu option
 
	self.optColSet.superTabFrame = BH.lib:ScrollTabsFrame(self.optColTabs,L.cd2OtherSetTabNameGeneral,L.cd2OtherSetTabNameIcons,L.cd2OtherSetTabNameColors,L.cd2OtherSetTabNameFont,
	L.cd2OtherSetTabNameText,L.cd2OtherSetTabNameOther,L.cd2OtherSetTabNameVisibility,L.cd2OtherSetTabNameBlackList,L.cd2OtherSetTabNameTemplate):Size(600,430):Point("TOP",0,-10)	
	
	--option generale
	
	self.optColSet.chkEnable = BHLib:Check(self.optColSet.superTabFrame.tab[1],"|cff00ff00 >>>"..L.senable.."<<<","",0):Point(10,-10):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].enabled = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].enabled = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneral = BHLib:Check(self.optColSet.superTabFrame.tab[1],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].frameGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].frameGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneral:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].frameGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.sliderLinesNum,module.options.optColSet.sliderAlpha,module.options.optColSet.sliderScale,module.options.optColSet.sliderWidth,module.options.optColSet.sliderColsInCol,module.options.optColSet.sliderBetweenLines,module.options.optColSet.sliderBlackBack,module.options.optColSet.butToCenter)	
	end
	
	self.optColSet.sliderLinesNum = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2lines,false,0):Size(300,20):Point("TOP",0,-50):Range(1,module.db.bhmaxLinesInCol):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameLines = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()		
	end)
	
	self.optColSet.sliderWidth = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2width,false,0):Size(300,20):Point("TOP",0,-85):Range(1,400):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameWidth = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderAlpha = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2alpha,false,0):Size(300,20):Point("TOP",0,-120):Range(0,100):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameAlpha = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderScale = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2scale,false,0):Size(300,20):Point("TOP",0,-155):Range(5,200):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameScale = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits("ScaleFix")
	end)
	
	self.optColSet.sliderColsInCol = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2ColSetColsInCol,false,0):Size(300,20):Point("TOP",0,-190):Range(1,module.db.bhmaxLinesInCol):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameColumns = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderBetweenLines = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2ColSetBetweenLines,false,0):Size(300,20):Point("TOP",0,-225):Range(0,20):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameBetweenLines = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderBlackBack = BHLib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2BlackBack,false,0):Size(300,20):Point("TOP",0,-260):Range(0,100):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].frameBlackBack = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)

	self.optColSet.butToCenter = BHLib:Button(self.optColSet.superTabFrame.tab[1],L.cd2ColSetResetPos):Size(200,20):Point("TOP",0,-295):OnClick(function(self) 
		if (module.db.bhmaxColumns + 1) == module.options.optColTabs.selected then
			module.frame:ClearAllPoints()
			module.frame:SetPoint("CENTER",UIParent,"CENTER",0,0)
		else
			module.frame.colFrame[module.options.optColTabs.selected]:ClearAllPoints()
			module.frame.colFrame[module.options.optColTabs.selected]:SetPoint("CENTER",UIParent,"CENTER",0,0)
		end
	end) 

	--> Icon and height options
	
	self.optColSet.sliderHeight = BHLib:Slider(self.optColSet.superTabFrame.tab[2],L.cd2OtherSetIconSize,false,0):Size(300,20):Point("TOP",0,-50):Range(6,128):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].iconSize = event
		module:ReloadAllSplits()
		self.tooltipText = event
		self:tooltipReload(self)
	end)
	
	self.optColSet.chkGray = BHLib:Check(self.optColSet.superTabFrame.tab[2],L.cd2graytooltip,"",0):Point(10,-110):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconGray = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconGray = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.textIconPos = BHLib:Text(self.optColSet.superTabFrame.tab[2],L.cd2OtherSetIconPosition..":"):Size(200,20):Point(10,-85)
	self.optColSet.dropDownIconPos = BHLib:DropDown(self.optColSet.superTabFrame.tab[2],190,3):Size(200):Point(180,-85)
	self.optColSet.dropDownIconPos.PosNames = {L.cd2OtherSetIconPositionLeft,L.cd2OtherSetIconPositionRight,L.cd2OtherSetIconPositionNo}
	for i=1,#self.optColSet.dropDownIconPos.PosNames do
		self.optColSet.dropDownIconPos.List[i] = {
			text = self.optColSet.dropDownIconPos.PosNames[i],
			arg1 = i,
			func = function (self,arg)
				BHLib:DropDownClose()
				VBH.ExCD2.colSet[module.options.optColTabs.selected].iconPosition = arg
				module:ReloadAllSplits()
				module.options.optColSet.dropDownIconPos:SetText(module.options.optColSet.dropDownIconPos.PosNames[arg])
			end,
		}
	end
	
	self.optColSet.chkCooldown = BHLib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetMethodCooldown,"",0):Point(10,-135):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsCooldown = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsCooldown = nil
		end
		module:ReloadAllSplits()
	end)

	self.optColSet.chkCooldownHideNumbers = BHLib:Check(self.optColSet.superTabFrame.tab[2],L.BattleResHideTime,"",0):Point("TOPLEFT",self.optColSet.chkCooldown,25,-25):Tooltip(L.BattleResHideTimeTooltip):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconCooldownHideNumbers = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconCooldownHideNumbers = nil
		end
		module:ReloadAllSplits()
	end)

	self.optColSet.chkCooldownShowSwipe = BHLib:Check(self.optColSet.superTabFrame.tab[2],"Show edge","",0):Point("TOPLEFT",self.optColSet.chkCooldownHideNumbers,0,-25):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconCooldownShowSwipe = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconCooldownShowSwipe = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkShowTitles = BHLib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetShowTitles,"",0):Point("TOPLEFT",self.optColSet.chkCooldown,0,-75):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconTitles = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconTitles = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkHideBlizzardEdges = BHLib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetIconHideBlizzardEdges,"",0):Point("TOPLEFT",self.optColSet.chkShowTitles,0,-25):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconHideBlizzardEdges = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconHideBlizzardEdges = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneralIcons = BHLib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].iconGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralIcons:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].iconGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.chkGray,module.options.optColSet.sliderHeight,module.options.optColSet.dropDownIconPos,module.options.optColSet.chkCooldown,module.options.optColSet.chkShowTitles,module.options.optColSet.chkHideBlizzardEdges,module.options.optColSet.chkCooldownShowSwipe,module.options.optColSet.chkCooldownHideNumbers)
	end
	
	--> Texture and colors Options
	
	local function dropDownTextureButtonClick(self,arg,name)
		BHLib:DropDownClose()
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textureFile = arg
		module:ReloadAllSplits()
		module.options.optColSet.dropDownTexture:SetText(L.cd2OtherSetTexture.." ["..name.."]")
	end

	self.optColSet.textDDTexture = BHLib:Text(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetTexture..":"):Size(200,20):Point(10,-35)
	self.optColSet.dropDownTexture = BHLib:DropDown(self.optColSet.superTabFrame.tab[3],200,15):Size(200):Point(180,-35)
	for i=1,#BH.F.textureList do
		self.optColSet.dropDownTexture.List[i] = {}
		local info = self.optColSet.dropDownTexture.List[i]
		info.text = i
		info.arg1 = BH.F.textureList[i]
		info.arg2 = i
		info.func = dropDownTextureButtonClick
		info.texture = BH.F.textureList[i]
		info.justifyH = "CENTER" 
	end
	if LibStub then
		local loaded,media = pcall(LibStub,"LibSharedMedia-3.0")
		if loaded and media then
			local barsList = media:HashTable("statusbar")
			if barsList then
				local count = #self.optColSet.dropDownTexture.List
				for key,texture in pairs(barsList) do
					count = count + 1
					self.optColSet.dropDownTexture.List[count] = {}
					local info = self.optColSet.dropDownTexture.List[count]
					
					info.text = key
					info.arg1 = texture
					info.arg2 = key
					info.func = dropDownTextureButtonClick
					info.texture = texture
					info.justifyH = "CENTER" 
				end
			end
		end
	end
	
	self.optColSet.textDDBorder = BHLib:Text(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetBorder..":"):Size(200,20):Point(10,-65)
	self.optColSet.sliderBorderSize = BHLib:Slider(self.optColSet.superTabFrame.tab[3],"",false,0):Size(170,20):Point(180,-68):Range(0,20):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderSize = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	self.optColSet.colorPickerBorder = BH.lib.CreateColorPickButton(self.optColSet.superTabFrame.tab[3],20,20,nil,361,-65)
	self.optColSet.colorPickerBorder:SetScript("OnClick",function (self)
		ColorPickerFrame.previousValues = {VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorR or module.db.bhcolsDefaults.textureBorderColorR,VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorG or module.db.bhcolsDefaults.textureBorderColorG,VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorB or module.db.bhcolsDefaults.textureBorderColorB, VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorA or module.db.bhcolsDefaults.textureBorderColorA}
		ColorPickerFrame.hasOpacity = true
		local nilFunc = BH.NULLfunc
		local function changedCallback(restore)
			local newR, newG, newB, newA
			if restore then
				newR, newG, newB, newA = unpack(restore)
			else
				newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB()
			end
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorR = newR
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorG = newG
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorB = newB
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorA = newA
			module:ReloadAllSplits()
			
			self.color:SetColorTexture(newR,newG,newB,newA)
		end
		ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = nilFunc, nilFunc, nilFunc
		ColorPickerFrame.opacity = VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorA or module.db.bhcolsDefaults.textureBorderColorA
		ColorPickerFrame:SetColorRGB(VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorR or module.db.bhcolsDefaults.textureBorderColorR,VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorG or module.db.bhcolsDefaults.textureBorderColorG,VBH.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorB or module.db.bhcolsDefaults.textureBorderColorB)
		ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = changedCallback, changedCallback, changedCallback
		ColorPickerFrame:Show()
	end)
		
	self.optColSet.chkAnimation = BHLib:Check(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetAnimation,"",0):Point(10,-97):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureAnimation = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureAnimation = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkHideSpark = BHLib:Check(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetHideSpark,"",0):Point(200,-97):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureHideSpark = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureHideSpark = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkSmoothAnimation = BHLib:Check(self.optColSet.superTabFrame.tab[3],L.cd2TextureSmoothAnim,"",0):Point(10,-122):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureSmoothAnimation = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureSmoothAnimation = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderSmoothAnimationDuration = BHLib:Slider(self.optColSet.superTabFrame.tab[3],"",false,0):Size(140,20):Point("TOP",self.optColSet.chkSmoothAnimation,0,-2):Point("LEFT",self.optColSet.chkSmoothAnimation.text,"RIGHT",20,0):Range(10,200):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textureSmoothAnimationDuration = event
		module:ReloadAllSplits()
		self.tooltipText = event / 100
		self:tooltipReload(self)
	end)
	self.optColSet.sliderSmoothAnimationDuration.Low:SetText("0.1")
	self.optColSet.sliderSmoothAnimationDuration.High:SetText("2")

	
	self.colorSetupFrame = CreateFrame("Frame",nil,self.optColSet.superTabFrame.tab[3])
	self.colorSetupFrame:SetSize(420,290)
	self.colorSetupFrame:SetPoint("TOP",0,-135)
		
	self.colorSetupFrame.backAlpha = BHLib:Slider(self.colorSetupFrame,L.cd2OtherSetColorFrameAlpha,false,0):Size(300,20):Point("TOP",0,-163):Range(0,100)
	self.colorSetupFrame.backCDAlpha = BHLib:Slider(self.colorSetupFrame,L.cd2OtherSetColorFrameAlphaCD,false,0):Size(300,20):Point("TOP",0,-198):Range(0,100)
	self.colorSetupFrame.backCooldownAlpha = BHLib:Slider(self.colorSetupFrame,L.cd2OtherSetColorFrameAlphaCooldown,false,0):Size(300,20):Point("TOP",0,-233):Range(0,100)
	self.colorSetupFrame.backAlpha.inOptName = "textureAlphaBackground"
	self.colorSetupFrame.backCDAlpha.inOptName = "textureAlphaTimeLine"
	self.colorSetupFrame.backCooldownAlpha.inOptName = "textureAlphaCooldown"
	
	local function colorPickerButtonClick(self)
		ColorPickerFrame.previousValues = {VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."R"] or module.db.bhcolsDefaults[self.inOptName.."R"],VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."G"] or module.db.bhcolsDefaults[self.inOptName.."G"],VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."B"] or module.db.bhcolsDefaults[self.inOptName.."B"], 1}
		local nilFunc = BH.NULLfunc
		local function changedCallback(restore)
			local newR, newG, newB, newA
			if restore then
				newR, newG, newB, newA = unpack(restore)
			else
				newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB()
			end
			VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."R"] = newR
			VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."G"] = newG
			VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."B"] = newB
			module:ReloadAllSplits()
			
			self.color:SetColorTexture(newR,newG,newB,1)
		end
		ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = nilFunc, nilFunc, nilFunc
		ColorPickerFrame:SetColorRGB(VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."R"] or module.db.bhcolsDefaults[self.inOptName.."R"],VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."G"] or module.db.bhcolsDefaults[self.inOptName.."G"],VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."B"] or module.db.bhcolsDefaults[self.inOptName.."B"])
		ColorPickerFrame.func, ColorPickerFrame.cancelFunc = changedCallback, changedCallback
		ColorPickerFrame:Show()
	end

	local function colorPickerSliderValue(self,newval)
		VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName] = newval / 100
		module:ReloadAllSplits()
		self.tooltipText = floor(newval +0.5)
		self:tooltipReload(self)
	end

	local function colorPickerCheckBoxClick(self)
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName] = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName] = nil
		end
		module:ReloadAllSplits()
	end
	
	local colorSetupFrameColorsNames_TopText = {L.cd2OtherSetColorFrameTopText,L.cd2OtherSetColorFrameTopBack,L.cd2OtherSetColorFrameTopTimeLine}
	for i=1,3 do
		self.colorSetupFrame["topText"..i] = BHLib:Text(self.colorSetupFrame,colorSetupFrameColorsNames_TopText[i],12):Size(50,20):Point(225+(i-1)*40,-15):Center():Color():Shadow()
	end
	
	local colorSetupFrameColorsNames_Text = {L.cd2OtherSetColorFrameText..":",L.cd2OtherSetColorFrameActive..":",L.cd2OtherSetColorFrameCooldown..":"}
	for j=1,3 do
		for i=1,3 do
			self.colorSetupFrame["color"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]] = BH.lib.CreateColorPickButton(self.colorSetupFrame,20,20,nil,240+(i-1)*40,-35-(j-1)*20)
			self.colorSetupFrame["color"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]].inOptName = "textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]
			self.colorSetupFrame["color"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]]:SetScript("OnClick",colorPickerButtonClick)
		end
		self.colorSetupFrame["text"..colorSetupFrameColorsNames[j]] = BHLib:Text(self.colorSetupFrame,colorSetupFrameColorsNames_Text[j],12):Size(210,20):Point(10,-35-(j-1)*20):Right():Color():Shadow()
	end
	
	local checksInOptNames = {"textureClassText","textureClassBackground","textureClassTimeLine"}
	for i=1,3 do
		self.colorSetupFrame["colorClass"..colorSetupFrameColorsObjectsNames[i]] = BHLib:Check(self.colorSetupFrame,"","",0):Point(241+(i-1)*40,-117):Size(18,18):OnClick(colorPickerCheckBoxClick)	
		self.colorSetupFrame["colorClass"..colorSetupFrameColorsObjectsNames[i]].inOptName = checksInOptNames[i]
	end
	self.colorSetupFrame["textClass"] = BHLib:Text(self.colorSetupFrame,L.cd2OtherSetColorFrameClass..":",12):Size(210,20):Point(10,-115):Right():Color():Shadow()
	
	self.colorSetupFrame.backAlpha:SetScript("OnValueChanged",colorPickerSliderValue)
	self.colorSetupFrame.backCDAlpha:SetScript("OnValueChanged",colorPickerSliderValue)
	self.colorSetupFrame.backCooldownAlpha:SetScript("OnValueChanged",colorPickerSliderValue)
	
	self.colorSetupFrame.resetButton = BHLib:Button(self.colorSetupFrame,L.cd2OtherSetColorFrameReset):Size(160,20):Point("TOP",-81,-265)
	self.colorSetupFrame.softenButton = BHLib:Button(self.colorSetupFrame,L.cd2OtherSetColorFrameSoften):Size(160,20):Point("TOP",81,-265)
	
	self.colorSetupFrame.softenButton:SetScript("OnClick",function()
		local tmpColors = {"R","G","B"}
		for j=1,3 do
			for i=1,3 do
				local maxColor = 0
				for n=1,3 do
					local color = VBH.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] or module.db.bhcolsDefaults["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]]
					maxColor = max(maxColor,color)
				end
				for n=1,3 do
					local color = VBH.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] or module.db.bhcolsDefaults["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]]
					if color < maxColor then
						VBH.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] = color + (maxColor - color) / 2
					end
				end
			end
		end
		module.options.showColorFrame(module.options.colorSetupFrame)
		module:ReloadAllSplits()
	end)
	
	self.colorSetupFrame.resetButton:SetScript("OnClick",function()
		local tmpColors = {"R","G","B"}
		for j=1,4 do
			for i=1,3 do
				for n=1,3 do
					VBH.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] = nil
				end
			end
		end
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textureAlphaBackground = nil
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textureAlphaTimeLine = nil
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textureAlphaCooldown = nil
		for i=1,3 do
			VBH.ExCD2.colSet[module.options.optColTabs.selected][ checksInOptNames[i] ] = nil
		end
		module.options.showColorFrame(module.options.colorSetupFrame)
		module:ReloadAllSplits()
	end)
	
	function self:showColorFrame()
		for j=1,3 do
			for i=1,3 do
				local this = module.options.colorSetupFrame["color"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]]
				this.color:SetColorTexture(VBH.ExCD2.colSet[module.options.optColTabs.selected][this.inOptName.."R"] or module.db.bhcolsDefaults[this.inOptName.."R"],VBH.ExCD2.colSet[module.options.optColTabs.selected][this.inOptName.."G"] or module.db.bhcolsDefaults[this.inOptName.."G"],VBH.ExCD2.colSet[module.options.optColTabs.selected][this.inOptName.."B"] or module.db.bhcolsDefaults[this.inOptName.."B"],1)
			end
		end
		for i=1,3 do
			module.options.colorSetupFrame["colorClass"..colorSetupFrameColorsObjectsNames[i]]:SetChecked( VBH.ExCD2.colSet[module.options.optColTabs.selected][ checksInOptNames[i] ] )
		end

		self.backAlpha:SetValue((VBH.ExCD2.colSet[module.options.optColTabs.selected][self.backAlpha.inOptName] or module.db.bhcolsDefaults[self.backAlpha.inOptName])*100)
		self.backCDAlpha:SetValue((VBH.ExCD2.colSet[module.options.optColTabs.selected][self.backCDAlpha.inOptName] or module.db.bhcolsDefaults[self.backCDAlpha.inOptName])*100)
		self.backCooldownAlpha:SetValue((VBH.ExCD2.colSet[module.options.optColTabs.selected][self.backCooldownAlpha.inOptName] or module.db.bhcolsDefaults[self.backCooldownAlpha.inOptName])*100)
	end

	self.colorSetupFrame:SetScript("OnShow",self.showColorFrame)

	
	self.optColSet.chkGeneralColorize = BHLib:Check(self.optColSet.superTabFrame.tab[3],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textureGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralColorize:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].textureGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.dropDownTexture,module.options.optColSet.chkAnimation,module.options.colorSetupFrame,module.options.optColSet.colorPickerBorder,module.options.optColSet.sliderBorderSize,module.options.optColSet.chkHideSpark)
	end	

	--> Font Options
	self.optColSet.nowFont = "font"
	
	self.optColSet.superTabFrame.tab[4].decorationLine = CreateFrame("Frame",nil,self.optColSet.superTabFrame.tab[4])
	self.optColSet.superTabFrame.tab[4].decorationLine.texture = self.optColSet.superTabFrame.tab[4].decorationLine:CreateTexture(nil, "BACKGROUND")
	self.optColSet.superTabFrame.tab[4].decorationLine:SetPoint("TOPLEFT",self.optColSet.superTabFrame.tab[4],0,-35)
	self.optColSet.superTabFrame.tab[4].decorationLine:SetPoint("BOTTOMRIGHT",self.optColSet.superTabFrame.tab[4],"TOPRIGHT",0,-55)
	self.optColSet.superTabFrame.tab[4].decorationLine.texture:SetAllPoints()
	self.optColSet.superTabFrame.tab[4].decorationLine.texture:SetColorTexture(1,1,1,1)
	self.optColSet.superTabFrame.tab[4].decorationLine.texture:SetGradientAlpha("VERTICAL",.24,.25,.30,1,.27,.28,.33,1)
	
	self.optColSet.fontsTab = BHLib:Tabs(self.optColSet.superTabFrame.tab[4],0,L.cd2ColSetFontPosGeneral,L.cd2ColSetFontPosRight,L.cd2ColSetFontPosCenter,L.cd2ColSetFontPosIcon):Size(455,160):Point(0,-55)
	self.optColSet.fontsTab:SetBackdropBorderColor(0,0,0,0)
	self.optColSet.fontsTab:SetBackdropColor(0,0,0,0)
	local function fontsTabButtonClick(self)
		local tabFrame = self.mainFrame
		tabFrame.selected = self.id
		tabFrame.UpdateTabs(tabFrame)
		
		module.options.optColSet.nowFont = self.fontMark
		
		local i = module.options.optColTabs.selected
		do
			local FontNameForDropDown = select(3,string.find(VBH.ExCD2.colSet[i][self.fontMark.."Name"] or module.db.bhcolsDefaults.fontName,"\\([^\\]*)$"))
			module.options.optColSet.dropDownFont:SetText(  (FontNameForDropDown or VBH.ExCD2.colSet[i][self.fontMark.."Name"] or module.db.bhcolsDefaults.fontName or "?") )
		end
		module.options.optColSet.sliderFont:SetValue(VBH.ExCD2.colSet[i][self.fontMark.."Size"] or module.db.bhcolsDefaults.fontSize)
		module.options.optColSet.chkFontOutline:SetChecked(VBH.ExCD2.colSet[i][self.fontMark.."Outline"])
		module.options.optColSet.chkFontShadow:SetChecked(VBH.ExCD2.colSet[i][self.fontMark.."Shadow"])
	end
	for i=1,4 do
		self.optColSet.fontsTab.tabs[i].button:SetScript("OnClick",fontsTabButtonClick)
	end
	local fontOtherAvailableTable = {"Left","Right","Center","Icon"}
	function self.fontOtherAvailable(isAvailable)
		if isAvailable then
			for i=2,4 do
				self.optColSet.fontsTab.tabs[i].button:Show()
			end
			self.optColSet.fontsTab.tabs[1].button:SetText(L.cd2ColSetFontPosLeft)
			for i=1,4 do
				self.optColSet.fontsTab.tabs[i].button.fontMark = "font"..fontOtherAvailableTable[i]
			end
		else
			for i=2,4 do
				self.optColSet.fontsTab.tabs[i].button:Hide()
			end
			self.optColSet.fontsTab.tabs[1].button:SetText(L.cd2ColSetFontPosGeneral)
			self.optColSet.fontsTab.tabs[1].button.fontMark = "font"
		end
		self.optColSet.fontsTab.resizeFunc(self.optColSet.fontsTab.tabs[1].button, 0, nil, nil, self.optColSet.fontsTab.tabs[1].button:GetFontString():GetStringWidth(), self.optColSet.fontsTab.tabs[1].button:GetFontString():GetStringWidth())
		fontsTabButtonClick(module.options.optColSet.fontsTab.tabs[1].button)
	end
	
	self.optColSet.chkFontOtherAvailable = BHLib:Check(self.optColSet.superTabFrame.tab[4],L.cd2ColSetFontOtherAvailable,"",0):Point(10,-220):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].fontOtherAvailable = true --fontOtherAvailable
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].fontOtherAvailable = nil
		end
		module:ReloadAllSplits()
		module.options.fontOtherAvailable( self:GetChecked() )
	end)

	self.optColSet.sliderFont = BHLib:Slider(self.optColSet.fontsTab,L.cd2OtherSetFontSize,false,0):Size(300,20):Point("TOP",0,-60):Range(8,72):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Size"] = event --fontSize
		module:ReloadAllSplits()
		self.tooltipText = event
		self:tooltipReload(self)
	end)

	self.optColSet.textDDFont = BHLib:Text(self.optColSet.fontsTab,L.cd2OtherSetFont..":"):Size(200,20):Point(10,-15)

	local function dropDownFontButtonClick(self,arg1,arg2)
		BHLib:DropDownClose()
		VBH.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Name"] = arg1 --fontName
		module:ReloadAllSplits()
		local FontNameForDropDown = select(3,string.find(arg1,"\\([^\\]*)$"))
		if arg2 <= #BH.F.fontList then
			module.options.optColSet.dropDownFont:SetText(FontNameForDropDown or BH.F.fontList[arg2])
		else
			module.options.optColSet.dropDownFont:SetText(FontNameForDropDown or arg2)
		end
	end
	
	self.optColSet.dropDownFont = BHLib:DropDown(self.optColSet.fontsTab,350,10):Size(200):Point(180,-15)
	for i=1,#BH.F.fontList do
		self.optColSet.dropDownFont.List[i] = {}
		local info = self.optColSet.dropDownFont.List[i]
		info.text = BH.F.fontList[i]
		info.arg1 = BH.F.fontList[i]
		info.arg2 = i
		info.func = dropDownFontButtonClick
		info.font = BH.F.fontList[i]
		info.justifyH = "CENTER" 
	end
	if LibStub then
		local loaded,media = pcall(LibStub,"LibSharedMedia-3.0")
		if loaded and media then
			local fontList = media:HashTable("font")
			if fontList then
				local count = #self.optColSet.dropDownFont.List
				for key,font in pairs(fontList) do
					count = count + 1
					self.optColSet.dropDownFont.List[count] = {}
					local info = self.optColSet.dropDownFont.List[count]
					
					info.text = font
					info.arg1 = font
					info.arg2 = count
					info.func = dropDownFontButtonClick
					info.font = font
					info.justifyH = "CENTER" 
				end
			end
		end
	end
	
	self.optColSet.chkFontOutline = BHLib:Check(self.optColSet.fontsTab,L.cd2OtherSetOutline,"",0):Point(10,-95):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Outline"] = true --fontOutline
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Outline"] = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkFontShadow = BHLib:Check(self.optColSet.fontsTab,L.cd2OtherSetFontShadow,"",0):Point(10,-120):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Shadow"] = true -- fontShadow
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Shadow"] = nil
		end
		module:ReloadAllSplits()
	end)

	self.optColSet.chkGeneralFont = BHLib:Check(self.optColSet.superTabFrame.tab[4],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].fontGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].fontGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)	
	function self.optColSet.chkGeneralFont:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].fontGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.dropDownFont,module.options.optColSet.sliderFont,module.options.optColSet.chkFontOutline,module.options.optColSet.chkFontShadow)
	end
	
	--> Text options
	
	self.optColSet.textLeftTemText = BHLib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextLeft..":"):Size(200,20):Point(10,-40)
	self.optColSet.textLeftTemEdit = BHLib:Edit(self.optColSet.superTabFrame.tab[5]):Size(220,20):Point(180,-40):OnChange(function(self,isUser)
		if isUser then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textTemplateLeft = self:GetText()
			module:ReloadAllSplits()
		end
	end)
	
	self.optColSet.textRightTemText = BHLib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextRight..":"):Size(200,20):Point(10,-65)
	self.optColSet.textRightTemEdit = BHLib:Edit(self.optColSet.superTabFrame.tab[5]):Size(220,20):Point(180,-65):OnChange(function(self,isUser)
		if isUser then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textTemplateRight = self:GetText()
			module:ReloadAllSplits()
		end
	end)
	
	self.optColSet.textCenterTemText = BHLib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextCenter..":"):Size(200,20):Point(10,-90)
	self.optColSet.textCenterTemEdit = BHLib:Edit(self.optColSet.superTabFrame.tab[5]):Size(220,20):Point(180,-90):OnChange(function(self,isUser)
		if isUser then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textTemplateCenter = self:GetText()
			module:ReloadAllSplits()
		end
	end)
	
	self.optColSet.textAllTemplates = BHLib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextTooltip,11):Size(450,200):Point(10,-115):Top():Color()

	self.optColSet.textResetButton = BHLib:Button(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextReset):Size(340,20):Point("TOP",0,-225):OnClick(function(self)
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textTemplateLeft = nil
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textTemplateRight = nil
		VBH.ExCD2.colSet[module.options.optColTabs.selected].textTemplateCenter = nil
		module:ReloadAllSplits()
		module.options.optColSet.textLeftTemEdit:SetText(module.db.bhcolsDefaults.textTemplateLeft)
		module.options.optColSet.textRightTemEdit:SetText(module.db.bhcolsDefaults.textTemplateRight)
		module.options.optColSet.textCenterTemEdit:SetText(module.db.bhcolsDefaults.textTemplateCenter)
	end)
	
	self.optColSet.chkIconName = BHLib:Check(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextIconName,"",0):Point(10,-250):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textIconName = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textIconName = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneralText = BHLib:Check(self.optColSet.superTabFrame.tab[5],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].textGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralText:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].textGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.textLeftTemEdit,module.options.optColSet.textRightTemEdit,module.options.optColSet.textCenterTemEdit,module.options.optColSet.chkIconName,module.options.optColSet.textAllTemplates,module.options.optColSet.textLeftTemText,module.options.optColSet.textRightTemText,module.options.optColSet.textCenterTemText,module.options.optColSet.textResetButton)
	end

	--> Method options
	
	self.optColSet.chkShowOnlyOnCD = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetOnlyOnCD,"",0):Point(10,-30):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsShownOnCD = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsShownOnCD = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkBotToTop = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetBotToTop,"",0):Point(10,-55):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].frameAnchorBottom = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].frameAnchorBottom = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.textStyleAnimation = BHLib:Text(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetStyleAnimation..":",11):Size(200,20):Point(10,-80)
	self.optColSet.dropDownStyleAnimation = BHLib:DropDown(self.optColSet.superTabFrame.tab[6],205,2):Size(220):Point(180,-80)
	self.optColSet.dropDownStyleAnimation.Styles = {L.cd2OtherSetStyleAnimation1,L.cd2OtherSetStyleAnimation2}
	for i=1,#self.optColSet.dropDownStyleAnimation.Styles do
		self.optColSet.dropDownStyleAnimation.List[i] = {
			text = self.optColSet.dropDownStyleAnimation.Styles[i],
			arg1 = i,
			func = function (self,arg)
				BHLib:DropDownClose()
				VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsStyleAnimation = arg
				module:ReloadAllSplits()
				self:GetParent().parent:SetText(module.options.optColSet.dropDownStyleAnimation.Styles[arg])
			end
		}
	end

	self.optColSet.textTimeLineAnimation = BHLib:Text(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetTimeLineAnimation..":",11):Size(200,20):Point(10,-105)
	self.optColSet.dropDownTimeLineAnimation = BHLib:DropDown(self.optColSet.superTabFrame.tab[6],205,2):Size(220):Point(180,-105)
	self.optColSet.dropDownTimeLineAnimation.Styles = {L.cd2OtherSetTimeLineAnimation1,L.cd2OtherSetTimeLineAnimation2}
	for i=1,#self.optColSet.dropDownTimeLineAnimation.Styles do
		self.optColSet.dropDownTimeLineAnimation.List[i] = {
			text = self.optColSet.dropDownTimeLineAnimation.Styles[i],
			arg1 = i,
			func = function (self,arg)
				BHLib:DropDownClose()
				VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsTimeLineAnimation = arg
				module:ReloadAllSplits()
				self:GetParent().parent:SetText(module.options.optColSet.dropDownTimeLineAnimation.Styles[arg])
			end
		}
	end
	
	self.optColSet.chkIconTooltip = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetIconToolip,"",0):Point(10,-130):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsIconTooltip = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsIconTooltip = nil
		end
		module:ReloadAllSplits()
	end)
		
	self.optColSet.chkLineClick = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetLineClick,"",0):Point(10,-155):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsLineClick = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsLineClick = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkLineClickWhisper = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetLineClickWhisper,"",0):Point(10,-180):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsLineClickWhisper = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsLineClickWhisper = nil
		end
		module:ReloadAllSplits()
	end)	
	
	self.optColSet.chkNewSpellNewLine = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2NewSpellNewLine,"",0):Point(10,-205):Tooltip(L.cd2NewSpellNewLineTooltip):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsNewSpellNewLine = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsNewSpellNewLine = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.textSortingRules= BHLib:Text(self.optColSet.superTabFrame.tab[6],L.cd2MethodsSortingRules..":",11):Size(200,20):Point(10,-230)
	self.optColSet.dropDownSortingRules = BHLib:DropDown(self.optColSet.superTabFrame.tab[6],405,6):Size(220):Point(180,-230)
	self.optColSet.dropDownSortingRules.Rules = {L.cd2MethodsSortingRules1,L.cd2MethodsSortingRules2,L.cd2MethodsSortingRules3,L.cd2MethodsSortingRules4,L.cd2MethodsSortingRules5,L.cd2MethodsSortingRules6}
	for i=1,#self.optColSet.dropDownSortingRules.Rules do
		self.optColSet.dropDownSortingRules.List[i] = {
			text = self.optColSet.dropDownSortingRules.Rules[i],
			arg1 = i,
			func = function (self,arg)
				BHLib:DropDownClose()
				VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsSortingRules = arg
				module:ReloadAllSplits()
				module.main:GROUP_ROSTER_UPDATE()
				self:GetParent().parent:SetText(module.options.optColSet.dropDownSortingRules.Rules[arg])
			end
		}
	end
	
	self.optColSet.chkHideOwnSpells = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2MethodsDisableOwn,"",0):Point(10,-255):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsHideOwnSpells = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsHideOwnSpells = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkAlphaNotInRange = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2MethodsAlphaNotInRange,"",0):Point(10,-280):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsAlphaNotInRange = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsAlphaNotInRange = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderAlphaNotInRange = BHLib:Slider(self.optColSet.superTabFrame.tab[6],"",false,0):Size(140,20):Point("TOPLEFT",self.optColSet.chkAlphaNotInRange,250,-3):Range(0,100):OnChange(function(self,event) 
		event = event - event%1
		VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsAlphaNotInRangeNum = event
		module:ReloadAllSplits()
		self.tooltipText = event
		self:tooltipReload(self)
	end)
	
	self.optColSet.chkDisableActive = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetDisableActive,"",0):Point(10,-305):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsDisableActive = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsDisableActive = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkOneSpellPerCol = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetOneSpellPerCol,"",0):Point(10,-330):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsOneSpellPerCol = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsOneSpellPerCol = nil
		end
		module:ReloadAllSplits()
	end):Tooltip(L.cd2ColSetOneSpellPerColTooltip)
	
	self.optColSet.chkGeneralMethods = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralMethods:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.chkShowOnlyOnCD,module.options.optColSet.chkBotToTop,module.options.optColSet.dropDownStyleAnimation,module.options.optColSet.dropDownTimeLineAnimation,module.options.optColSet.chkIconTooltip,module.options.optColSet.chkLineClick,module.options.optColSet.chkNewSpellNewLine,module.options.optColSet.dropDownSortingRules,module.options.optColSet.textSortingRules,module.options.optColSet.textStyleAnimation,module.options.optColSet.textTimeLineAnimation,module.options.optColSet.chkHideOwnSpells,module.options.optColSet.chkAlphaNotInRange,module.options.optColSet.sliderAlphaNotInRange,module.options.optColSet.chkDisableActive,module.options.optColSet.chkOneSpellPerCol,module.options.optColSet.chkLineClickWhisper)
	end
	
	self.optColSet.chkSortByAvailability = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2SortByAvailability,VBH.ExCD2.SortByAvailability,0):Point(10,-355):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.SortByAvailability = true
		else
			VBH.ExCD2.SortByAvailability = nil
			module.main:GROUP_ROSTER_UPDATE()
		end
	end)
	
	self.optColSet.chkSortByAvailability_activeToTop = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2SortByAvailabilityActiveToTop,VBH.ExCD2.SortByAvailabilityActiveToTop,0):Point("TOPLEFT",self.optColSet.chkSortByAvailability,0,-25):Tooltip(L.cd2SortByAvailabilityActiveToTopTooltip):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.SortByAvailabilityActiveToTop = true
		else
			VBH.ExCD2.SortByAvailabilityActiveToTop = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkReverseSorting = BHLib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ReverseSorting,VBH.ExCD2.ReverseSorting,0):Point("TOPLEFT",self.optColSet.chkSortByAvailability_activeToTop,200,0):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.ReverseSorting = true
		else
			VBH.ExCD2.ReverseSorting = nil
		end
		module:ReloadAllSplits()
	end)

	--> Visibility
	
	
	self.optColSet.chkOnlyInCombat = BHLib:Check(self.optColSet.superTabFrame.tab[7],L.TimerOnlyInCombat):Point(10,-30):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsOnlyInCombat = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].methodsOnlyInCombat = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.visibilityTextPartyType = BHLib:Text(self.optColSet.superTabFrame.tab[7],L.cd2OtherVisibilityPartyType..":",10):Point(10,-60):Color()
	
	self.optColSet.chkVisibilityPartyTypeAlways = BHLib:Radio(self.optColSet.superTabFrame.tab[7],ALWAYS):Point(10,-75):OnClick(function(self) 
		module.options.optColSet.chkVisibilityPartyTypeAlways:SetChecked(true)
		module.options.optColSet.chkVisibilityPartyTypeParty:SetChecked(false)
		module.options.optColSet.chkVisibilityPartyTypeRaid:SetChecked(false)
		VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityPartyType = nil
		module:ReloadAllSplits()
	end)
	self.optColSet.chkVisibilityPartyTypeParty = BHLib:Radio(self.optColSet.superTabFrame.tab[7],AGGRO_WARNING_IN_PARTY):Point(10,-95):OnClick(function(self) 
		module.options.optColSet.chkVisibilityPartyTypeAlways:SetChecked(false)
		module.options.optColSet.chkVisibilityPartyTypeParty:SetChecked(true)
		module.options.optColSet.chkVisibilityPartyTypeRaid:SetChecked(false)
		VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityPartyType = 1
		module:ReloadAllSplits()
	end)
	self.optColSet.chkVisibilityPartyTypeRaid = BHLib:Radio(self.optColSet.superTabFrame.tab[7],L.cd2OtherVisibilityPartyTypeRaid):Point(10,-115):OnClick(function(self) 
		module.options.optColSet.chkVisibilityPartyTypeAlways:SetChecked(false)
		module.options.optColSet.chkVisibilityPartyTypeParty:SetChecked(false)
		module.options.optColSet.chkVisibilityPartyTypeRaid:SetChecked(true)
		VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityPartyType = 2
		module:ReloadAllSplits()
	end)
	
	self.optColSet.visibilityTextZoneType = BHLib:Text(self.optColSet.superTabFrame.tab[7],L.cd2OtherVisibilityZoneType..":",10):Point(10,-140):Color()
	
	self.optColSet.chkVisibilityZoneArena = BHLib:Check(self.optColSet.superTabFrame.tab[7],ARENA,"",0):Point(10,-155):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableArena = nil
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableArena = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneBG = BHLib:Check(self.optColSet.superTabFrame.tab[7],BATTLEGROUND,"",0):Point(10,-180):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableBG = nil
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableBG = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneScenario = BHLib:Check(self.optColSet.superTabFrame.tab[7],TRACKER_HEADER_SCENARIO,"",0):Point(10,-205):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable3ppl = nil
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable3ppl = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZone5ppl = BHLib:Check(self.optColSet.superTabFrame.tab[7],CALENDAR_TYPE_DUNGEON,"",0):Point(10,-230):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable5ppl = nil
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable5ppl = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneRaid = BHLib:Check(self.optColSet.superTabFrame.tab[7],RAID,"",0):Point(10,-255):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableRaid = nil
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableRaid = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneOutdoor = BHLib:Check(self.optColSet.superTabFrame.tab[7],WORLD,"",0):Point(10,-280):OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableWorld = nil
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableWorld = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneralVisibility = BHLib:Check(self.optColSet.superTabFrame.tab[7],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralVisibility:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].visibilityGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.chkOnlyInCombat,module.options.optColSet.visibilityTextPartyType,module.options.optColSet.chkVisibilityPartyTypeAlways,module.options.optColSet.chkVisibilityPartyTypeParty,module.options.optColSet.chkVisibilityPartyTypeRaid,module.options.optColSet.visibilityTextZoneType,module.options.optColSet.chkVisibilityZoneArena,module.options.optColSet.chkVisibilityZoneBG,module.options.optColSet.chkVisibilityZoneScenario,module.options.optColSet.chkVisibilityZone5ppl,module.options.optColSet.chkVisibilityZoneRaid,module.options.optColSet.chkVisibilityZoneOutdoor)
	end
	
	--> Black List
	
	self.optColSet.blacklistText = BHLib:Text(self.optColSet.superTabFrame.tab[8],L.cd2ColSetBlacklistTooltip,12):Size(350,80):Point(30,-20):Top():Color()
	
	self.optColSet.blacklistEditBox = BHLib:MultiEdit(self.optColSet.superTabFrame.tab[8]):Size(350,120):Point("TOPLEFT",30,-80)
	do
		local scheluded = nil
		local function ScheludeFunc(self)
			scheluded = nil
			module:ReloadAllSplits()
		end
		function self.optColSet.blacklistEditBox:OnTextChanged(isUser)
			if not isUser then
				return
			end
			VBH.ExCD2.colSet[module.options.optColTabs.selected].blacklistText = strtrim( self:GetText() )
			if not scheluded then
				scheluded = BH.F.ScheduleTimer(ScheludeFunc, 1)
			end
		end
	end

	self.optColSet.whitelistText = BHLib:Text(self.optColSet.superTabFrame.tab[8],L.cd2ColSetWhitelistTooltip,12):Size(350,80):Point(30,-220):Top():Color()
	
	self.optColSet.whitelistEditBox = BHLib:MultiEdit(self.optColSet.superTabFrame.tab[8]):Size(350,120):Point("TOPLEFT",30,-280)
	do
		local scheluded = nil
		local function ScheludeFunc(self)
			scheluded = nil
			module:ReloadAllSplits()
		end
		function self.optColSet.whitelistEditBox:OnTextChanged(isUser)
			if not isUser then
				return
			end
			VBH.ExCD2.colSet[module.options.optColTabs.selected].whitelistText = strtrim( self:GetText() )
			if not scheluded then
				scheluded = BH.F.ScheduleTimer(ScheludeFunc, 1)
			end
		end
	end
		
	self.optColSet.chkGeneralBlackList = BHLib:Check(self.optColSet.superTabFrame.tab[8],L.cd2ColSetGeneral,"",0):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VBH.ExCD2.colSet[module.options.optColTabs.selected].blacklistGeneral = true
		else
			VBH.ExCD2.colSet[module.options.optColTabs.selected].blacklistGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralBlackList:doAlphas()
		BH.lib.SetAlphas(VBH.ExCD2.colSet[module.options.optColTabs.selected].blacklistGeneral and module.options.optColTabs.selected ~= (module.db.bhmaxColumns + 1) and 0.5 or 1,module.options.optColSet.blacklistEditBox,module.options.optColSet.whitelistEditBox,module.options.optColSet.whitelistText,module.options.optColSet.blacklistText)
	end
	
	--> Templates Tab
	self.optColSet.templates = {}
	self.optColSet.templateData = {
		spells = {31821,62618,97462,20484,98008},
		spellsCD = {90,0,0,20,0},
		spellsDuration = {0,10,0,0,0},
		spellsDead = {nil,nil,true,nil,nil},
		spellsCharge = {nil,nil,nil,true,nil},
		spellsClass = {"PALADIN","PRIEST","WARRIOR","DRUID","SHAMAN"},
		[1] = {
			iconSize = 16,
			optionAnimation = true,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 1,
			optionIconPosition = 1,
			optionGray = true,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = BH.F.barImg,
			colorsText = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsBack = {0,1,0, 0,1,0, 1,0,0, 1,1,0},
			colorsTL = {0,1,0, 0,1,0, 1,0,0, 1,1,0},
			textureAlphaBackground = 0.3,
			textureAlphaTimeLine = 0.8,
			textureAlphaCooldown = 1,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%time%",
			textTemplateCenter = "",
		},
		[2] = {
			iconSize = 14,
			optionAnimation = false,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 1,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = BH.F.barImg,
			colorsText = {1,1,1, 0.5,1,0.5, 1,0.5,0.5, 1,1,0.5,},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.3,
			textureAlphaTimeLine = 0.8,
			textureAlphaCooldown = 1,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = false,
			textTemplateLeft = "%time% %name%",
			textTemplateRight = "",
			textTemplateCenter = "",
		},
		[3] = {
			iconSize = 14,
			optionAnimation = true,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar26.tga",
			colorsText = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.15,
			textureAlphaTimeLine = 0.8,
			textureAlphaCooldown = 1,
			optionClassColorBackground = false,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "",
			textTemplateRight = "%time%",
			textTemplateCenter = "%name%: %spell%",
		},
		[4] = {
			iconSize = 16,
			optionAnimation = true,
			optionStyleAnimation = 2,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar19.tga",
			colorsText = {1,1,1, 0.5,1,0.5, 1,1,1, 1,1,0.5},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.15,
			textureAlphaTimeLine = 1,
			textureAlphaCooldown = 0.85,
			optionClassColorBackground = true,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%time%",
			textTemplateCenter = "",
			
			frameBetweenLines = 1,
		},
		[5] = {
			iconSize = 40,
			optionAnimation = false,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 1,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 10,
			fontName = BH.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = BH.F.barImg,
			colorsText = {1,1,1, 0.5,1,0.5, 1,0.5,0.5, 1,1,0.5,},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0,
			textureAlphaTimeLine = 0,
			textureAlphaCooldown = 0.7,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = false,
			textTemplateLeft = "",
			textTemplateRight = "",
			textTemplateCenter = "",
			textIconName = true,
			methodsCooldown = true,
			
			frameWidth = 40,
			frameColumns = 4,
		},
		[6] = {
			iconSize = 12,
			optionAnimation = false,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 1,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = false,
			textureFile = BH.F.barImg,
			colorsText = {1,1,1, 0.5,1,0.5, 1,0.5,0.5, 1,1,0.5,},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0,
			textureAlphaTimeLine = 0,
			textureAlphaCooldown = 1,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = false,
			textTemplateLeft = "%time% %name%",
			textTemplateRight = "",
			textTemplateCenter = "",
		},
		[7] = {
			iconSize = 14,
			optionAnimation = true,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 1,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar29.tga",
			colorsText = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsBack = {0,1,0, 0,1,0, 0.8,0,0, 1,1,0},
			colorsTL = {0,1,0, 0,1,0, 0.8,0,0, 1,1,0},
			textureAlphaBackground = 0.3,
			textureAlphaTimeLine = 0.8,
			textureAlphaCooldown = 0.5,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%stime%",
			textTemplateCenter = "",
		},
		[8] = {
			iconSize = 16,
			optionAnimation = true,
			optionStyleAnimation = 2,
			optionTimeLineAnimation = 2,
			optionIconPosition = 2,
			optionGray = true,
			fontSize = 13,
			fontName = BH.F.defFont,
			fontOutline = true,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar6.tga",
			colorsText = {1,1,1, 0.5,1,0.5, 1,0.5,0.5, 1,1,0.5,},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.3,
			textureAlphaTimeLine = 0.8,
			textureAlphaCooldown = 0.5,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = true,
			textTemplateLeft = "%name%",
			textTemplateRight = "",
			textTemplateCenter = "",
		},
		[9] = {
			iconSize = 18,
			optionAnimation = true,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar16.tga",
			colorsText = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsBack = {0,0,0, 0,0,0, 0,0,0, 0,0,0},
			colorsTL = {0.24,0.44,1, 1,0.37,1, 0.24,0.44,1, 1,0.46,0.10},
			textureAlphaBackground = 0.3,
			textureAlphaTimeLine = 0.9,
			textureAlphaCooldown = 1,
			optionClassColorBackground = false,
			optionClassColorTimeLine = false,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%stime%",
			textTemplateCenter = "",
			textureBorderSize = 1,
			frameBetweenLines = 3,
			textureBorderColorA = 1,
		},
		[10] = {
			iconSize = 18,
			optionAnimation = true,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar16.tga",
			colorsText = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsBack = {0,0,0, 0,0,0, 0,0,0, 0,0,0},
			colorsTL = {0.24,0.44,1, 1,0.37,1, 0.24,0.44,1, 1,0.46,0.10},
			textureAlphaBackground = 0.3,
			textureAlphaTimeLine = 0.9,
			textureAlphaCooldown = 1,
			optionClassColorBackground = false,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%stime%",
			textTemplateCenter = "",
			textureBorderSize = 1,
			frameBetweenLines = 3,
			textureBorderColorA = 1,
		},
		[11] = {
			_twoSized = true,
			_Scaled = .8,
			
			iconSize = 40,
			optionAnimation = true,
			optionStyleAnimation = 1,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = true,
			fontSize = 14,
			fontName = BH.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar17.tga",
			colorsText = {1,1,1, 1,1,1, 1,.6,.6, 1,1,.5},
			colorsBack = {0,0,0, 0,0,0, 0,0,0, 0,0,0},
			colorsTL = {0,0,0, 0,0,0, 0,0,0, 0,0,0},
			textureAlphaBackground = 0.8,
			textureAlphaTimeLine = 1,
			textureAlphaCooldown = .5,
			optionClassColorBackground = false,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "",
			textTemplateCenter = "",
			methodsCooldown = true,
			methodsNewSpellNewLine = true,
			frameColumns = 5,
			iconHideBlizzardEdges = true,
			
			frameLines = 60,
			
			DiffSpellData = {
				spells = 	{31821,	31821,	0,	0,	0,	97462,	0,	0,	0,	0,	20484,	20484},
				spellsCD = 	{90,	0,	0,	0,	0,	0,	0,	0,	0,	0,	20,	0},
				spellsDuration = {0,	10,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0},
				spellsDead = 	{nil,	nil,	nil,	nil,	nil,	true,	nil,	nil,	nil,	nil,	nil,	nil},
				spellsCharge = 	{nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	true,	nil},
				spellsClass = 	{"PALADIN","PALADIN",nil,nil,nil,	"WARRIOR",nil,nil,nil,nil,		"DRUID","DRUID"},			
			},
		},
		[12] = {},
		[13] = {
			iconSize = 13,
			optionAnimation = true,
			optionStyleAnimation = 2,
			optionTimeLineAnimation = 2,
			optionIconPosition = 2,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar19.tga",
			colorsText = {1,1,1, 0.5,1,0.5, 1,1,1, 1,1,0.5},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.15,
			textureAlphaTimeLine = 1,
			textureAlphaCooldown = 0.85,
			optionClassColorBackground = true,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%time%",
			textTemplateCenter = "",
			iconTitles = true,
			
			frameBetweenLines = 0,	
			
			DiffSpellData = {
				spells = 	{31821,	31821,	31821,	97462,	97462,	51052,	51052,	51052,	},
				spellsCD = 	{0,	90,	0,	0,	0,	0,	0,	20,	},
				spellsDuration ={0,	0,	10,	0,	0,	0,	0,	0,	},
				spellsDead = 	{nil,	nil,	nil,	nil,	true,	nil,	nil,	nil,	},
				spellsCharge = 	{nil,	nil,	nil,	nil,	nil,	nil,	nil,	true,	},
				spellsClass = 	{"title","PALADIN","PALADIN","title","WARRIOR","title","DEATHKNIGHT","DEATHKNIGHT"},			
			},		
		},
		[14] = {
			iconSize = 14,
			optionAnimation = true,
			optionStyleAnimation = 2,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar19.tga",
			colorsText = {1,1,1, 0.5,1,0.5, 1,1,1, 1,1,0.5},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.15,
			textureAlphaTimeLine = 1,
			textureAlphaCooldown = 0.85,
			optionClassColorBackground = true,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%time%",
			textTemplateCenter = "",
			
			frameBetweenLines = 0,
		},
		[15] = {
			_twoSized = true,
			_Scaled = .75,
			
			iconSize = 13,
			optionAnimation = true,
			optionStyleAnimation = 2,
			optionTimeLineAnimation = 2,
			optionIconPosition = 1,
			optionGray = false,
			fontSize = 12,
			fontName = BH.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\BH\\libs\\media\\bar19.tga",
			colorsText = {1,1,1, 0.5,1,0.5, 1,1,1, 1,1,0.5},
			colorsBack = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			colorsTL = {1,1,1, 1,1,1, 1,1,1, 1,1,1},
			textureAlphaBackground = 0.15,
			textureAlphaTimeLine = 1,
			textureAlphaCooldown = 0.85,
			optionClassColorBackground = true,
			optionClassColorTimeLine = true,
			optionClassColorText = false,
			textTemplateLeft = "%name%",
			textTemplateRight = "%time%",
			textTemplateCenter = "",
			iconTitles = true,
			methodsNewSpellNewLine = true,
			frameColumns = 5,
			frameLines = 60,
			frameBetweenLines = 0,	
			
			DiffSpellData = {
				spells = 	{31821,	31821,	31821,	0,	0,	97462,	97462,	0,	0,	0,	740,	740,	740,	0,	0,	51052,	51052,	51052,	0,	0,	64843,	64843,	64843,},
				spellsCD = 	{0,	90,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	20,	0,	0,	0,	0,	70,},
				spellsDuration ={0,	0,	10,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,},
				spellsDead = 	{nil,	nil,	nil,	nil,	nil,	nil,	true,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,},
				spellsCharge = 	{nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	nil,	true,	nil,	nil,	nil,	nil,	nil,},
				spellsClass = 	{"title","PALADIN","PALADIN",nil,nil,"title","WARRIOR",nil,nil,nil,"title","DRUID","DRUID",nil,nil,"title","DEATHKNIGHT","DEATHKNIGHT",nil,nil,"title","PRIEST","PRIEST"},			
			},
		},
		[16] = {},
		toOptions = {
			iconSize = "iconSize",
			optionAnimation = "textureAnimation",
			optionStyleAnimation = "methodsStyleAnimation",
			optionTimeLineAnimation = "methodsTimeLineAnimation",
			optionIconPosition = "iconPosition",
			optionGray = "iconGray",
			fontSize = "fontSize",
			fontName = "fontName",
			fontOutline = "fontOutline",
			fontShadow = "fontShadow",
			textureFile = "textureFile",
			colorsText = {"textureColorTextDefaultR","textureColorTextDefaultG","textureColorTextDefaultB","textureColorTextActiveR","textureColorTextActiveG","textureColorTextActiveB","textureColorTextCooldownR","textureColorTextCooldownG","textureColorTextCooldownB","textureColorTextCastR","textureColorTextCastG","textureColorTextCastB",},
			colorsBack = {"textureColorBackgroundDefaultR","textureColorBackgroundDefaultG","textureColorBackgroundDefaultB","textureColorBackgroundActiveR","textureColorBackgroundActiveG","textureColorBackgroundActiveB","textureColorBackgroundCooldownR","textureColorBackgroundCooldownG","textureColorBackgroundCooldownB","textureColorBackgroundCastR","textureColorBackgroundCastG","textureColorBackgroundCastB",},
			colorsTL = {"textureColorTimeLineDefaultR","textureColorTimeLineDefaultG","textureColorTimeLineDefaultB","textureColorTimeLineActiveR","textureColorTimeLineActiveG","textureColorTimeLineActiveB","textureColorTimeLineCooldownR","textureColorTimeLineCooldownG","textureColorTimeLineCooldownB","textureColorTimeLineCastR","textureColorTimeLineCastG","textureColorTimeLineCastB",},
			textureAlphaBackground = "textureAlphaBackground",
			textureAlphaTimeLine = "textureAlphaTimeLine",
			textureAlphaCooldown = "textureAlphaCooldown",
			optionClassColorBackground = "textureClassBackground",
			optionClassColorTimeLine = "textureClassTimeLine",
			optionClassColorText = "textureClassText",	
			textTemplateLeft = "textTemplateLeft",
			textTemplateRight = "textTemplateRight",
			textTemplateCenter = "textTemplateCenter",
			methodsCooldown = "methodsCooldown",
			textIconName = "textIconName",
			fontOtherAvailable = "fontOtherAvailable",
			frameBetweenLines = "frameBetweenLines",
			textureBorderSize = "textureBorderSize",
			textureBorderColorR = "textureBorderColorR",
			textureBorderColorG = "textureBorderColorG",
			textureBorderColorB = "textureBorderColorB",
			textureBorderColorA = "textureBorderColorA",
			methodsNewSpellNewLine = "methodsNewSpellNewLine",
			methodsSortingRules = "methodsSortingRules",
			iconTitles = "iconTitles",
			iconHideBlizzardEdges = "iconHideBlizzardEdges",
			
			iconGeneral = "iconGeneral",
			textureGeneral = "textureGeneral",
			methodsGeneral = "methodsGeneral",
			fontGeneral = "fontGeneral",
			textGeneral = "textGeneral",
			frameGeneral = "frameGeneral",

			frameColumns = "frameColumns",
			
			_frameAlpha = "frameAlpha",
			_frameWidth = "frameWidth",
			_frameBlackBack = "frameBlackBack",
			_frameLines = "frameLines",
		},
	}
	self.optColSet.templateSaveData = nil
	
	self.optColSet.templatesScrollFrame = BHLib:ScrollFrame(self.optColSet.superTabFrame.tab[9]):Size(419,423):Point("TOPLEFT",6,-5):Height( ceil(#self.optColSet.templateData/2) * 125 + 10 )
	for i=1,#self.optColSet.templateData do if i==1 or not self.optColSet.templateData[i-1]._twoSized then
		local templateFrame = CreateFrame("Button",nil,self.optColSet.templatesScrollFrame.C)
		self.optColSet.templates[i] = templateFrame
		templateFrame:SetPoint(self.optColSet.templateData[i]._twoSized and "TOP" or (i-1)%2 == 0 and "TOPRIGHT" or "TOPLEFT",self.optColSet.templatesScrollFrame.C,"TOP",0,-floor((i-1)/2) * 125 - 5)
		templateFrame:SetSize(185,120)
		if self.optColSet.templateData[i]._twoSized then
			templateFrame:SetSize(370,120)
		end
		templateFrame:SetBackdrop({edgeFile = BH.F.defBorder, edgeSize = 8})
		templateFrame:SetBackdropBorderColor(1,1,1,0)
		templateFrame.backgTexture = templateFrame:CreateTexture(nil, "BACKGROUND")
		templateFrame.backgTexture:SetAllPoints()
		
		templateFrame:SetScript("OnEnter",function (self)
			self:SetBackdropBorderColor(1,1,1,0.5)
			self.backgTexture:SetColorTexture(1,1,1,0.3)
		end)
		
		templateFrame:SetScript("OnLeave",function (self)
		  	self:SetBackdropBorderColor(1,1,1,0)
			self.backgTexture:SetColorTexture(0,0,0,0)
		end)
		
		templateFrame:SetScript("OnClick",function (self)
		  	module.options.optColSet.templateRestore:Show()
		  	module.options.optColSet.templateSaveData = {}
		  	BH.F.table_copy(VBH.ExCD2.colSet[module.options.optColTabs.selected],module.options.optColSet.templateSaveData)
		  	for key,val in pairs(module.options.optColSet.templateData.toOptions) do
		  		if type(val) ~= "table" then
		  			if string.find(key,"^_") then
		  				local key2 = string.sub(key,2)
		  				if module.options.optColSet.templateData[i][key2] then
		  					VBH.ExCD2.colSet[module.options.optColTabs.selected][val] = module.options.optColSet.templateData[i][key2]
		  				elseif key2 == "frameWidth" then
		  					VBH.ExCD2.colSet[module.options.optColTabs.selected][val] = max(110,VBH.ExCD2.colSet[module.options.optColTabs.selected][val] or 110)
		  				end
		  			elseif val:find("General") then
		  				VBH.ExCD2.colSet[module.options.optColTabs.selected][val] = nil
		  			else
		  				VBH.ExCD2.colSet[module.options.optColTabs.selected][val] = module.options.optColSet.templateData[i][key]
		  			end
		  		else
		  			for k=1,#val do
		  				VBH.ExCD2.colSet[module.options.optColTabs.selected][val[k]] = module.options.optColSet.templateData[i][key][k]
		  			end
		  		end
		  	end
		  	module:ReloadAllSplits()
		  	module.options.selectColumnTab()
		end)
		
		local width,height = self.optColSet.templateData[i].frameWidth or 160, self.optColSet.templateData[i].iconSize
		local betweenLines = self.optColSet.templateData[i].frameBetweenLines or 0
		
		templateFrame.barWidth = width
		templateFrame.iconSize = height
		
		templateFrame.fontName = self.optColSet.templateData[i].fontName
		templateFrame.fontSize = self.optColSet.templateData[i].fontSize
		templateFrame.fontOutline = self.optColSet.templateData[i].fontOutline
		templateFrame.fontShadow = self.optColSet.templateData[i].fontShadow
		for _,pos in pairs({"Left","Right","Center","Icon"}) do
			templateFrame["font"..pos.."Name"] = self.optColSet.templateData[i]["font"..pos.."Name"] or templateFrame.fontName
			templateFrame["font"..pos.."Size"] = self.optColSet.templateData[i]["font"..pos.."Size"] or templateFrame.fontSize
			templateFrame["font"..pos.."Outline"] = self.optColSet.templateData[i]["font"..pos.."Outline"] or templateFrame.fontOutline
			templateFrame["font"..pos.."Shadow"] = self.optColSet.templateData[i]["font"..pos.."Shadow"] or templateFrame.fontShadow
		end
	
		templateFrame.textTemplateLeft = self.optColSet.templateData[i].textTemplateLeft
		templateFrame.textTemplateRight = self.optColSet.templateData[i].textTemplateRight
		templateFrame.textTemplateCenter = self.optColSet.templateData[i].textTemplateCenter
		templateFrame.optionIconName = self.optColSet.templateData[i].textIconName
		templateFrame.optionCooldown = self.optColSet.templateData[i].methodsCooldown
		templateFrame.optionIconPosition = self.optColSet.templateData[i].optionIconPosition
		templateFrame.optionAnimation = self.optColSet.templateData[i].optionAnimation
		templateFrame.optionGray = self.optColSet.templateData[i].optionGray
		
		templateFrame.textureFile = self.optColSet.templateData[i].textureFile
		templateFrame.optionAlphaBackground = self.optColSet.templateData[i].textureAlphaBackground
		templateFrame.optionAlphaTimeLine = self.optColSet.templateData[i].textureAlphaTimeLine
		templateFrame.optionAlphaCooldown = self.optColSet.templateData[i].textureAlphaCooldown
		
		templateFrame.optionTimeLineAnimation = self.optColSet.templateData[i].optionTimeLineAnimation
		templateFrame.optionStyleAnimation = self.optColSet.templateData[i].optionStyleAnimation
		
		templateFrame.optionClassColorBackground = self.optColSet.templateData[i].optionClassColorBackground
		templateFrame.optionClassColorTimeLine = self.optColSet.templateData[i].optionClassColorTimeLine
		templateFrame.optionClassColorText = self.optColSet.templateData[i].optionClassColorText

		templateFrame.optionIconHideBlizzardEdges = self.optColSet.templateData[i].iconHideBlizzardEdges
		
		templateFrame.textureBorderColorR = self.optColSet.templateData[i].textureBorderColorR or 0
		templateFrame.textureBorderColorG = self.optColSet.templateData[i].textureBorderColorG or 0
		templateFrame.textureBorderColorB = self.optColSet.templateData[i].textureBorderColorB or 0
		templateFrame.textureBorderColorA = self.optColSet.templateData[i].textureBorderColorA or 0
		
		templateFrame.optionIconTitles = self.optColSet.templateData[i].iconTitles
		
		local templateDataColorsTablesNames = {"colorsText","colorsBack","colorsTL"}
		for object_c=1,3 do
			for state_c=1,3 do
				templateFrame["optionColor".. colorSetupFrameColorsObjectsNames[object_c] .. colorSetupFrameColorsNames[state_c] ] = {
					r = self.optColSet.templateData[i][ templateDataColorsTablesNames[object_c] ][ (state_c-1)*3+1 ],
					g = self.optColSet.templateData[i][ templateDataColorsTablesNames[object_c] ][ (state_c-1)*3+2 ],
					b = self.optColSet.templateData[i][ templateDataColorsTablesNames[object_c] ][ (state_c-1)*3+3 ],
				}
			end
		end
		
		templateFrame.textureBorderSize = self.optColSet.templateData[i].textureBorderSize or 0
		
		templateFrame.optionSmoothAnimationDuration = module.db.bhcolsDefaults.textureSmoothAnimationDuration
		
		local DiffSpellData = self.optColSet.templateData[i].DiffSpellData
		
		local classColorsTable = type(CUSTOM_CLASS_COLORS)=="table" and CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
		
		templateFrame.lines = {}
		for j=1,DiffSpellData and #DiffSpellData.spells or 5 do if not DiffSpellData or DiffSpellData.spells[j] ~= 0 then
			local bar = CreateBar(templateFrame)
			templateFrame.lines[j] = bar
	
			if not self.optColSet.templateData[i].frameColumns then
				bar:SetPoint("TOP",0,-height*(j-1)-10 -betweenLines*(j-1))
			else
				local inLine = (j-1) % self.optColSet.templateData[i].frameColumns
				local line = floor((((j-1) - inLine) / self.optColSet.templateData[i].frameColumns ) +0.5)
				if self.optColSet.templateData[i]._twoSized then
					bar:SetPoint("TOPLEFT", inLine*width + 10, -line*height -10 -betweenLines*line) 
				else
					local pos = inLine * width
					local totalWidth = self.optColSet.templateData[i].frameColumns * width
					pos = pos - totalWidth / 2
					bar:SetPoint("TOPLEFT", templateFrame,"TOP",pos, -line*height -10 -betweenLines*line) 	
				end
			end
			
			if self.optColSet.templateData[i]._Scaled then
				bar:SetScale(self.optColSet.templateData[i]._Scaled)
			end
			
			local spellID = DiffSpellData and DiffSpellData.spells[j] or self.optColSet.templateData.spells[j]
			local spellName,_,spellTexture = GetSpellInfo(spellID or 0)
			spellName = spellName or "unk"
			
			local spellClass = DiffSpellData and DiffSpellData.spellsClass[j] or self.optColSet.templateData.spellsClass[j]
		
			bar.data = {
				name = BH.SDB.charName,
				fullName = BH.SDB.charName,
				icon = spellTexture,
				spellName = i == 3 and spellName:sub(1,spellName:find(' ')) or spellName,
				db = {spellID,spellClass},
				lastUse = GetTime(),
				charge = GetTime(),
				cd = DiffSpellData and DiffSpellData.spellsCD[j] or self.optColSet.templateData.spellsCD[j],
				duration = DiffSpellData and DiffSpellData.spellsDuration[j] or self.optColSet.templateData.spellsDuration[j],
				classColor = classColorsTable[spellClass] or module.db.bhnotAClass,
				
				disabled = ((DiffSpellData and DiffSpellData.spellsDead[j]) or (not DiffSpellData and self.optColSet.templateData.spellsDead[j])) and 1,
				isCharge = DiffSpellData and DiffSpellData.spellsCharge[j] or not DiffSpellData and self.optColSet.templateData.spellsCharge[j],
				
				specialUpdateData = function(data)
					local currTime = GetTime()
					if data.isCharge then
						if (data.charge + data.cd) < currTime then
							data.charge = currTime
							data.lastUse = currTime
						end
						return
					end
					if data.cd ~= 0 then
						if (data.lastUse + data.cd) < currTime then
							data.lastUse = currTime
						end
					elseif data.duration ~= 0 then
						if (data.lastUse + data.duration) < currTime then
							data.lastUse = currTime
						end
					end
				end,
			}
			
			bar:UpdateStyle()
			bar:Update()
			bar:UpdateStatus()
			if spellClass == "title" then
				bar:CreateTitle()
			end
		end end
	end end
	
	self.optColSet.templateRestore = CreateFrame("Button",nil,self.optColSet.superTabFrame.tab[9])
	self.optColSet.templateRestore:SetPoint("TOPLEFT",-120,-200)
	self.optColSet.templateRestore:SetSize(100,30)
	self.optColSet.templateRestore:SetBackdrop({edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeSize = 8})
	self.optColSet.templateRestore:SetBackdropBorderColor(1,0.5,0.5,1)
	self.optColSet.templateRestore.text = BHLib:Text(self.optColSet.templateRestore,L.cd2OtherSetTemplateRestore,12):Point('x'):Center():Color():Shadow()
	self.optColSet.templateRestore:SetScript("OnEnter",function (self)
	  	self.text:SetTextColor(1,1,0,1)
	end)
	self.optColSet.templateRestore:SetScript("OnLeave",function (self)
	  	self.text:SetTextColor(1,1,1,1)	  
	end)
	self.optColSet.templateRestore:SetScript("OnClick",function (self)
		VBH.ExCD2.colSet[module.options.optColTabs.selected] = {}
		BH.F.table_copy(module.options.optColSet.templateSaveData,VBH.ExCD2.colSet[module.options.optColTabs.selected])
		module:ReloadAllSplits()
		module.options.selectColumnTab()
		self:Hide()
	end)
	self.optColSet.templateRestore:Hide()
	
	do
		module.options.optColTabs.selected = module.db.bhmaxColumns+1
		module.options.tab.tabs[2]:SetScript("OnShow",function ()
			module.options.selectColumnTab(self.optColTabs.tabs[module.db.bhmaxColumns+1].button)
			module.options.tab.tabs[2]:SetScript("OnShow",nil)
		end)
	end	
	
	--> Other setts
	self.optSetTab = BHLib:OneTab(self.tab.tabs[2],L.cd2OtherSet):Size(550,34):Point("TOP",10,-500)
	
	self.chkSplit = BHLib:Check(self.optSetTab,L.cd2split,VBH.ExCD2.SplitOpt,0):Point("LEFT",10,0):Tooltip(L.cd2splittooltip):OnClick(function(self,event)
		if self:GetChecked() then
			VBH.ExCD2.SplitOpt = true
		else
			VBH.ExCD2.SplitOpt = nil
		end
		module:SplitExCD2Window()
		module:ReloadAllSplits()
	end)
	
	self.chkNoRaid = BHLib:Check(self.optSetTab,L.cd2noraid,VBH.ExCD2.NoRaid,0):Point("LEFT",165,0):OnClick(function(self,event)
		if self:GetChecked() then
			VBH.ExCD2.NoRaid = true
		else
			VBH.ExCD2.NoRaid = nil
		end
		UpdateRoster()
	end)
	
	self.testMode = BHLib:Check(self.optSetTab,L.cd2GeneralSetTestMode,module.db.bhtestMode,0):Point("LEFT",325,0):Tooltip(L.cd2HelpTestButton):OnClick(function(self,event)
		if self:GetChecked() then
			module.db.bhtestMode = true
		else
			module.db.bhtestMode = nil
			TestMode(1)
		end
		UpdateRoster()
	end)

	self.butResetToDef = BHLib:Button(self.optSetTab,L.cd2OtherSetReset):Size(80,20):Point("LEFT",440,0):Tooltip(L.cd2HelpButtonDefault):OnClick(function()
		StaticPopupDialogs["BH_EXCD_DEFAULT"] = {
			text = L.cd2OtherSetReset,
			button1 = L.YesText,
			button2 = L.NoText,
			OnAccept = function()
				table_wipe2(VBH.ExCD2.colSet[module.options.optColTabs.selected])
				for optName,optVal in pairs(module.db.bhcolsInit) do
					VBH.ExCD2.colSet[module.options.optColTabs.selected][optName] = optVal
				end
				VBH.ExCD2.SortByAvailability = nil
				
				module.options.selectColumnTab(self.optColTabs.tabs[module.options.optColTabs.selected].button)
				module:ReloadAllSplits()
			end,
			timeout = 0,
			whileDead = true,
			hideOnEscape = true,
			preferredIndex = 3,
		}
		StaticPopup_Show("BH_EXCD_DEFAULT")
	end) 
	
	
end

function module.options:CleanUPVariables()
	local cleanUP = {}
	for sett,col in pairs(VBH.ExCD2.CDECol) do
		local bool = nil
		for i=1,#module.db.bhspellDB do
			for j=3,7 do
				if module.db.bhspellDB[i][j] then
					if tonumber( string.gsub(sett,";%d",""),nil ) == module.db.bhspellDB[i][j][1] then
						bool = true
					end
				end
			end
		end
		if not bool then
			cleanUP [#cleanUP + 1] = sett
		end
	end
	for i=1,#cleanUP do
		VBH.ExCD2.CDECol[cleanUP[i]] = nil
	end
	table_wipe2(cleanUP)
	for sid,val in pairs(VBH.ExCD2.CDE) do
		local bool = nil
		for i=1,#module.db.bhspellDB do
			if sid == module.db.bhspellDB[i][1] then
				bool = true
			end
		end
		if not bool then
			cleanUP [#cleanUP + 1] = sid
		end
	end
	for i=1,#cleanUP do
		VBH.ExCD2.CDE[cleanUP[i]] = nil
	end
	table_wipe2(cleanUP)
	for sid,val in pairs(VBH.ExCD2.Priority) do
		local bool = nil
		for i=1,#module.db.bhspellDB do
			if sid == module.db.bhspellDB[i][1] then
				bool = true
			end
		end
		if not bool then
			cleanUP [#cleanUP + 1] = sid
		end
	end
	for i=1,#cleanUP do
		VBH.ExCD2.Priority[cleanUP[i]] = nil
	end
end

local function CreateBlackList(text)
	local blacklist = {}
	local tmpList = {strsplit("\n", text)}
	for i=1,#tmpList do
		if tmpList[i]~="" then
			if tmpList[i]:find(":(%d+)") then
				local name,spellID = tmpList[i]:match("([^:]+):(%d+)")
				if name and spellID then
					spellID = tonumber(spellID)
					blacklist[ spellID ] = blacklist[ spellID ] or {}
					name = name:lower()
					blacklist[ spellID ][name] = true
				end
			else
				tmpList[i] = tmpList[i]:lower()
				blacklist[ tmpList[i] ] = true
			end
		end
	end
	return blacklist
end
local function CreateWhiteList(text)
	if text == "" then
		return
	end
	local whitelist = {}
	local tmpList = {strsplit("\n", text)}
	for i=1,#tmpList do
		if tmpList[i]~="" then
			tmpList[i] = tmpList[i]:lower()
			whitelist[ tmpList[i] ] = true
		end
	end
	return whitelist
end

local lastSplitsReload = 0
function module:ReloadAllSplits(argScaleFix)
	local _ctime = GetTime()
	if lastSplitsReload > _ctime then
		return
	end
	lastSplitsReload = _ctime + 0.05
	local VBH_ColumnOptions = VBH.ExCD2.colSet
	local Width = 0
	local maxHeight = 0
	local maxLine = VBH_ColumnOptions[module.db.bhmaxColumns+1].frameLines or module.db.bhcolsDefaults.frameLines
	local maxBetweenLines = 0
	if VBH_ColumnOptions[module.db.bhmaxColumns+1].frameColumns then
		maxLine = ceil(maxLine / VBH_ColumnOptions[module.db.bhmaxColumns+1].frameColumns)
	end	

	for i=1,module.db.bhmaxColumns do 
		local columnFrame = module.frame.colFrame[i]
		if not columnFrame.LOADEDs then
			columnFrame.LOADEDs = {}
		end
	
		columnFrame.iconSize = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconSize) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconSize) or module.db.bhcolsDefaults.iconSize
		if VBH_ColumnOptions[i].enabled and columnFrame.iconSize > maxHeight then
			maxHeight = columnFrame.iconSize
		end
		
		local frameBetweenLines = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameBetweenLines) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameBetweenLines) or module.db.bhcolsDefaults.frameBetweenLines

		local frameColumns = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameColumns) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameColumns) or module.db.bhcolsDefaults.frameColumns
		columnFrame.frameColumns = frameColumns
		local linesShown = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameLines) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameLines) or module.db.bhcolsDefaults.frameLines	
		linesShown = ceil(linesShown / frameColumns)
		local linesTotal = linesShown * frameColumns
		if VBH.ExCD2.SplitOpt then 
			columnFrame:SetHeight(columnFrame.iconSize*linesShown+frameBetweenLines*(linesShown-1)) 
		else
			columnFrame:SetHeight(columnFrame.iconSize*linesShown)
			if VBH_ColumnOptions[i].enabled then
				if linesShown > maxLine then
					maxLine = linesShown
				end
				local nowBetweenLines = frameBetweenLines*(linesShown-1)
				if nowBetweenLines > maxBetweenLines then
					maxBetweenLines = nowBetweenLines
				end
			end
		end
		columnFrame.NumberLastLinesActive = module.db.bhmaxLinesInCol
		
		if VBH_ColumnOptions[i].enabled then
			for j=1,linesTotal do
				if not columnFrame.LOADEDs[j] then
					columnFrame.lines[j] = CreateBar(columnFrame)
					columnFrame.lines[j]:Hide()
					columnFrame.LOADEDs[j] = true
				end
			end
			columnFrame.IsColumnEnabled = true
		else
			columnFrame.IsColumnEnabled = false
		end

		local frameAlpha = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameAlpha) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameAlpha) or module.db.bhcolsDefaults.frameAlpha
		columnFrame:SetAlpha(frameAlpha/100) 

		local frameScale = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameScale) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameScale) or module.db.bhcolsDefaults.frameScale
		if VBH.ExCD2.SplitOpt then 
			if argScaleFix == "ScaleFix" then
				BH.F.SetScaleFix(columnFrame,frameScale/100)
			else
				columnFrame:SetScale(frameScale/100) 
			end
		else
			columnFrame:SetScale(1)
		end
		
		local blackBack = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameBlackBack) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameBlackBack) or module.db.bhcolsDefaults.frameBlackBack
		columnFrame.texture:SetColorTexture(0,0,0,blackBack / 100)
		
		--> View options
		columnFrame.optionClassColorBackground = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureClassBackground) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureClassBackground)
		columnFrame.optionClassColorTimeLine = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureClassTimeLine) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureClassTimeLine)
		columnFrame.optionClassColorText = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureClassText) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureClassText)

		columnFrame.optionAnimation = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureAnimation) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureAnimation)
		columnFrame.optionSmoothAnimation = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureSmoothAnimation) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureSmoothAnimation)
		columnFrame.optionSmoothAnimationDuration = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureSmoothAnimationDuration) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureSmoothAnimationDuration) or module.db.bhcolsDefaults.textureSmoothAnimationDuration
			columnFrame.optionSmoothAnimationDuration = columnFrame.optionSmoothAnimationDuration / 100
		columnFrame.optionLinesMax = min(linesShown*frameColumns,module.db.bhmaxLinesInCol)
		columnFrame.optionShownOnCD = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsShownOnCD) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsShownOnCD)
		columnFrame.optionIconPosition = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconPosition) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconPosition) or module.db.bhcolsDefaults.iconPosition
		columnFrame.optionStyleAnimation = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsStyleAnimation) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsStyleAnimation) or module.db.bhcolsDefaults.methodsStyleAnimation
		columnFrame.optionTimeLineAnimation = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsTimeLineAnimation) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsTimeLineAnimation) or module.db.bhcolsDefaults.methodsTimeLineAnimation
		columnFrame.optionCooldown = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].methodsCooldown) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsCooldown)
		columnFrame.optionCooldownHideNumbers = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconCooldownHideNumbers) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconCooldownHideNumbers)
		columnFrame.optionCooldownShowSwipe = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconCooldownShowSwipe) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconCooldownShowSwipe)
		columnFrame.optionIconName = (not VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[i].textIconName) or (VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textIconName)
		columnFrame.optionHideSpark = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureHideSpark) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureHideSpark)
		columnFrame.optionIconTitles = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconTitles) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconTitles)
			columnFrame.optionIconTitles = columnFrame.optionIconTitles and not (columnFrame.optionIconPosition == 3)
		columnFrame.optionIconHideBlizzardEdges = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconHideBlizzardEdges) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconHideBlizzardEdges)
		
		columnFrame.methodsIconTooltip = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsIconTooltip) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsIconTooltip) 
		columnFrame.methodsLineClick = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsLineClick) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsLineClick)
		columnFrame.methodsLineClickWhisper = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsLineClickWhisper) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsLineClickWhisper)
		columnFrame.methodsNewSpellNewLine = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsNewSpellNewLine) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsNewSpellNewLine)
		columnFrame.methodsSortingRules = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsSortingRules) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsSortingRules) or module.db.bhcolsDefaults.methodsSortingRules
		columnFrame.methodsHideOwnSpells = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsHideOwnSpells) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsHideOwnSpells)
		columnFrame.methodsAlphaNotInRange = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsAlphaNotInRange) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsAlphaNotInRange)
		columnFrame.methodsAlphaNotInRangeNum = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsAlphaNotInRangeNum) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsAlphaNotInRangeNum) or module.db.bhcolsDefaults.methodsAlphaNotInRangeNum
			columnFrame.methodsAlphaNotInRangeNum = columnFrame.methodsAlphaNotInRangeNum / 100
		columnFrame.methodsDisableActive = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsDisableActive) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsDisableActive)
		columnFrame.methodsOneSpellPerCol = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].methodsOneSpellPerCol) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsOneSpellPerCol)
		
		columnFrame.methodsOnlyInCombat = (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].methodsOnlyInCombat) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].methodsOnlyInCombat)
		columnFrame.visibilityPartyType = (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityPartyType) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityPartyType)
		columnFrame.visibilityArena = not ( (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityDisableArena) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityDisableArena) )
		columnFrame.visibilityBG = not ( (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityDisableBG) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityDisableBG) )
		columnFrame.visibility3ppl = not ( (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityDisable3ppl) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityDisable3ppl) )
		columnFrame.visibility5ppl = not ( (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityDisable5ppl) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityDisable5ppl) )
		columnFrame.visibilityRaid = not ( (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityDisableRaid) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityDisableRaid) )
		columnFrame.visibilityWorld = not ( (not VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[i].visibilityDisableWorld) or (VBH_ColumnOptions[i].visibilityGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].visibilityDisableWorld) )

		columnFrame.textTemplateLeft = (not VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[i].textTemplateLeft) or (VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textTemplateLeft) or module.db.bhcolsDefaults.textTemplateLeft
		columnFrame.textTemplateRight = (not VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[i].textTemplateRight) or (VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textTemplateRight) or module.db.bhcolsDefaults.textTemplateRight
		columnFrame.textTemplateCenter = (not VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[i].textTemplateCenter) or (VBH_ColumnOptions[i].textGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textTemplateCenter) or module.db.bhcolsDefaults.textTemplateCenter
		
		local blacklistText = (not VBH_ColumnOptions[i].blacklistGeneral and VBH_ColumnOptions[i].blacklistText) or (VBH_ColumnOptions[i].blacklistGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].blacklistText) or module.db.bhcolsDefaults.blacklistText
		columnFrame.BlackList = CreateBlackList(blacklistText)
		local whitelistText = (not VBH_ColumnOptions[i].blacklistGeneral and VBH_ColumnOptions[i].whitelistText) or (VBH_ColumnOptions[i].blacklistGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].whitelistText) or module.db.bhcolsDefaults.whitelistText
		columnFrame.WhiteList = CreateWhiteList(whitelistText)
		
		local frameWidth = (not VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[i].frameWidth) or (VBH_ColumnOptions[i].frameGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameWidth) or module.db.bhcolsDefaults.frameWidth
		columnFrame:SetWidth(frameWidth*frameColumns)
		columnFrame.barWidth = frameWidth
		
		columnFrame.optionGray = (not VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[i].iconGray) or (VBH_ColumnOptions[i].iconGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].iconGray)
		columnFrame.fontSize = (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontSize) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontSize) or module.db.bhcolsDefaults.fontSize
		columnFrame.fontName = (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontName) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontName) or module.db.bhcolsDefaults.fontName
		columnFrame.fontOutline = (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontOutline) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontOutline)
		columnFrame.fontShadow = (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontShadow) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontShadow)
		columnFrame.textureFile = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureFile) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureFile) or module.db.bhcolsDefaults.textureFile
		columnFrame.textureBorderSize = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureBorderSize) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureBorderSize) or module.db.bhcolsDefaults.textureBorderSize

		columnFrame.textureBorderColorR = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureBorderColorR) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureBorderColorR) or module.db.bhcolsDefaults.textureBorderColorR
		columnFrame.textureBorderColorG = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureBorderColorG) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureBorderColorG) or module.db.bhcolsDefaults.textureBorderColorG
		columnFrame.textureBorderColorB = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureBorderColorB) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureBorderColorB) or module.db.bhcolsDefaults.textureBorderColorB
		columnFrame.textureBorderColorA = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureBorderColorA) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureBorderColorA) or module.db.bhcolsDefaults.textureBorderColorA

		local fontOtherAvailable = (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontOtherAvailable) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontOtherAvailable)

		columnFrame.fontLeftSize = (not fontOtherAvailable and columnFrame.fontSize) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontLeftSize) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontLeftSize) or module.db.bhcolsDefaults.fontSize
		columnFrame.fontLeftName = (not fontOtherAvailable and columnFrame.fontName) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontLeftName) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontLeftName) or module.db.bhcolsDefaults.fontName
		columnFrame.fontLeftOutline = (not fontOtherAvailable and columnFrame.fontOutline) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontLeftOutline) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontLeftOutline)))
		columnFrame.fontLeftShadow = (not fontOtherAvailable and columnFrame.fontShadow) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontLeftShadow) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontLeftShadow)))

		columnFrame.fontRightSize = (not fontOtherAvailable and columnFrame.fontSize) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontRightSize) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontRightSize) or module.db.bhcolsDefaults.fontSize
		columnFrame.fontRightName = (not fontOtherAvailable and columnFrame.fontName) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontRightName) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontRightName) or module.db.bhcolsDefaults.fontName
		columnFrame.fontRightOutline = (not fontOtherAvailable and columnFrame.fontOutline) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontRightOutline) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontRightOutline)))
		columnFrame.fontRightShadow = (not fontOtherAvailable and columnFrame.fontShadow) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontRightShadow) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontRightShadow)))

		columnFrame.fontCenterSize = (not fontOtherAvailable and columnFrame.fontSize) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontCenterSize) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontCenterSize) or module.db.bhcolsDefaults.fontSize
		columnFrame.fontCenterName = (not fontOtherAvailable and columnFrame.fontName) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontCenterName) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontCenterName) or module.db.bhcolsDefaults.fontName
		columnFrame.fontCenterOutline = (not fontOtherAvailable and columnFrame.fontOutline) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontCenterOutline) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontCenterOutline)))
		columnFrame.fontCenterShadow = (not fontOtherAvailable and columnFrame.fontShadow) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontCenterShadow) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontCenterShadow)))

		columnFrame.fontIconSize = (not fontOtherAvailable and columnFrame.fontSize) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontIconSize) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontIconSize) or module.db.bhcolsDefaults.fontSize
		columnFrame.fontIconName = (not fontOtherAvailable and columnFrame.fontName) or (not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontIconName) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontIconName) or module.db.bhcolsDefaults.fontName
		columnFrame.fontIconOutline = (not fontOtherAvailable and columnFrame.fontOutline) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontIconOutline) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontIconOutline)))
		columnFrame.fontIconShadow = (not fontOtherAvailable and columnFrame.fontShadow) or (fontOtherAvailable and ((not VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[i].fontIconShadow) or (VBH_ColumnOptions[i].fontGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].fontIconShadow)))

		for j=1,3 do
			for n=1,3 do
				local object = colorSetupFrameColorsObjectsNames[j]
				local state = colorSetupFrameColorsNames[n]
				if not columnFrame["optionColor"..object..state] then
					columnFrame["optionColor"..object..state] = {}
				end

				columnFrame["optionColor"..object..state].r = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i]["textureColor"..object..state.."R"]) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1]["textureColor"..object..state.."R"]) or module.db.bhcolsDefaults["textureColor"..object..state.."R"]
				columnFrame["optionColor"..object..state].g = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i]["textureColor"..object..state.."G"]) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1]["textureColor"..object..state.."G"]) or module.db.bhcolsDefaults["textureColor"..object..state.."G"]
				columnFrame["optionColor"..object..state].b = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i]["textureColor"..object..state.."B"]) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1]["textureColor"..object..state.."B"]) or module.db.bhcolsDefaults["textureColor"..object..state.."B"]
			end
		end

		columnFrame.optionAlphaBackground = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureAlphaBackground) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureAlphaBackground) or module.db.bhcolsDefaults.textureAlphaBackground
		columnFrame.optionAlphaTimeLine = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureAlphaTimeLine) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureAlphaTimeLine) or module.db.bhcolsDefaults.textureAlphaTimeLine
		columnFrame.optionAlphaCooldown = (not VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[i].textureAlphaCooldown) or (VBH_ColumnOptions[i].textureGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].textureAlphaCooldown) or module.db.bhcolsDefaults.textureAlphaCooldown

		if VBH_ColumnOptions[i].enabled then
			--for n=1,linesTotal do
			for n=1,#columnFrame.lines do
				columnFrame.lines[n]:UpdateStyle()
				if columnFrame.lines[n]:IsVisible() then
					columnFrame.lines[n]:UpdateStatus()
				end
			end
		
			local frameAnchorBottom = (not VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[i].frameAnchorBottom) or (VBH_ColumnOptions[i].methodsGeneral and VBH_ColumnOptions[module.db.bhmaxColumns+1].frameAnchorBottom)
			if frameAnchorBottom then
				local lastLine = nil
				for n=1,linesTotal do 
					local inLine = (n-1) % frameColumns
					local line = ((n-1) - inLine) / frameColumns
					columnFrame.lines[n]:ClearAllPoints() 
					columnFrame.lines[n]:SetPoint("BOTTOMLEFT", inLine*frameWidth, line*columnFrame.iconSize+line*frameBetweenLines) 
					
					if line ~= lastLine then
						columnFrame.lines[n].IsNewLine = true
					else
						columnFrame.lines[n].IsNewLine = nil
					end
					lastLine = line
				end
			else
				local lastLine = nil
				for n=1,linesTotal do 
					local inLine = (n-1) % frameColumns
					local line = floor((((n-1) - inLine) / frameColumns ) +0.5 )
					columnFrame.lines[n]:ClearAllPoints()
					columnFrame.lines[n]:SetPoint("TOPLEFT", inLine*frameWidth, -line*columnFrame.iconSize-line*frameBetweenLines) 
					
					if line ~= lastLine then
						columnFrame.lines[n].IsNewLine = true
					else
						columnFrame.lines[n].IsNewLine = nil
					end
					lastLine = line
				end
			end
		end
		
		if VBH_ColumnOptions[i].enabled and VBH.ExCD2.enabled then
			columnFrame.optionIsEnabled = true
			columnFrame:Show()
		else
			columnFrame.optionIsEnabled = nil
			columnFrame:Hide()
		end
		if not VBH.ExCD2.SplitOpt then
			columnFrame:ClearAllPoints()
			columnFrame:SetPoint("TOPLEFT",module.frame,Width, 0)
		else
			if VBH_ColumnOptions[i].posX and VBH_ColumnOptions[i].posY then
				columnFrame:ClearAllPoints()
				columnFrame:SetPoint("TOPLEFT",UIParent,"BOTTOMLEFT",VBH_ColumnOptions[i].posX,VBH_ColumnOptions[i].posY)
			else
				columnFrame:ClearAllPoints()
				columnFrame:SetPoint("CENTER",UIParent,"CENTER",0,0)
			end
		end
		if VBH_ColumnOptions[i].enabled then
			Width = Width + frameWidth*frameColumns
		end
	end
	module.frame:SetWidth(Width)
	module.frame:SetHeight(maxHeight*maxLine + maxBetweenLines)
	module.frame:SetAlpha((VBH_ColumnOptions[module.db.bhmaxColumns+1].frameAlpha or module.db.bhcolsDefaults.frameAlpha)/100)
	if argScaleFix == "ScaleFix" then
		BH.F.SetScaleFix(module.frame,(VBH_ColumnOptions[module.db.bhmaxColumns+1].frameScale or module.db.bhcolsDefaults.frameScale)/100)
	else
		module.frame:SetScale((VBH_ColumnOptions[module.db.bhmaxColumns+1].frameScale or module.db.bhcolsDefaults.frameScale)/100) 
	end
	
	module:updateCombatVisibility()
	
 	SortAllData()
 	UpdateAllData()
end

function module:SplitExCD2Window()
	if VBH.ExCD2.SplitOpt then
		for i=1,module.db.bhmaxColumns do 
			module.frame.colFrame[i]:SetParent(UIParent)
			module.frame.colFrame[i]:EnableMouse(false)

			if not VBH.ExCD2.lock then 
				BH.F.LockMove(module.frame.colFrame[i],true,module.frame.colFrame[i].lockTexture)
				BH.lib.AddShadowComment(module.frame.colFrame[i],nil,L.cd2,i,72,"OUTLINE")
			end
		end
		module.frame:Hide()
	else
		for i=1,module.db.bhmaxColumns do 
			module.frame.colFrame[i]:SetParent(module.frame)
			BH.F.LockMove(module.frame.colFrame[i],nil,module.frame.colFrame[i].lockTexture)
			BH.lib.AddShadowComment(module.frame.colFrame[i],1)
		end
		module.frame:Show()
	end

end

function module:slash(arg1,arg2)
	if string.find(arg1,"runcd ") then
		local sid,name = arg2:match("%a+ (%d+) (.+)")
		if sid and name then
			print("Run CD "..sid.." by "..name)
			module.main:COMBAT_LOG_EVENT_UNFILTERED(nil,"SPELL_CAST_SUCCESS",nil,nil,name,nil,nil,nil,nil,nil,nil,sid)
		end
	elseif string.find(arg1,"resetcd ") then
		local sid,name = arg2:match("%a+ (%d+) (.+)")
		if sid and name then
			print("Reset CD "..sid.." by "..name)
			local j = module.db.bhcdsNav[name][sid]
			if j then
				j[3] = 0
			end
		end
	end
end
