local GlobalAddonName, ExRT = ...

local GetTime, IsEncounterInProgress, RAID_CLASS_COLORS, GetInstanceInfo, GetSpellCharges = GetTime, IsEncounterInProgress, RAID_CLASS_COLORS, GetInstanceInfo, GetSpellCharges
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 = UnitIsDeadOrGhost, UnitIsConnected, UnitName, UnitCreatureFamily, UnitIsDead, UnitIsGhost, UnitGUID, UnitInRange

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

local VExRT, VExRT_CDE = nil

local module = ExRT.mod:New("ExCD2",ExRT.L.cd2)
local ELib,L = ExRT.lib,ExRT.L

module._C = {}
module.db.spellDB = {
{31821,	"PALADIN",	nil,			{31821,	180,	6},	nil,			nil,			},	--Владение аурами
{204150,"PALADIN",	nil,			nil,			{204150,300,	6},	nil,			},	--Эгида Света
{62618,	"PRIEST",	nil,			{62618,	180,	10},	nil,			nil,			},	--Слово силы: Барьер
{98008,	"SHAMAN",	nil,			nil,			nil,			{98008,	180,	6},	},	--Тотем духовной связи
{97462,	"WARRIOR",	nil,			{97462,	180,	10},	{97462,	180,	10},	nil,			},	--Ободряющий клич
{31842,	"PALADIN",	nil,			{31842,	120,	20},	nil,			nil,			},	--Гнев карателя
{64843,	"PRIEST",	nil,			nil,			{64843,	180,	8},	nil,			},	--Божественный гимн
{108280,"SHAMAN",	nil,			nil,			nil,			{108280,180,	10},	},	--Тотем целительного прилива
{740,	"DRUID",	nil,			nil,			nil,			nil,{740,180,	8},	},	--Спокойствие
{115310,"MONK",		nil,			nil,			nil,			{115310,180,	0},	},	--Восстановление сил
{15286,	"PRIEST",	nil,			nil,			nil,			{15286,	180,	15},	},	--Объятия вампира
{196718,"DEMONHUNTER",	nil,			{196718,180,	8},	nil,						},	--Мрак
{207399,"SHAMAN",	nil,			nil,			nil,			{207399,300,	30},	},	--Тотем защиты Предков

{102342,"DRUID",	nil,			nil,			nil,			nil,{102342,90,	12},	},	--Железная кора
{47788,	"PRIEST",	nil,			nil,			{47788,	240,	10},	nil,			},	--Оберегающий дух
{33206,	"PRIEST",	nil,			{33206,	240,	8},	nil,			nil,			},	--Подавление боли
{6940,	"PALADIN",	nil,			{6940,	150,	0},	{6940,	150,	0},	nil,			},	--Жертвенное благословление
{633,	"PALADIN",	{633,	600,	0},	nil,			nil,			nil,			},	--Возложение рук
{116849,"MONK",		nil,			nil,			nil,			{116849,180,	12},	},	--Исцеляющий кокон
{207810,"DEMONHUNTER",	nil,			nil,			{207810,120,	15},				},	--Узы Пустоты
{1022,	"PALADIN",	{1022,	300,	10},	nil,			nil,			nil,			},	--Благословение защиты
{204018,"PALADIN",	nil,			nil,			{204018,180,	10},	nil,			},	--Благословение защиты от заклинаний
{1044,	"PALADIN",	{1044,	25,	8},	nil,			nil,			nil,			},	--Благословенная свобода
{73325,	"PRIEST",	nil,			{73325,	90,	0},	{73325,	90,	0},	nil,			},	--Духовное рвение

{106898,"DRUID",	nil,			nil,			{77764,	120,	8},	{77761,	120,	8},nil,	},	--Тревожный рев
{192077,"SHAMAN",	{192077,120,	15},	nil,			nil,			nil,			},	--Тотем ветряного порыва

{187614,"NO",		{187614,120,	15},	nil,			nil,			nil,			},	--Legendary DD
{187612,"NO",		{187612,120,	15},	nil,			nil,			nil,			},	--Legendary Heal
{187613,"NO",		{187613,120,	15},	nil,			nil,			nil,			},	--Legendary Tank

{161642,"NO",		{161642,0,	0},	nil,			nil,			nil,			},	--Resurrecting [Raid Combat Res]
{20484,	"DRUID",	{20484,	600,	0},	nil,			nil,			nil,nil,		},	--Возрождение
{20707,	"WARLOCK",	{20707,	600,	0},	nil,			nil,			nil,			},	--Камень души
{61999,	"DEATHKNIGHT",	{61999,	600,	0},	nil,			nil,			nil,			},	--Воскрешение союзника
{20608,	"SHAMAN",	{21169,	1800,	0},	nil,			nil,			nil,			},	--Реинкарнация

{46968,	"WARRIOR",	{46968,	40,	0},	nil,			nil,			nil,			},	--Ударная волна
{119381,"MONK",		{119381,45,	5},	nil,			nil,			nil,			},	--Круговой удар ногой
{179057,"DEMONHUNTER",	nil,			{179057,60,	5},	nil,						},	--Кольцо Хаоса
{192058,"SHAMAN",	{192058,45,	2},	nil,			nil,			nil,			},	--Тотем выброса тока

{32375,	"PRIEST",	{32375,	15,	0},	nil,			nil,			nil,			},	--Массовое рассеивание
{64901,	"PRIEST",	nil,			nil,			{64901,	360,	10},	nil,			},	--Символ надежды
{29166,	"DRUID",	nil,			{29166,	180,	10},	nil,			nil,{29166,180,	10},	},	--Озарение

{108199,"DEATHKNIGHT",	nil,			{108199,180,	0},	nil,			nil,			},	--Хватка Кровожада
{49576,	"DEATHKNIGHT",	nil,			{49576,	15,	0},	{49576,	25,	0},	{49576,	25,	0},	},	--Хватка смерти
{2825,	"SHAMAN",	{2825,	300,	40},	nil,			nil,			nil,			},	--Жажда крови
{80353,	"MAGE",		{80353,	300,	40},	nil,			nil,			nil,			},	--Искажение времени
--{id,	class,		all specs,		spec1,			spec2={spellid,cd,duration},spec3,spec4		},	--name
}


module.db.Cmirror = module._C
module.db.dbCountDef = #module.db.spellDB
module.db.findspecspells = {
	[224968] = 62, [30451] = 62, [7268] = 62,
	[194466] = 63, [133] = 63, [11366] = 63,
	[214634] = 64, [116] = 64, [30455] = 64,
	
	[200652] = 65, [20473] = 65, [82326] = 65,
	[209202] = 66, [53600] = 66, [31935] = 66,
	[205273] = 70, [85256] = 70, [53385] = 70, 

	[209577] = 71, [12294] = 71, [167105] = 71,
	[205546] = 72, [23881] = 72, [184367] = 72,
	[203524] = 73, [20243] = 73, [23922] = 73,
	
	[202767] = 102, [78674] = 102, [190984] = 102,
	[210722] = 103, [52610] = 103, --[1822] = 103, 
	[200851] = 104, [33917] = 104, [22842] = 104,
	[208253] = 105, [188550] = 105, [48438] = 105, 

	[205223] = 250, [206930] = 250, [50842] = 250,
	[190778] = 251, [49143] = 251, [49184] = 251,
	[220143] = 252, [47541] = 252, [63560] = 252, 

	[207068] = 253, [193455] = 253, [34026] = 253,
	[204147] = 254, [19434] = 254, [185901] = 254,
	[203415] = 255, [190928] = 255, [186270] = 255, 

	[207946] = 256, [200829] = 256, [47666] = 256,
			[139] = 257, [33076] = 257,
	[205065] = 258, [8092] = 258, [34914] = 258, 

	[192759] = 259, [1329] = 259, [1943] = 259, 
	[202665] = 260, [2098] = 260, [193315] = 260,
	[209782] = 261, [196819] = 261, [53] = 261,

	[205495] = 262, [188196] = 262, [188389] = 262,
	[204945] = 263, [17364] = 263, [60103] = 263,
	[207778] = 264, [61295] = 264, [1064] = 264,
	
	[216698] = 265, [30108] = 265, [980] = 265, 
	[211714] = 266, [603] = 266, [105174] = 266,
	[196586] = 267, [29722] = 267, [116858] = 267, 
	
	[214326] = 268, [205523] = 268, [121253] = 268, 
	[205320] = 269, [113656] = 269, --[100780] = 269,
	[205406] = 270, [115151] = 270, [116670] = 270,
	
	[201467] = 577, [162243] = 577, [198013] = 577,
	[207407] = 581, [203782] = 581, [228477] = 581,
}
module.db.classNames = ExRT.GDB.ClassList

module.db.specByClass = {}
for class,classData in pairs(ExRT.GDB.ClassSpecializationList) do
	local newData = {0}
	for i=1,#classData do
		newData[#newData + 1] = classData[i]
	end
	module.db.specByClass[class] = newData
end

module.db.specIcons = ExRT.GDB.ClassSpecializationIcons
module.db.specInDBase = {
	[253] = 4,	[254] = 5,	[255] = 6,
	[71] = 4,	[72] = 5,	[73] = 6,
	[65] = 4,	[66] = 5,	[70] = 6,
	[62] = 4,	[63] = 5,	[64] = 6,
	[256] = 4,	[257] = 5,	[258] = 6,
	[265] = 4,	[266] = 5,	[267] = 6,
	[250] = 4,	[251] = 5,	[252] = 6,
	[259] = 4,	[260] = 5,	[261] = 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,
}

do
	local specList = {
		[62] = "MAGEDPS1",		--Arcane
		[63] = "MAGEDPS2",		--Fire
		[64] = "MAGEDPS3",		--Frost
		[65] = "PALADINHEAL",
		[66] = "PALADINTANK",
		[70] = "PALADINDPS",
		[71] = "WARRIORDPS1",		--Arms
		[72] = "WARRIORDPS2",		--Fury
		[73] = "WARRIORTANK",
		[102] = "DRUIDDPS1",		--Owl
		[103] = "DRUIDDPS2",		--Cat
		[104] = "DRUIDTANK",
		[105] = "DRUIDHEAL",
		[250] = "DEATHKNIGHTTANK",
		[251] = "DEATHKNIGHTDPS1",	--Frost
		[252] = "DEATHKNIGHTDPS2",	--Unholy
		[253] = "HUNTERDPS1",		--BM
		[254] = "HUNTERDPS2",		--MM
		[255] = "HUNTERDPS3",		--Survival
		[256] = "PRIESTHEAL1",		--Disc
		[257] = "PRIESTHEAL2",		--Holy
		[258] = "PRIESTDPS",
		[259] = "ROGUEDPS1",		--Assassination
		[260] = "ROGUEDPS2",		--Combat
		[261] = "ROGUEDPS3",		--Subtlety
		[262] = "SHAMANDPS1",		--Elemental
		[263] = "SHAMANDPS2",		--Enhancement
		[264] = "SHAMANHEAL",
		[265] = "WARLOCKDPS1",		--Affliction
		[266] = "WARLOCKDPS2",		--Demonology
		[267] = "WARLOCKDPS3",		--Destruction
		[268] = "MONKTANK",
		[269] = "MONKDPS",
		[270] = "MONKHEAL",
		[577] = "DEMONHUNTERDPS",
		[581] = "DEMONHUNTERTANK",
		[0] = "NO",
	}
	module.db.specInLocalizate = setmetatable({},{__index = function (t,k)
		if tonumber(k) then
			return specList[k] 
		else
			for i,val in pairs(specList) do
				if val == k then
					return i
				end
			end
		end
	end})
end

module.db.historyUsage = {}

module.db.testMode = nil
module.db.isEncounter = nil

local cdsNav_wipe,cdsNav_set = nil
do
	local cdsNavData = {}
	local nilData = {}
	module.db.cdsNav = 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.session_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
			if v > 0 then
				e[v] = true
			else
				e[-v] = nil
			end
		end
	})	
	module.db.session_gGUIDs_DEBUG = sessionData
end

module.db.session_Pets = {}
module.db.session_PetOwner = {}

module.db.spell_isTalent = {
	[7384]=1,	[46968]=1,	[107570]=1,	[772]=1,	[107574]=1,	[197690]=1,	[207982]=1,	[152277]=1,	
	[46968]=1,	[107570]=1,	[107574]=1,	[12292]=1,	[46924]=1,	[118000]=1,
	[46968]=1,	[107570]=1,	[202168]=1,	[107574]=1,	[228920]=1,
	
	[223306]=1,	[114158]=1,	[205656]=1,	[214202]=1,	[20066]=1,	[115750]=1,	[105809]=1,	[114165]=1,	[156910]=1,	[200025]=1,
	[204019]=1,	[204035]=1,	[20066]=1,	[115750]=1,	[204018]=1,	[204013]=1,	[213652]=1,	[204150]=1,	[152262]=1,	
	[213757]=1,	[205228]=1,	[217020]=1,	[20066]=1,	[115750]=1,	[202270]=1,	[198034]=1,	[205191]=1,	[210191]=1,	[205656]=1,	[224668]=1,	[210220]=1,	
	
	[217200]=1,	[53209]=1,	[109248]=1,	[19386]=1,	[19577]=1,	[131894]=1,	[120360]=1,	[194386]=1,	[201430]=1,	
	[194599]=1,	[212431]=1,	[206817]=1,	[109248]=1,	[19386]=1,	[199483]=1,	[131894]=1,	[120360]=1,	[194386]=1,	[214579]=1,	[198670]=1,
	[200163]=1,	[206505]=1,	[194277]=1,	[192488]=1,	[191241]=1,	[200108]=1,	[199483]=1,	[212436]=1,	[194855]=1,	[201078]=1,
	
	[16511]=1,	[200806]=1,	[137619]=1,	[152150]=1,
	[195457]=1,	[199743]=1,	[185767]=1,	[51690]=1,	[137619]=1,	[152150]=1,	
	[137619]=1,	[152150]=1,	
	
	[214621]=1,	[121536]=1,	[204263]=1,	[123040]=1,	[10060]=1,	[110744]=1,	[120517]=1,	
	[121536]=1,	[214121]=1,	[19236]=1,	[204263]=1,	[64901]=1,	[110744]=1,	[120517]=1,	[200183]=1,	[204883]=1,
	[205351]=1,	[205369]=1,	[10060]=1,	[205385]=1,	[200174]=1,	[193223]=1,
	
	[206931]=1,	[221699]=1,	[219809]=1,	[194679]=1,	[194844]=1,	[206977]=1,	
	[57330]=1,	[207127]=1,	[207167]=1,	[207256]=1,	[152279]=1,	[194913]=1,	
	[194918]=1,	[108194]=1,	[207319]=1,	[207349]=1,	[152280]=1,	[130736]=1,	
	
	[192063]=1,	[108281]=1,	[192077]=1,	[192058]=1,	[51485]=1,	[196932]=1,	[117014]=1,	[210714]=1,	[16166]=1,	[192249]=1,	[114050]=1,	[192222]=1,	
	[201898]=1,	[201897]=1,	[215864]=1,	[196884]=1,	[192077]=1,	[192058]=1,	[51485]=1,	[196932]=1,	[197214]=1,	[114051]=1,	[188089]=1,	
	[73685]=1,	[192063]=1,	[192077]=1,	[192058]=1,	[51485]=1,	[196932]=1,	[108281]=1,	[207399]=1,	[198838]=1,	[157153]=1,	[114052]=1,	[197995]=1,
	
	[205022]=1,	[205025]=1,	[212653]=1,	[55342]=1,	[116011]=1,	[157980]=1,	[205032]=1,	[108839]=1,	[113724]=1,	[153626]=1,	
	[212653]=1,	[55342]=1,	[116011]=1,	[157981]=1,	[205029]=1,	[108839]=1,	[113724]=1,	[44457]=1,	[198929]=1,	[153561]=1,	
	[205021]=1,	[212653]=1,	[55342]=1,	[116011]=1,	[157997]=1,	[205030]=1,	[108839]=1,	[113724]=1,	[153595]=1,	
	
	[48181]=1,	[6789]=1,	[5484]=1,	[196098]=1,	[48018]=1,	[108416]=1,	[108503]=1,	[205179]=1,		
	[205181]=1,	[6789]=1,	[30283]=1,	[196098]=1,	[48018]=1,	[108416]=1,	[205180]=1,	
	[152108]=1,	[6789]=1,	[30283]=1,	[196098]=1,	[48018]=1,	[108416]=1,	[108501]=1,	[196447]=1,
	
	[123986]=1,	[115098]=1,	[115008]=1,	[116841]=1,	[115399]=1,	[116844]=1,	[115315]=1,	[119381]=1,	[122281]=1,	[122783]=1,	[122278]=1,	[116847]=1,	[132578]=1,	
	[123986]=1,	[124081]=1,	[197945]=1,	[115008]=1,	[116841]=1,	[116844]=1,	[198898]=1,	[119381]=1,	[122281]=1,	[122783]=1,	[122278]=1,	[196725]=1,	[198664]=1,	[115313]=1,	[197908]=1,	
	[123986]=1,	[115098]=1,	[115008]=1,	[116841]=1,	[115288]=1,	[116844]=1,	[119381]=1,	[122281]=1,	[122783]=1,	[122278]=1,	[116847]=1,	[123904]=1,	[152175]=1,	[152173]=1,	

	[205636]=1,	[202425]=1,	[108238]=1,	[102280]=1,	[102401]=1,	[5211]=1,	[102359]=1,	[132469]=1,	[102560]=1,	[202359]=1,	[202360]=1,	[202770]=1,	
	[108238]=1,	[102280]=1,	[102401]=1,	[5211]=1,	[102359]=1,	[132469]=1,	[102543]=1,	[202060]=1,	[202028]=1,		
	[155835]=1,	[102280]=1,	[102401]=1,	[5211]=1,	[102359]=1,	[132469]=1,	[102558]=1,	[204066]=1,	
	[102351]=1,	[108238]=1,	[102280]=1,	[102401]=1,	[5211]=1,	[102359]=1,	[132469]=1,	[33891]=1,	[197721]=1,	

	[213241]=1,	[196555]=1,	[211881]=1,	[206491]=1,	[211048]=1,	[211053]=1,	
	[213241]=1,	[211881]=1,	[212084]=1,	[207810]=1,	[227225]=1,	[202138]=1,

	--Other & items
	[67826]=1,
}

module.db.spell_talentsList = {
--2:08 16.07.2016 Build 22231 [Pre-patch Beta]
	["WARRIOR"] = {
		[71] = {
			202297,7384,202161,
			46968,107570,103827,
			202316,772,107574,
			29838,202163,197690,
			215550,202593,207982,
			227266,215538,202612,
			152278,203179,152277,
		},
		[72] = {
			215556,202296,215568,
			46968,107570,103827,
			215569,206320,107574,
			202224,202163,208154,
			206315,215571,202922,
			12292,206313,215573,
			46924,202751,118000,
		},
		[73] = {
			46968,107570,103828,
			202168,205484,223657,
			202288,122509,107574,
			223662,202163,203201,
			202560,202561,202095,
			202572,202603,202743,
			152278,203177,228920,
		},
	},
	["PALADIN"] = {
		[65] = {
			223306,114158,196926,
			230332,114154,214202,
			198054,20066,115750,
			183425,183416,183415,
			197646,105809,114165,
			196923,53376,183778,
			156910,197446,200025,
		},
		[66] = {
			152261,204019,203785,
			203776,204035,204023,
			198054,20066,115750,
			204018,230332,203797,
			213652,204139,204077,
			204150,183778,204054,
			204074,152262,203791,
		},
		[70] = {
			198038,213757,205228,
			203316,217020,218178,
			198054,20066,115750,
			202271,202270,198034,
			215661,205191,210191,
			213313,230332,202273,
			223817,224668,210220,
		},
	},
	["HUNTER"] = {
		[253] = {
			204308,194397,193532,
			199530,217200,53209,
			109215,199523,199921,
			199528,194306,130392,
			109248,19386,19577,
			131894,120360,194386,
			201430,199532,191384,
		},
		[254] = {
			155228,193533,53238,
			194595,194599,199527,
			109215,199523,199921,
			212431,206817,213423,
			109248,19386,199483,
			131894,120360,194386,
			214579,198670,199522,
		},
		[255] = {
			204315,200163,201082,
			206505,201075,201078,
			109215,199523,199921,
			194277,199518,162488,
			191241,200108,199483,
			212436,194855,87935,
			194407,199543,191384,
		},
	},
	["ROGUE"] = {
		[259] = {
			196864,193640,16511,
			14062,108208,108209,
			193531,114015,14983,
			108211,79008,31230,
			196861,131511,154904,
			200802,193539,200806,
			152152,137619,152150,
		},
		[260] = {
			196937,200733,196938,
			195457,196924,196922,
			193531,114015,14983,
			193546,79008,31230,
			199743,131511,108216,
			185767,193539,51690,
			5171,137619,152150,
		},
		[261] = {
			31223,193537,200758,
			14062,108208,108209,
			193531,114015,14983,
			200759,79008,31230,
			196951,131511,200778,
			196979,193539,206237,
			196976,137619,152150,
		},
	},
	["PRIEST"] = {
		[256] = {
			200347,193134,214621,
			121536,64129,193063,
			204263,196704,205367,
			129250,197045,123040,
			197419,10060,109142,
			152118,110744,120517,
			204197,200309,204065,
		},
		[257] = {
			200128,200153,193155,
			121536,214121,19236,
			204263,200199,196707,
			196985,200209,64901,
			109186,32546,197034,
			197031,110744,120517,
			200183,193157,204883,
		},
		[258] = {
			109142,193195,205351,
			193173,64129,193063,
			205369,196704,205367,
			199849,199853,205371,
			199855,155271,162452,
			10060,205385,200174,
			193225,73510,193223,
		},
	},
	["DEATHKNIGHT"] = {
		[250] = {
			195679,221536,206931,
			194662,212744,211078,
			219786,221699,205727,
			206940,205723,219809,
			206970,206960,219779,
			206967,194679,206974,
			194844,206977,114556,
		},
		[251] = {
			207057,194878,207061,
			207060,194909,57330,
			207126,207127,207142,
			207161,207167,207170,
			207188,207200,212765,
			207230,207104,194912,
			207256,152279,194913,
		},
		[252] = {
			194916,207264,207269,
			207317,194917,194918,
			207289,207305,207311,
			207313,108194,207316,
			207321,207319,212763,
			198943,207346,207272,
			207349,152280,130736,
		},
	},
	["SHAMAN"] = {
		[262] = {
			201909,170374,210643,
			192063,108281,192077,
			192058,51485,196932,
			117014,192087,108283,
			192235,117013,210714,
			16166,192249,210707,
			114050,210689,192222,
		},
		[263] = {
			201898,201900,201897,
			215864,196884,192077,
			192058,51485,196932,
			192106,192087,210853,
			192234,210727,210731,
			192246,197211,197214,
			114051,197992,188089,
		},
		[264] = {
			200071,73685,200072,
			192063,192088,192077,
			192058,51485,196932,
			197464,108281,200076,
			207399,198838,207401,
			197467,157153,108283,
			114052,197995,157154,
		},
	},
	["MAGE"] = {
		[62] = {
			205022,205025,205035,
			212653,86949,11958,
			55342,116011,1463,
			157980,205032,205028,
			108839,113724,205036,
			114923,157976,205039,
			155147,198923,153626,
		},
		[63] = {
			205020,205023,205026,
			212653,86949,11958,
			55342,116011,1463,
			157981,205029,205033,
			108839,113724,205036,
			44457,157976,205037,
			155148,198929,153561,
		},
		[64] = {
			205021,205024,205027,
			212653,86949,11958,
			55342,116011,1463,
			157997,205030,56377,
			108839,113724,205036,
			112948,157976,205038,
			155149,199786,153595,
		},
	},
	["WARLOCK"] = {
		[265] = {
			48181,196102,198590,
			196105,196103,196104,
			219272,6789,5484,
			63106,196226,196098,
			48018,111400,108416,
			152107,108501,108503,
			205178,205179,215941,
		},
		[266] = {
			196269,205181,205145,
			196270,196272,196277,
			219272,6789,30283,
			196283,196605,196098,
			48018,111400,108416,
			152107,108501,171975,
			205180,157695,215941,
		},
		[267] = {
			196406,205184,17877,
			205148,152108,196104,
			219272,6789,30283,
			196412,196408,196098,
			48018,111400,108416,
			152107,108501,108503,
			196410,196447,215941,
		},
	},
	["MONK"] = {
		[268] = {
			123986,196607,115098,
			115008,116841,115173,
			196721,115399,196719,
			116844,115315,119381,
			122281,122783,122278,
			116847,132578,196730,
			196738,196736,196737,
		},
		[269] = {
			123986,196607,115098,
			115008,116841,115173,
			115288,115396,121817,
			116844,196722,119381,
			122281,122783,122278,
			116847,123904,196740,
			196743,152175,152173,
		},
		[270] = {
			123986,124081,197945,
			115008,116841,115173,
			197915,210802,197900,
			116844,198898,119381,
			122281,122783,122278,
			196725,198664,115313,
			197908,197895,210804,
		},
	},
	["DRUID"] = {
		[102] = {
			205636,202425,202345,
			108238,102280,102401,
			202157,197491,197492,
			5211,102359,132469,
			114107,102560,202347,
			202342,202359,202360,
			202770,202354,202430,
		},
		[103] = {
			202021,202022,155580,
			108238,102280,102401,
			197488,217615,197492,
			5211,102359,132469,
			158476,102543,52610,
			202031,202032,202060,
			202028,155672,155577,
		},
		[104] = {
			203953,155835,203962,
			204012,102280,102401,
			197488,202155,197492,
			5211,102359,132469,
			158477,102558,203964,
			203974,155578,203965,
			204053,204066,80313,
		},
		[105] = {
			200383,102351,207383,
			108238,102280,102401,
			197632,197490,197491,
			5211,102359,132469,
			158478,33891,200390,
			207385,197073,155675,
			155577,197061,197721,
		},
	},
	["DEMONHUNTER"] = {
		[577] = {
			192939,206475,203550,
			203551,203555,206478,
			213241,206416,206473,
			196555,205411,204909,
			206476,211881,206491,
			203556,206477,193897,
			211048,211053,213410,
		},
		[581] = {
			207550,207548,209400,
			207697,227174,207739,
			213241,227322,211881,
			218612,209795,217996,
			207666,202138,209281,
			212084,203753,218679,
			209258,207810,227225,
		},
	},
}
module.db.spell_glyphsList = {}
module.db.spell_charge_fix = {		--Спелы с зарядами
	[100]=103827,
	[12294]=202593,
	[2565]=1,
	[198304]=1,
	[35395]=1,
	[214202]=1,
	[53595]=1,
	[53600]=1,
	[210191]=1,
	[214579]=1,
	[190928]=1,
	[200163]=1,
	[185313]=1,
	[121536]=1,
	[32379]=1,
	[50842]=1,
	[221699]=1,
	[194679]=1,
	[51505]=108283,
	[5394]=108283,
	[212653]=1,
	[45438]=11958,
	[116011]=1,
	[122]=205036,
	[108853]=1,
	[205181]=1,
	[17962]=1,
	[109132]=1,
	[115308]=1,
	[119582]=1,
	[122281]=1,
	[197945]=1,
	[61336]=1,
	[202028]=1,
	[22842]=1,
	[18562]=200383,
	[195072]=1,
	[203720]=1,
	[189110]=1,
	[190784]=230332,
	[215206]=1,
}

module.db.spell_durationByTalent_fix = {	--Изменение длительности талантом\глифом   вид: [спелл] = {spellid глифа\таланта, изменение времени (-10;10;*0.5;*1.5)}
	[52174] = {202163,3},
	[167105] = {202612,16},
	[31842] = {53376,"*1.5"},
	[781] = {109215,8},
	[186257] = {199921,3},
	[190925] = {109215,8},
	[212552] = {219779,"*1.5"},
	[48707] = {210852,"*2",207321,5},
	[80240] = {196410,12},
	[202137] = {209281,-1,207666,2},
	[204596] = {209281,-1,207666,2},
	[207684] = {209281,-1},
	[202138] = {209281,-1,207666,2},
	[6544] = {209483,4},
	[1160] = {188651,"*1.5"},
	[31281] = {200311,2},
	[498] = {200407,4},
	[1022] = {206338,"*1.5"},
	[1044] = {206338,"*1.5"},
	[6940] = {206338,"*1.5"},
	[204018] = {206338,"*1.5"},
	[26573] = {209218,{1,2,3,4,5,6}},
	[205273] = {179546,6},
	[31884] = {186945,{2.5,5,7.5,10,12.5,15}},
	[224668] = {186945,{2.5,5,7.5,10,12.5,15}},
	[193530] = {197038,{1,2,3,4,5,6}},
	[121471] = {197386,{3,6,10,13,16,20}},
	[47536] = {197727,{1,2,3,4,5,6}},
	[49028] = {192514,{2,4,6,8,10,12}},
	[63560] = {208598,{2,4,6,8,10,12}},
	[5394] = {210604,"*1.2"},
	[108280] = {210604,"*1.2"},
	[98008] = {210604,"*1.2"},
	[12042] = {187264,{1,2,3,4,5,6}},
	[61336] = {210557,{1,2,3,4,5,6}},
	[22812] = {200399,{0.5,1,1.5,2,2.5,3}},
	[192081] = {200399,{0.5,1,1.5,2,2.5,3}},
	[192083] = {200399,{0.5,1,1.5,2,2.5,3}},
	[204021] = {212894,2},
}

module.db.spell_cdByTalent_fix = {		--Изменение кд талантом\глифом   вид: [спелл] = {spellid глифа\таланта, изменение времени (-60;60);spellid2,time2;spellid3,time3;...}
	[100] = {103827,-3},
	[52174] = {202163,-15},
	[642] = {114154,"*0.7",213313,"*0.5"},
	[498] = {114154,"*0.7"},
	[633] = {200326,{-54.5,-100,-138.5,-171.5,-200,-225},114154,"*0.7",206380,"*0.4"},
	[20473] = {53376,"*0.5"},
	[190784] = {204139,"*0.5"},
	[35395] = {203316,-1},
	[187698] = {199518,"*0.5",203752,"*0.8"},
	[191433] = {199518,"*0.5",203752,"*0.8"},
	[187650] = {199518,"*0.85",203752,"*0.8"},
	[8122] = {196704,-30},
	[108199] = {206970,-60},
	[212552] = {212763,-15},
	[79206] = {192088,-60},
	[80240] = {196410,-20},
	[109132] = {115173,-5},
	[115308] = {196721,-3},
	[119582] = {196721,-3},
	[77761] = {204012,"*0.5"},
	[22812] = {200402,{-3,-6,-9,-12,-15,-18},203965,"*0.67"},
	[61336] = {203965,"*0.67"},
	[18562] = {200383,-5},
	[740] = {197073,-60},
	[102342] = {197061,-30},
	[198793] = {203551,-10},
	[179057] = {206477,"*0.67"},
	[189110] = {207550,-5},
	[202137] = {209281,"*0.8"},
	[204596] = {209281,"*0.8"},
	[207684] = {209281,"*0.8"},
	[202138] = {209281,"*0.8"},
	[1719] = {200870,-10},
	[6544] = {203230,{-2,-4,-6,-8,-10,-12}},
	[1022] = {200298,{-15,-30,-45,-60,-75,-90},186994,{-30,-60,-90,-120,-150,-180}},
	[1044] = {200298,{-1.25,-2.5,-3.75,-5,-6.25,-7.5}},
	[6940] = {200298,{-7.5,-15,-22.5,-30,-37.5,-45},209285,-60},
	[31850] = {209220,{-10,-20,-30,-40,-50,-60}},
	[184662] = {184778,{-10,-20,-30,-40,-50,-60}},
	[186257] = {197343,-60,225092,-20,206332,"*0.5"},
	[186387] = {190567,{-1.5,-3,-4.5,-6,-7.5,-9}},
	[193526] = {190462,{-10,-20,-30,-40,-50,-60}},
	[186289] = {225092,-20,206332,"*0.5"},
	[186265] = {225092,-20,206332,"*0.5"},
	[162488] = {203752,"*0.8"},
	[194277] = {203752,"*0.8"},
	[193530] = {206332,"*0.5"},
	[31224] = {192323,{-3,-6,-10,-13,-16,-20}},
	[79140] = {192349,{-10,-20,-30,-40,-50,-60}},
	[2983] = {192345,{-3,-6,-10,-13,-16,-20}},
	[13750] = {202907,{-10,-18,-25,-33,-40,-48}},
	[33206] = {197713,{-10,-20,-30,-40,-50,-60}},
	[34861] = {196429,{-3,-6,-10,-13,-16,-20}},
	[47585] = {193642,{-10,-20,-30,-40,-50,-60}},
	[20608] = {207357,-600},
	[21169] = {207357,-600},
	[195676] = {187301,{-2,-4,-6,-8,-10,-12}},
	[104773] = {211131,{-10,-20,-30,-40,-50,60},215223,-30},
	[191427] = {201460,{-20,-40,-60,-80,-100,-120}},

	[34433] = {186980,-160},
	[200174] = {186980,-40},
	[12975] = {185796,"*0.5"},
}

module.db.tierSetsSpells = {	--[specID.tierID.tierMark] = {2P Bonus Spell ID, 4P Bonus Spell ID}
	[5181] = {186980,nil},		--> Priest T18
	[2181] = {185581,nil},		--> Paladin T18
	[1181] = {185796,185799},	--> Warrior T18
	[4181] = {nil,186279},		--> Rouge T18
}
module.db.tierSetsList = {	-- [itemID] = specID.tierID.tierMark
	[124155] = 5181, [124161] = 5181, [124166] = 5181, [124172] = 5181, [124178] = 5181,
	[124319] = 1181, [124329] = 1181, [124334] = 1181, [124340] = 1181, [124346] = 1181,
	[124318] = 2181, [124328] = 2181, [124333] = 2181, [124339] = 2181, [124345] = 2181,
	[124248] = 4181, [124257] = 4181, [124263] = 4181, [124269] = 4181, [124274] = 4181,
}

module.db.spell_talentReplaceOther = {		--Спелы, показ которых нужно убрать при наличии таланта (талант заменяет эти спелы) [spellID] = [talent Spell ID]
	[227847]=152277,
	[34428]=202168,
	[53695]=204035,
	[86659]=204018,
	[184092]=213652,
	[35395]=217020,
	[184575]={202270,198034},
	[31884]=224668,
	[187650]=162488,
	[187698]=194277,
	[187650]=162488,
	[195645]=200108,
	[187708]=212436,
	[2094]=199743,
	[34433]={123040,200174},
	[8122]=205369,
	[47568]=207127,
	[43265]=152280,
	[51514]=196932,
	[198067]=192249,
	[1953]=212653,
	[31687]=205024,
	[109132]=115008,
	[137639]=152173,
	[194223]=102560,
	[106951]=102543,
	[198589]={196555,205411},
	[1022]=204018,
}

module.db.spell_aura_list = {		--Спелы, время действия которых отменять при отмене бафа 	[buff_sid] = spellID
	[23920]=23920,
	[147833]=198304,
	[184662]=184662,
	[31850]=31850,
	[152262]=152262,
	[199483]=199483,
	[47788]=47788,
	[48707]=48707,
	[207319]=207319,
	[198839]=198838,
	[207495]=207399,
	[110960]=110959,
	[45438]=45438,
	[11426]=11426,
	[12051]=12051,
	[108839]=108839,
	[108416]=108416,
	[122278]=122278,
	[116849]=116849,
	[122470]=122470,
	[227225]=227225,
	[214366]=214366,
	[214423]=214423,
	[215670]=215670,
}
module.db.spell_speed_list = {		--Спелы, которым менять время действия на основании спелхасты
	[740]=true,
	[64843]=true,
	[12051]=true,
	[113656]=true,
}
module.db.spell_afterCombatReset = {	--Принудительный сброс кд после боя с боссом (для спелов с кд менее 5 мин., 3мин после 6.1)
	[161642]=true,
	
	[31884]=true,
	[12042]=true,
}
module.db.spell_afterCombatNotReset = {	--Запрещать сброс кд после боя с боссом (для петов, например; для спелов с кд 5 и более мин., для анха)
	[90355]=true,
	[126393]=true,
	[53478]=true,
	[55709]=true,
	[20608]=true,
	[21169]=true,
	[159931]=true,
	[159956]=true,
	
	--[26297]=true,	--Fixed in 7.0?
	[67826]=true,
	
	[199740]=true,
}
module.db.spell_reduceCdByHaste = {	--Заклинания, кд которых уменьшается хастой
	[20473]=true,
	[845]=true,
	[12294]=true,
	[23881]=true,
	[23922]=true,
	[2565]=true,
	[6572]=true,
	[6343]=true,
	[26573]=true,
	[85222]=true,
	[20271]=true,
	[35395]=true,
	[53595]=true,
	[184092]=true,
	[31935]=true,
	[53600]=true,	
	[204019]=true,
	[213652]=true,
	[184575]=true,
	[205228]=true,
	[213757]=true,
	[217020]=true,
	[202270]=true,
	[198034]=true,
	[34026]=true,
	[217200]=true,
	[53209]=true,
	[194386]=true,
	[120679]=true,
	[214579]=true,
	[200163]=true,
	[212436]=true,
	[202800]=true,
	[190928]=true,
	[17]=true,
	[129250]=true,
	[204883]=true,
	[33076]=true,
	[8092]=true,
	[228260]=true,
	[50842]=true,
	[194913]=true,
	[207317]=true,
	[201897]=true,
	[187874]=true,
	[17364]=true,
	[193796]=true,
	[44425]=true,
	[198929]=true,
	[44457]=true,
	[108853]=true,
	[196447]=true,
	[17962]=true,
	[115308]=true,
	[119582]=true,
	[121253]=true,
	[116847]=true,
	[100784]=true,
	[107428]=true,
	[196725]=true,
	[152175]=true,
	[113656]=true,
	[202028]=true,
	[22842]=true,
	[6807]=true,
	[33917]=true,
	[188499]=true,
	[213241]=true,
	[203720]=true,
	[178740]=true,
}
module.db.spell_resetOtherSpells = {	--Заклинания, которые откатывают другие заклинания
	[191427]={{198013,193897},{179057,193897},{198589,193897}},
	[187827]={{202137,210867},{204596,210867},{207684,210867},{202138,210867}},
}
module.db.spell_sharingCD = {		--Заклинания, которые запускают кд на другие заклинания 	[spellID] = {[otherSpellID] = CD}
	[90633] = {[90632]=120,[90631]=120},
	[90632] = {[90633]=120,[90631]=120},
	[90631] = {[90632]=120,[90633]=120},
}

module.db.spell_runningSameSpell = {}	--Схожие заклинания

do
	local sameSpellsData = {
		{121093,59545,59543,59548,59542,59544,59547,28880},		--DraeneiRacial
		{69041,69070},							--Goblin Racial
		{28730,69179,129597,80483,155145,25046,50613,202719},		--Belf Racial
		{106898,77764,77761},						--Stampeding Roar
		{187611,187614,187615},						--Legendary Ring
		{51514,211015,210873,211010,211004},				--Hex
		{202767,202771,202768},						--New moon [Balance Druid artifact]
		{115308,119582},						--Brewmaster brew
		{90633,90628},{90632,90626},{90631,89479},			--Guild Battle Standard
	}
	for i=1,#sameSpellsData do
		local list = sameSpellsData[i]
		for j=1,#list do
			module.db.spell_runningSameSpell[ list[j] ] = list
		end
	end
end

module.db.spell_reduceCdCast = {	--Заклинания, применение которых уменьшает время восстановления других заклинаний
	[1680]={{1719,152278},-2.5},
	[163201]={{1719,152278},-1},
	[1464]={{1719,152278},-2},
	[1715]={{1719,152278},-1},
	[845]={{1719,152278},-1},
	[12294]={{1719,152278},-2},
	[7384]={{1719,152278},-1},
	[772]={{1719,152278},-1.5},
	[207982]={{1719,152278},-1.5},
	
	[2565]={{1719,152278},-1,{12975,152278},-1,{871,152278},-1},
	[204488]={{1719,152278},-3,{12975,152278},-3,{871,152278},-3},
	[190456]={{1719,152278},-6,{12975,152278},-6,{871,152278},-6},
	[202168]={{1719,152278},-6,{12975,152278},-6,{871,152278},-6},
	
	[35395]={{20473,196926},-1.5,{85222,196926},-1.5},
	[20271]={{853,198054,-70},-10},
	[53600]={{184092,204074},-3,{213652,204074},-3,{31884,204074},-3},
	[85256]={{853,198054,70},-8},
	[53385]={{853,198054,70},-8},
	[213757]={{853,198054,70},-8},
	[215661]={{853,198054,70},-8},
	[210191]={{853,198054,70},-8},
	[202273]={{853,198054,70},-8},

	[2061]={2050,-6,{2050,196985},-2,{2050,200183,nil,200183},-12,{2050,196985,nil,200183},-4},
	[2060]={2050,-6,{2050,196985},-2,{2050,200183,nil,200183},-12,{2050,196985,nil,200183},-4},
	[596]={34861,-6,{34861,196985},-2,{34861,200183,nil,200183},-12,{34861,196985,nil,200183},-4},
	[585]={88625,-6,{88625,196985},-2,{88625,200183,nil,200183},-12,{88625,196985,nil,200183},-4},
	[32546]={2050,-3,34861,-3},
	[33076]={{34861,197034},-6},
	
	[196819]={{1856,186279},-5},
	[195452]={{1856,186279},-5},	
	
	[49998]={{55233,205723},-7.5},
	
	[47541]={{63560,198943},-5},
	
	[195676]={1953,-15},
	
	[107428]={{116680,210804},-30,{137639,209256},-2.2},
	
	[23922]={{871,215057},-4},
	[185358]={{193526,206889},-1.1},
	[198670]={{193526,206889},-1.1},
	[19434]={{193526,206889},-1.1},
	[186387]={{193526,206889},-1.1},
	[120679]={{34026,212278},-3.1},
	[185311]={{79140,208895},-0.6},
	[51723]={{79140,208895},-0.7},
	[703]={{79140,208895},-0.9},
	[1725]={{79140,208895},-0.6},
	[32645]={{79140,208895},-0.7},
	[185565]={{79140,208895},-0.8},
	[6770]={{79140,208895},-0.7},
	[192759]={{79140,208895},-0.7},
	[1833]={{79140,208895},-0.8},
	[1329]={{79140,208895},-1.1},
	[1943]={{79140,208895},-0.5},
	[408]={{79140,208895},-0.5},
	[1966]={{79140,208895},-0.4},
	[16511]={{79140,208895},-0.6},
	[152150]={{79140,208895},-0.5},
	[17]={{33206,214576},-4},
	[206930]={{55233,208706},-2},
	[51505]={{198067,191512},-2},
	[113656]={{137639,209256},-3.3},
	[100784]={{137639,209256},-1.1},
	[115151]={{115310,206902},-2.1},
	[78674]={{102560,208199},-5,{194223,208199},-5},
	[191034]={{102560,208199},-7.5,{194223,208199},-7.5},
}
module.db.spell_increaseDurationCast = {	--Заклинания, продляющие время действия
	[23922]={{2565,203177},1.5},
	
	[49184]={{196770,194912},0.5},
	[45524]={{196770,194912},0.5},
	[3714]={{196770,194912},0.5},
	[111673]={{196770,194912},0.5},
	[49020]={{196770,194912},1},
	[194913]={{196770,194912},0.5},
	
	[5143]={{12042,155147},2},
	[30455]={{12472,155149},2},
	
	[195452]={{121471,208892},1.5},
	[196819]={{121471,208892},1.5},
	[408]={{121471,208892},1.5},
}
module.db.spell_dispellsFix = {}
module.db.spell_dispellsList = {	--Заклинания-диспелы (мгновенно откатываются, если ничего не диспелят)
	[4987] = true,
	[527] = true,
	[51886] = true,
	[77130] = true,
	[475] = true,
	[115450] = true,
	[2782] = true,
	[88423] = true,
	[213644] = true,
}

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

module.db.spell_reduceCdByAuraFade = {	--Заклинания, кд которых уменьшается при спадении ауры до окончания времени действия. !Важно обязательное время действия для таких заклинаний
	[47788]={{47788,200209},-150},
}
module.db.spell_battleRes = {		--Заклинания-воскрешения [WOD]
	[20484]=true,
	[20707]=true,
	[61999]=true,
	--[126393]=true,
	[161642]=true,
	--[159931]=true,
	--[159956]=true,
}
module.db.isResurectDisabled = nil

module.db.spell_isRacial = {		--Расовые заклинания
	[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",
}

module.db.def_col = {			--Стандартные положения в колонках
	["161642;1"]=2,
	["97462;2"]=1,
	["97462;3"]=1,
	["46968;1"]=1,
	["1022;1"]=2,
	["204018;3"]=2,
	["204013;3"]=2,
	["1044;1"]=2,
	["31821;2"]=1,
	["633;1"]=2,
	["31842;2"]=1,
	["6940;2"]=2,
	["6940;3"]=2,
	["204150;3"]=1,
	["64843;3"]=1,
	["73325;2"]=2,
	["73325;3"]=2,
	["32375;1"]=1,
	["47788;3"]=2,
	["15286;4"]=1,
	["33206;2"]=2,
	["64901;3"]=1,
	["62618;2"]=1,
	["61999;1"]=2,
	["108199;2"]=1,
	["49576;2"]=3,
	["49576;3"]=3,
	["49576;4"]=3,
	["2825;1"]=3,
	["114052;4"]=1,
	["20608;1"]=2,
	["192077;1"]=1,
	["98008;4"]=1,
	["207399;4"]=1,
	["108280;4"]=1,
	["80353;1"]=3,
	["20707;1"]=2,
	["115310;4"]=1,
	["116849;4"]=2,
	["119381;1"]=1,
	["20484;1"]=2,
	["102342;5"]=2,
	["29166;2"]=2,
	["29166;5"]=2,
	["740;5"]=1,
	["106898;3"]=1,
	["106898;4"]=1,
	["179057;1"]=1,
	["196718;1"]=1,
	["207810;3"]=2,
}

module.db.petsAbilities = {	--> PetTypes = HUNTERS[ Tenacity [1], Cunning = [2], Ferocity[3] ]
	[0] = 						{},
	[L.creatureNames["Basilisk"]] = 		{1,	{159733,45},	},
	[L.creatureNames["Bat"]] = 		{2,	},
	[L.creatureNames["Bear"]] = 		{1,	{50256,10},	},
	[L.creatureNames["Beetle"]] = 		{1,	{90339,60,12},	},
	[L.creatureNames["Bird of Prey"]] = 	{2,	},
	[L.creatureNames["Boar"]] = 		{1,	},
	[L.creatureNames["Carrion Bird"]] = 	{3,	{24423,6},	},
	[L.creatureNames["Cat"]] = 		{3,	{24450,10},	{93435,45},	},
	[L.creatureNames["Chimaera"]] = 		{2,	{54644,10},	},
	[L.creatureNames["Core Hound"]] = 		{3,	{90355,360,40},	},
	[L.creatureNames["Crab"]] = 		{1,	{159926,60,12},	},
	[L.creatureNames["Crane"]] = 		{2,	{159931,600},	},
	[L.creatureNames["Crocolisk"]] = 		{1,	{50433,10},	},
	[L.creatureNames["Devilsaur"]] = 		{3,	{159953,60},	{54680,8},	},
	[L.creatureNames["Direhorn"]] = 		{1,	{137798,30},	},
	[L.creatureNames["Dog"]] = 		{3,	},
	[L.creatureNames["Dragonhawk"]] = 		{2,	},
	[L.creatureNames["Fox"]] = 		{3,	{160011,120},	},
	[L.creatureNames["Goat"]] = 		{3,	},
	[L.creatureNames["Gorilla"]] = 		{1,	},
	[L.creatureNames["Hyena"]] = 		{3,	{128432,90},	},
	[L.creatureNames["Monkey"]] = 		{2,	{160044,120},	},
	[L.creatureNames["Moth"]] = 		{3,	{159956,600},	},
	[L.creatureNames["Nether Ray"]] = 		{2,	{90355,360,40},	},
	[L.creatureNames["Porcupine"]] = 		{1,	},
	[L.creatureNames["Quilen"]] = 		{3,	{126393,600},	},
	[L.creatureNames["Raptor"]] = 		{3,	{160052,45},	},
	[L.creatureNames["Ravager"]] = 		{2,	},
	["Clefthoof"] = 				{1,	},					-- Clefthoof[WOD] = Rhino
	[L.creatureNames["Scorpid"]] = 		{1,	{160060,6},	},
	[L.creatureNames["Serpent"]] = 		{2,	{128433,90},	},
	[L.creatureNames["Shale Spider"]] = 	{1,	{160063,60,12},	},
	[L.creatureNames["Silithid"]] = 		{2,	{160065,10},	},
	[L.creatureNames["Spider"]] = 		{2,	{160067,10},	},
	[L.creatureNames["Spirit Beast"]] = 	{3,	{90328,10},	{90361,30},	},
	[L.creatureNames["Sporebat"]] = 		{2,	},
	[L.creatureNames["Tallstrider"]] = 	{3,	{160073,45},	},
	[L.creatureNames["Turtle"]] = 		{1,	{26064,60,12},	},
	[L.creatureNames["Warp Stalker"]] = 	{1,	{35346,15},	},
	[L.creatureNames["Wasp"]] = 		{3,	},
	[L.creatureNames["Water Strider"]] = 	{2,	},
	[L.creatureNames["Wind Serpent"]] = 	{2,	},
	[L.creatureNames["Wolf"]] = 		{3,	{24604,45},	},
	[L.creatureNames["Worm"]] = 		{1,	{93433,14},	},
	[1] = 						{0,	{53478,360,20},	{61685,25},	{63900,10},	},
	[2] = 						{0,	{53490,180,12},	{61684,32,16},	{53480,60,12},	},
	[3] = 						{0,	{61684,32,16},	{55709,480},	},
	[L.creatureNames["Ghoul"]] = 		{0,	{91837,45,10},	{91802,30},	{91797,60},	},
	[L.creatureNames["Felguard"]] = 		{0,	{89751,45,6},	{89766,30},	{30151,15},	},
	[L.creatureNames["Felhunter"]] = 		{0,	{19647,24},	{19505,15},	},
	[L.creatureNames["Fel Imp"]] = 		{0,	{115276,30},	},
	[L.creatureNames["Imp"]] = 		{0,	{89808,10},	{119899,30,12},	{89792,20},	},
	[L.creatureNames["Observer"]] = 		{0,	{115781,24},	{115284,15},	},
	[L.creatureNames["Shivarra"]] = 		{0,	{115770,25},	{115268,30},	},
	[L.creatureNames["Succubus"]] = 		{0,	{6360,25},	{6358,30},	},
	[L.creatureNames["Voidlord"]] = 		{0,	{115236,10}	},
	[L.creatureNames["Voidwalker"]] = 		{0,	{17735,10},	{17767,120,20},	{115232,10},	},
	[L.creatureNames["Wrathguard"]] = 		{0,	{115831,45,6},	},
	[L.creatureNames["Water Elemental"]] = 	{0,	{135029,25,4},	{33395,25},	},
}
module.db.spell_isPetAbility = {}
do
	for petName,petData in pairs(module.db.petsAbilities) do
		for i=2,#petData do
			module.db.spell_isPetAbility[petData[i][1]] = petName
		end
	end
end

module.db.itemsToSpells = {	-- Тринкеты вида [item ID] = spellID
	[113931] = 176878,
	[113969] = 176874,
	[118876] = 177597,	--Coin
	[118878] = 177594,	--Couplend
	[118880] = 177592,	--Candle
	[118882] = 177189,	--Kyanos
	[118884] = 176460,	--Kyb
	[113905] = 176873,	--Tank BRF
	[113834] = 176876,
	[113835] = 176875,	--Shard of nothing
	[113842] = 176879,
	[110002] = 165531,
	[110003] = 165543,
	[110008] = 165535,
	[110012] = 165532,
	[110013] = 165543,
	[110017] = 165534,
	[110018] = 165535,
	[114488] = 176883,
	[114489] = 176882,
	[114490] = 176884,
	[114491] = 176881,
	[114492] = 176885,
	[109997] = 165485,
	[109998] = 165542,
	[110007] = 165532,
	[124224] = 184270,	--Mirror of the Blademaster
	[124232] = 183929,	--Intuition's Gift
	[133598] = 201414,
	[133585] = 201371,
	
	[137105] = 206338,
	[137059] = 206380,
	[137017] = 207628,
	[137089] = 215176,
	[137054] = 215057,
	[137101] = 206332,
	[137033] = 206889,
	[137227] = 212278,
	[137100] = 208892,
	[137030] = 208895,
	[132436] = 214576,
	[132367] = 208706,
	[132376] = 210852,
	[137058] = 210604,
	[137097] = 209256,
	[137027] = 224489,
	[137096] = 206902,
	[137039] = 208199,
	[137061] = 215149,
	[137071] = 210867,
	[138949] = 210970,
	
	[64402] = 90633,
	[64401] = 90632,
	[64400] = 90631,
	
	[133642] = 215956,
	[137541] = 215648,
	[137539] = 214962,
	[137538] = 215936,
	[137537] = 215658,
	[137486] = 214980,
	[137462] = 215206,
	[137440] = 214584,
	[137433] = 215467,
	[137369] = 214971,
	[137344] = 214423,
	[137338] = 214366,
	[137329] = 215670,
	[133647] = 214203,
	[133646] = 214198,
	[139322] = 221837,
	[139333] = 221992,
	[139327] = 221695,
	[139326] = 222046,
	[139320] = 221803,
}
module.db.itemsArtifacts = {	-- Artifacts & First trait
	[127857] = 224968,
	[128820] = 194466,
	[128862] = 214634,
	
	[128823] = 200652,
	[128866] = 209202,
	[120978] = 205273,

	[128910] = 209577,
	[128908] = 205546,
	[128289] = 203524,
	
	[128858] = 202767,
	[128860] = 210722,
	[128821] = 200851,
	[128306] = 208253,

	[128402] = 205223,
	[128292] = 189186,
	[128403] = 220143,

	[128861] = 207068,
	[128826] = 204147,
	[128808] = 203415,

	[128868] = 207946,
	[128825] = 196684,
	[128827] = 205065,

	[128870] = 192759,
	[128872] = 202665,
	[128476] = 209782,

	[128935] = 205495,
	[128819] = 204945,
	[128911] = 207778,
	
	[128942] = 216698,
	[128943] = 211714,
	[128941] = 196586,
	
	[128938] = 214326,
	[128940] = 205320,
	[128937] = 205406,
	
	[127829] = 201467,
	[128832] = 207407,
}

do
	for itemID,spellID in pairs(module.db.itemsArtifacts) do
		module.db.itemsToSpells[itemID] = spellID
	end
	for itemID,spellID in pairs(module.db.itemsToSpells) do
		module.db.spell_isTalent[spellID] = true
	end
end
ExRT.F.table_add2(module.db.itemsToSpells,{
	[124634] = 187614,	--Legendary Ring
	[124636] = 187615,	--Legendary Ring
	[124635] = 187611,	--Legendary Ring
	[124637] = 187613,	--Legendary Ring
	[124638] = 187612,	--Legendary Ring
})

module.db.differentIcons = {	--Другие иконки заклинаниям
	[176875]="Interface\\Icons\\Inv_misc_trinket6oOG_Isoceles1",
	[176873]="Interface\\Icons\\Inv_misc_trinket6oIH_orb4",
	[184270]="Interface\\Icons\\spell_nature_mirrorimage",
	[183929]="Interface\\Icons\\spell_mage_presenceofmind",	
	[187614]="Interface\\Icons\\inv_60legendary_ring1c",
	[187613]="Interface\\Icons\\inv_60legendary_ring1b",
	[187612]="Interface\\Icons\\inv_60legendary_ring1a",
	
	[90633] = "Interface\\Icons\\inv_guild_standard_horde_c",
	[90632] = "Interface\\Icons\\inv_guild_standard_horde_b",
	[90631] = "Interface\\Icons\\inv_guild_standard_horde_a",
}

module.db.artifactAllSpells = {
	209483, 200870, 203230, 188651,
	200311, 200326, 200407, 200298, 209285, 209218, 209220, 186994, 179546, 184778, 186945,
	197038, 197343, 190567, 190462, 225092, 203752,
	192323, 192349, 192345, 202907, 197386,
	197727, 197713, 196429, 193642,
	192514, 208598,
	191512, 207357,
	187264, 187301, 195345,
	211131, 215223,
	210557, 200399, 200402,
	201460, 212894,
}


local isLegendaryRingInRaid_DD = nil
local isLegendaryRingInRaid_Tank = nil
local isLegendaryRingInRaid_Heal = nil

module.db.playerName = nil

module.db.plugin = {}

module.db.notAClass = { 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.maxLinesInCol = 100
module.db.maxColumns = 10

module.db.colsDefaults = {
	iconSize = 16,
	iconGray = true,
	iconPosition = 1,
	textureFile = ExRT.F.barImg,
	textureBorderSize = 0,
	fontSize = 12,
	fontName = ExRT.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.colsInit = {
	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.status_UnitsToCheck = {}
module.db.status_UnitIsDead = {}
module.db.status_UnitIsDisconnected = {}
module.db.status_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.status_UnitsToCheck,module.db.status_UnitIsDead,module.db.status_UnitIsDisconnected,module.db.status_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()
		VExRT.ExCD2.Left = self:GetLeft()
		VExRT.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))
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 VExRT.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 = data.specialStatus()
		if var2 then
			if var1 then
				isCooldown = true
				lastUse = var2
				t = var2 + var3
			else
				isCooldown = false
				t = nil				
			end
		end
	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 = ExRT.F.chatType(true)
	SendChatMessage(text,chat_type)
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.colsDefaults.textureFile
	local isValidTexture = self.background:SetTexture(textureFile)
	if not isValidTexture then
		textureFile = module.db.colsDefaults.textureFile
		self.background:SetTexture(textureFile)
	end
	self.timeline:SetTexture(textureFile)
	
	local isValidFont = nil
	
	isValidFont = self.textLeft:SetFont(parent.fontLeftName,parent.fontLeftSize,parent.fontLeftOutline and "OUTLINE")	if not isValidFont then self.textLeft:SetFont(module.db.colsDefaults.fontName,parent.fontLeftSize,parent.fontLeftOutline and "OUTLINE") end
	isValidFont = self.textRight:SetFont(parent.fontRightName,parent.fontRightSize,parent.fontRightOutline and "OUTLINE")	if not isValidFont then self.textRight:SetFont(module.db.colsDefaults.fontName,parent.fontRightSize,parent.fontRightOutline and "OUTLINE") end
	isValidFont = self.textCenter:SetFont(parent.fontCenterName,parent.fontCenterSize,parent.fontCenterOutline and "OUTLINE")if not isValidFont then self.textCenter:SetFont(module.db.colsDefaults.fontName,parent.fontCenterSize,parent.fontCenterOutline and "OUTLINE") end
	isValidFont = self.textIcon:SetFont(parent.fontIconName,parent.fontIconSize,parent.fontIconOutline and "OUTLINE")	if not isValidFont then self.textIcon:SetFont(module.db.colsDefaults.fontName,parent.fontIconSize,parent.fontIconOutline and "OUTLINE") end
	
	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.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 then
		self.clickFrame:SetScript("OnClick",LineIconOnClick)
		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.plugin and type(module.db.plugin.UpdateBarStyle)=="function" then
		module.db.plugin.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")
	self.cooldown = cooldown
	
	local background = self:CreateTexture(nil, "BACKGROUND", nil, -7)
	background:SetAllPoints()
	self.background = background
	
	self.textLeft = ELib:Text(self.statusbar,nil,nil,"GameFontNormal"):Size(0,0):Point(1,0):Color()
	self.textRight = ELib:Text(self.statusbar,nil,nil,"GameFontNormal"):Size(40,0):Point("TOPRIGHT",1,0):Right():Color()
	self.textCenter = ELib:Text(self.statusbar,nil,nil,"GameFontNormal"):Size(0,0):Point(0,0):Center():Color()
	self.textIcon = ELib:Text(icon,nil,nil,"GameFontNormal"):Size(0,0):Point(0,0):Center():Bottom():Color()
	
	--[[
	self.textLeft = self.statusbar:CreateFontString(nil,"ARTWORK")
	self.textLeft:SetJustifyH("LEFT")
	self.textLeft:SetJustifyV("MIDDLE")
	self.textLeft:SetSize(0,0)
	self.textLeft:SetPoint("TOPLEFT",1,0)
	self.textLeft:SetFont(ExRT.F.defFont,12)
	self.textLeft:SetTextColor(1,1,1,1)
	
	self.textRight = self.statusbar:CreateFontString(nil,"ARTWORK")
	self.textRight:SetJustifyH("RIGHT")
	self.textRight:SetJustifyV("MIDDLE")
	self.textRight:SetSize(40,0)
	self.textRight:SetPoint("TOPRIGHT",1,0)
	self.textRight:SetFont(ExRT.F.defFont,12)
	self.textRight:SetTextColor(1,1,1,1)
	
	self.textCenter = self.statusbar:CreateFontString(nil,"ARTWORK")
	self.textCenter:SetJustifyH("CENTER")
	self.textCenter:SetJustifyV("MIDDLE")
	self.textCenter:SetSize(0,0)
	self.textCenter:SetPoint("TOPLEFT",1,0)
	self.textCenter:SetFont(ExRT.F.defFont,12)
	self.textCenter:SetTextColor(1,1,1,1)
	
	self.textIcon = icon:CreateFontString(nil,"ARTWORK")
	self.textIcon:SetJustifyH("CENTER")
	self.textIcon:SetJustifyV("BOTTOM")
	self.textIcon:SetSize(0,0)
	self.textIcon:SetPoint("TOPLEFT",1,0)
	self.textIcon:SetFont(ExRT.F.defFont,12)
	self.textIcon:SetTextColor(1,1,1,1)
	]]
	
	--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

for i=1,module.db.maxColumns 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()
		VExRT.ExCD2.colSet[i].posX = self:GetLeft()
		VExRT.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)
end

do
	local isInCombat = false
	local isInEncounter = false
	function module:updateCombatVisibility()
		local _, zoneType = GetInstanceInfo()
		local inRaid = IsInRaid()
		for i=1,module.db.maxColumns 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 VExRT.ExCD2.SplitOpt then
			if VExRT.ExCD2.colSet[module.db.maxColumns+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.testMode then 
			return 
		end
		wipe(VExRT.ExCD2.Save)
		for i=1,#_C do
			local unitSpellData = _C[i]
			if unitSpellData.lastUse + unitSpellData.cd - currTime > 0 then
				VExRT.ExCD2.Save[ (unitSpellData.fullName or "?")..(unitSpellData.db[1] or 0) ] = {unitSpellData.lastUse,unitSpellData.cd}
			else
				VExRT.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.specInDBase[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.spell_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 (not module.db.spell_afterCombatNotReset[unitSpellData.db[1]] or 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.specInDBase[VExRT.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.maxColumns
	local maxLinesInCol = _db.maxLinesInCol
	local specInDBase = _db.specInDBase
	local spell_isTalent = _db.spell_isTalent
	local session_gGUIDs = _db.session_gGUIDs
	local spell_isPetAbility = _db.spell_isPetAbility
	local session_Pets = _db.session_Pets
	local petsAbilities = _db.petsAbilities
	local spell_talentReplaceOther = _db.spell_talentReplaceOther
	local spell_charge_fix = _db.spell_charge_fix
	local def_col = _db.def_col
	local columnsTable = _mainFrame.colFrame
	
	local playerName = ExRT.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_b(a,b) return (a.sorting or 0) < (b.sorting or 0) 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()
		local SortByAvailability = VExRT.ExCD2.SortByAvailability
		if SortByAvailability then
			local currTime = GetTime()
			local SortByAvailabilityActiveToTop = VExRT.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 VExRT.ExCD2.ReverseSorting then
		  		sort(_C,sort_b)
		  	else
		  		sort(_C,sort_br)
		  	end
		else
		  	if not VExRT.ExCD2.ReverseSorting then
		  		sort(_C,sort_a)
		  	else
		  		sort(_C,sort_ar)
		  	end
		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.testMode
		local CDECol = VExRT.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 (VExRT_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_isPetAbility[spellID] or session_Pets[name] == spell_isPetAbility[spellID] or (session_Pets[name] and petsAbilities[ session_Pets[name] ] and petsAbilities[ session_Pets[name] ][1] == spell_isPetAbility[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 = VExRT.ExCD2.CDECol[db[unitSpecID][1]..";"..(unitSpecID-2)] or def_col[db[unitSpecID][1]..";"..(unitSpecID-2)] or 1
				elseif db[3] then
					col = VExRT.ExCD2.CDECol[db[3][1]..";1"] or def_col[db[3][1]..";1"] or 1
				end
				data.column = col
				
				local isCharge = spell_charge_fix[ spellID ]
				if isCharge then
					if session_gGUIDs[data.fullName][isCharge] then
						data.isCharge = true
						isCharge = true
					else
						data.isCharge = nil
						isCharge = nil
					end
				end
				
				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
	
	local statusTimer1,statusTimer2 = 0,0
	
	function module:timer(elapsed)
		local forceUpdateAllData,forceSortAllData = false,false

		if not _db.isEncounter and IsEncounterInProgress() then
			_db.isEncounter = true
			local _,_,difficulty = GetInstanceInfo()
			if difficulty == 14 or difficulty == 15 or difficulty == 16 or difficulty == 17 or difficulty == 7 then
				_db.isResurectDisabled = true
			end
			module:toggleCombatVisibility(true,1)
		elseif _db.isEncounter and not IsEncounterInProgress() then
			_db.isEncounter = nil
			_db.isResurectDisabled = nil
			if GetDifficultyForCooldownReset() 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.spell_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
					
					if charges and lastBattleResChargesStatus and charges < lastBattleResChargesStatus then		--Add resurrect to history
						module.db.historyUsage[#module.db.historyUsage + 1] = {time(),20484,"*",GetEncounterTime()}
					end
				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 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
		
		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.testMode then
		return 20
	elseif n == 0 and VExRT.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 VExRT.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.testMode then
		local _,race = UnitRace(name or "?")
		return name,subgroup,classFileName,level,race,online,isDead
	elseif module.db.testMode 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(VExRT.ExCD2.gnGUIDs) do
			namesList[#namesList+1] = {unitName}
			for className, classSpecs in pairs(module.db.specByClass) do
				if ExRT.F.table_find(module.db.classNames,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.classNames[i]]..tostring(j)
			classFileName = module.db.classNames[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

local function UpdateLegendaryRingState()
	isLegendaryRingInRaid_DD = nil
	isLegendaryRingInRaid_Tank = nil
	isLegendaryRingInRaid_Heal = nil
	
	local session_gGUIDs = module.db.session_gGUIDs
	
	local roster = {}
	for i=1,#_C do
		roster[ _C[i].name ] = true
	end
	for name,_ in pairs(roster) do
		if session_gGUIDs[name][187614] or session_gGUIDs[name][187615] or session_gGUIDs[name][187611] then
			isLegendaryRingInRaid_DD = true
		elseif session_gGUIDs[name][187613] then
			isLegendaryRingInRaid_Tank = true
		elseif session_gGUIDs[name][187612] then
			isLegendaryRingInRaid_Heal = true
		end		
	end
end

function RaidResurrectSpecialCheck()
	local _,_,difficulty = GetInstanceInfo()
	if difficulty == 14 or difficulty == 15 or difficulty == 16 or difficulty == 7 or difficulty == 17 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
		else
			return true,started,duration
		end
	end
end

local LegendaryRingSpecialCheck_DD,LegendaryRingSpecialCheck_Tank,LegendaryRingSpecialCheck_Heal

function LegendaryRingSpecialCheck_DD() return isLegendaryRingInRaid_DD end
function LegendaryRingSpecialCheck_Tank() return isLegendaryRingInRaid_Tank end
function LegendaryRingSpecialCheck_Heal() return isLegendaryRingInRaid_Heal 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.testMode 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.spellDB) do
					local SpellID = spellData[1]
					local AddThisSpell = true
					if level < 100 then
						local spellLevel = GetSpellLevelLearned(SpellID)
						if level < (spellLevel or 0) then
							AddThisSpell = false
						end
					end
					if module.db.spell_isRacial[ SpellID ] and race ~= module.db.spell_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 ExRT.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.specInDBase[_specID] or 3
						if spellData[uSpecID] then
							spellColumn = VExRT.ExCD2.CDECol[spellData[uSpecID][1]..";"..(uSpecID-2)] or _db.def_col[spellData[uSpecID][1]..";"..(uSpecID-2)] or 1
						elseif spellData[3] then
							spellColumn = VExRT.ExCD2.CDECol[spellData[3][1]..";1"] or _db.def_col[spellData[3][1]..";1"] or 1
						end
						local getSpellColumn = _mainFrame.colFrame[spellColumn]
						local prior = nil
						--[[
							1: 00AABBBBBBCCDDDD
							2: 00AACCBBBBBBDDDD
							3: AAEEBBBBBBCCDDDD
							4: AAEECCBBBBBBDDDD
							5: 00CCAABBBBBBDDDD
							6: EEAACCBBBBBBDDDD
							
							A - priority
							B - spell ID
							C - name
							D - priority counter
							E - classID
						]]
						if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
							prior = (VExRT.ExCD2.Priority[SpellID] or 15) * 1000000000000 + (SpellID or 0) * 1000000 + (ExRT.F.table_find(priorNamesToNumber,name) or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 2 then
							prior = (VExRT.ExCD2.Priority[SpellID] or 15) * 1000000000000 + (ExRT.F.table_find(priorNamesToNumber,name) or 0) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 3 then
							prior = (VExRT.ExCD2.Priority[SpellID] or 15) * 100000000000000 + (ExRT.F.table_find(module.db.classNames,class) or 0) * 1000000000000 + (SpellID or 0) * 1000000 + (ExRT.F.table_find(priorNamesToNumber,name) or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 4 then
							prior = (VExRT.ExCD2.Priority[SpellID] or 15) * 100000000000000 + (ExRT.F.table_find(module.db.classNames,class) or 0) * 1000000000000 + (ExRT.F.table_find(priorNamesToNumber,name) or 0) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 5 then
							prior = (ExRT.F.table_find(priorNamesToNumber,name) or 0) * 1000000000000 + (VExRT.ExCD2.Priority[SpellID] or 15) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						elseif getSpellColumn.methodsSortingRules == 6 then
							prior = (ExRT.F.table_find(module.db.classNames,class) or 0) * 100000000000000 + (VExRT.ExCD2.Priority[SpellID] or 15) * 1000000000000 + (ExRT.F.table_find(priorNamesToNumber,name) or 0) * 10000000000 + (SpellID or 0) * 10000 + priorCounter
						end
						local secondPrior = (VExRT.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 VExRT.ExCD2.Save[sName] and NumberInRange(VExRT.ExCD2.Save[sName][1] + VExRT.ExCD2.Save[sName][2] - GetTime(),0,2000,false,true) then
							lastUse,nowCd = VExRT.ExCD2.Save[sName][1],VExRT.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)
						
						if module.db.differentIcons[SpellID] then
							spellTexture = module.db.differentIcons[SpellID]
						end
						
						for l=3,7 do
							if spellData[l] then
								local h = module.db.cdsNav[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.notAClass,
								sort = prior,
								sort2 = secondPrior,
								column = spellColumn,
							}
						end
					end
				end
				module.db.session_gGUIDs[name] = 1
				if isInRaid then
					module.main:UNIT_PET("raid"..j)
				end
			end
		end
		
		--WOD Raid resurrect
		do
			local findResSpell = ExRT.F.table_find(module.db.spellDB,161642,1)
			if findResSpell then
				local spellData = module.db.spellDB[findResSpell]
				local h = module.db.cdsNav["*"][spellData[3][1]]
				local prior = 0
				
				priorCounter = priorCounter + 1
				
				local spellColumn = VExRT.ExCD2.CDECol["161642;1"] or _db.def_col["161642;1"] or 1
				local getSpellColumn = _mainFrame.colFrame[spellColumn]
				if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
					prior = (VExRT.ExCD2.Priority[161642] or 15) * 1000000000000 + 161642 * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 2 then
					prior = (VExRT.ExCD2.Priority[161642] or 15) * 1000000000000 + 161642 * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 3 then
					prior = (VExRT.ExCD2.Priority[161642] or 15) * 100000000000000 + 161642 * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 4 then
					prior = (VExRT.ExCD2.Priority[161642] or 15) * 100000000000000 + 161642 * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 5 then
					prior = (VExRT.ExCD2.Priority[161642] or 15) * 10000000000 + 161642 * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 6 then
					prior = (VExRT.ExCD2.Priority[161642] or 15) * 1000000000000 + 161642 * 10000 + priorCounter
				end
				local secondPrior = (VExRT.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.notAClass,
						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.session_gGUIDs["*"] = 1
			end
		end
		--WOD Legendary Ring
		do
			local RingSpellID = 187614
			local findRingSpell = ExRT.F.table_find(module.db.spellDB,RingSpellID,1)
			if findRingSpell then
				local spellData = module.db.spellDB[findRingSpell]
				local h = module.db.cdsNav["*"][RingSpellID]
				local prior = 0
				priorCounter = priorCounter + 1
				local spellColumn = VExRT.ExCD2.CDECol[RingSpellID..";1"] or _db.def_col[RingSpellID..";1"] or 1
				local getSpellColumn = _mainFrame.colFrame[spellColumn]
				if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 2 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 3 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 100000000000000 + RingSpellID * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 4 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 100000000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 5 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 10000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 6 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 10000 + priorCounter
				end
				local secondPrior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000 + (RingSpellID or 0)
				
				if not h then
					local spellName,_,spellTexture = GetSpellInfo(RingSpellID)
					if module.db.differentIcons[RingSpellID] then
						spellTexture = module.db.differentIcons[RingSpellID]
					end
					_C [#_C + 1] = {
						name = "Legendary DD",
						fullName = "*",
						loweredName = "*",
						icon = spellTexture,
						spellName = spellName or "unk",
						db = spellData,
						lastUse = 0,
						cd = 0,
						duration = 0,
						classColor = module.db.notAClass,
						sort = prior,
						sort2 = secondPrior,
						column = spellColumn,
						specialCheck = LegendaryRingSpecialCheck_DD,
					}
				else
					h.sort = prior
					h.sort2 = secondPrior
					h.column = spellColumn
				end
				module.db.session_gGUIDs["*"] = 1
			end
			
			local RingSpellID = 187613
			local findRingSpell = ExRT.F.table_find(module.db.spellDB,RingSpellID,1)
			if findRingSpell then
				local spellData = module.db.spellDB[findRingSpell]
				local h = module.db.cdsNav["*"][RingSpellID]
				local prior = 0
				priorCounter = priorCounter + 1
				local spellColumn = VExRT.ExCD2.CDECol[RingSpellID..";1"] or _db.def_col[RingSpellID..";1"] or 1
				local getSpellColumn = _mainFrame.colFrame[spellColumn]
				if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 2 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 3 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 100000000000000 + RingSpellID * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 4 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 100000000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 5 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 10000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 6 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 10000 + priorCounter
				end
				local secondPrior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000 + (RingSpellID or 0)
				
				if not h then
					local spellName,_,spellTexture = GetSpellInfo(RingSpellID)
					if module.db.differentIcons[RingSpellID] then
						spellTexture = module.db.differentIcons[RingSpellID]
					end
					_C [#_C + 1] = {
						name = "Legendary Tank",
						fullName = "*",
						loweredName = "*",
						icon = spellTexture,
						spellName = spellName or "unk",
						db = spellData,
						lastUse = 0,
						cd = 0,
						duration = 0,
						classColor = module.db.notAClass,
						sort = prior,
						sort2 = secondPrior,
						column = spellColumn,
						specialCheck = LegendaryRingSpecialCheck_Tank,
					}
				else
					h.sort = prior
					h.sort2 = secondPrior
					h.column = spellColumn
				end
				module.db.session_gGUIDs["*"] = 1
			end
			
			local RingSpellID = 187612
			local findRingSpell = ExRT.F.table_find(module.db.spellDB,RingSpellID,1)
			if findRingSpell then
				local spellData = module.db.spellDB[findRingSpell]
				local h = module.db.cdsNav["*"][RingSpellID]
				local prior = 0
				priorCounter = priorCounter + 1
				local spellColumn = VExRT.ExCD2.CDECol[RingSpellID..";1"] or _db.def_col[RingSpellID..";1"] or 1
				local getSpellColumn = _mainFrame.colFrame[spellColumn]
				if not getSpellColumn or getSpellColumn.methodsSortingRules == 1 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 2 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 3 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 100000000000000 + RingSpellID * 1000000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 4 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 100000000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 5 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 10000000000 + RingSpellID * 10000 + priorCounter
				elseif getSpellColumn.methodsSortingRules == 6 then
					prior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000000000 + RingSpellID * 10000 + priorCounter
				end
				local secondPrior = (VExRT.ExCD2.Priority[RingSpellID] or 15) * 1000000 + (RingSpellID or 0)
				
				if not h then
					local spellName,_,spellTexture = GetSpellInfo(RingSpellID)
					if module.db.differentIcons[RingSpellID] then
						spellTexture = module.db.differentIcons[RingSpellID]
					end
					_C [#_C + 1] = {
						name = "Legendary Heal",
						fullName = "*",
						loweredName = "*",
						icon = spellTexture,
						spellName = spellName or "unk",
						db = spellData,
						lastUse = 0,
						cd = 0,
						duration = 0,
						classColor = module.db.notAClass,
						sort = prior,
						sort2 = secondPrior,
						column = spellColumn,
						specialCheck = LegendaryRingSpecialCheck_Heal,
					}
				else
					h.sort = prior
					h.sort2 = secondPrior
					h.column = spellColumn
				end
				module.db.session_gGUIDs["*"] = 1
			end
		end
		
		
		cdsNav_wipe()

		local pluginFunc = module.db.plugin and type(module.db.plugin.UpdateRoster)=="function" and module.db.plugin.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.testMode 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
	UpdateLegendaryRingState()
	UpdateAllData()
	SortAllData()
end

local GetArtifactTraitsKnown
do
	local function DispellSchedule(data)
		if not module.db.spell_dispellsFix[ data.fullName ] then
			data.cd = 0
		end
		module.db.spell_dispellsFix[ data.fullName ] = nil
	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.specInDBase[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.spell_battleRes[spellID] and _db.isResurectDisabled then
				return
			end
		end
		
		data.cd = data.db[uSpecID][2]
		data.duration = data.db[uSpecID][3]
		
		--Talents / Glyphs
		local durationTable = module.db.spell_durationByTalent_fix[spellID]
		if durationTable then
			for j=1,#durationTable,2 do
				if module.db.session_gGUIDs[fullName][ durationTable[j] ] then
					local timeReduce = durationTable[j+1]
					if type(timeReduce) == 'table' then
						local traits = GetArtifactTraitsKnown(fullName,durationTable[j])
						if traits > 0 then
							data.duration = data.duration + timeReduce[traits]
						end
					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.spell_cdByTalent_fix[spellID]
		if cdTable then
			for j=1,#cdTable,2 do
				if module.db.session_gGUIDs[fullName][ cdTable[j] ] then
					local timeReduce = cdTable[j+1]
					if type(timeReduce) == 'table' then
						local traits = GetArtifactTraitsKnown(fullName,cdTable[j])
						if traits > 0 then
							data.cd = data.cd + timeReduce[traits]
						end
					elseif 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
		local isCharge = module.db.spell_charge_fix[ data.db[1] ]
		if isCharge and (data.lastUse+data.cd) >= currTime then
			data.charge = (data.charge or data.lastUse) + data.cd
			data.lastUse = currTime
			module.db.session_gGUIDs[fullName] = isCharge
		elseif isCharge and module.db.session_gGUIDs[fullName][isCharge] then
			data.charge = currTime
			data.lastUse = currTime
		else
			data.lastUse = currTime
		end
		--Haste/Readiness
		if module.db.spell_speed_list[spellID] then
			data.duration = data.duration / (1 + (UnitSpellHaste(fullName) or 0) /100)
		end
		if module.db.spell_reduceCdByHaste[spellID] then
			data.cd = data.cd / (1 + (UnitSpellHaste(fullName) or 0) /100) 
		end
		--Dispels
		if module.db.spell_dispellsList[spellID] then
			ScheduleTimer(DispellSchedule, 0.5, data)
		end
		-- 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()
		
		module.db.historyUsage[#module.db.historyUsage + 1] = {time(),data.db[uSpecID][1],fullName,GetEncounterTime()}
	end
end

function module:Enable()
	VExRT.ExCD2.enabled = true
	if not VExRT.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','UNIT_PET','PLAYER_LOGOUT','ZONE_CHANGED_NEW_AREA','CHALLENGE_MODE_RESET','PLAYER_REGEN_DISABLED','PLAYER_REGEN_ENABLED')

	UpdateRoster()
end

function module:Disable()
	VExRT.ExCD2.enabled = nil
	if not VExRT.ExCD2.SplitOpt then 
		module.frame:Hide()
	else
		for i=1,module.db.maxColumns 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','UNIT_PET','PLAYER_LOGOUT','ZONE_CHANGED_NEW_AREA','CHALLENGE_MODE_RESET','PLAYER_REGEN_DISABLED','PLAYER_REGEN_ENABLED')
end

function module.main:ADDON_LOADED()
	VExRT = _G.VExRT
	VExRT.ExCD2 = VExRT.ExCD2 or {NoRaid = true}
	
	if VExRT.Addon.Version < 2126 then
		if VExRT.ExCD2.colSet then
			for i=1,module.db.maxColumns+1 do
				if VExRT.ExCD2.colSet[i] and not VExRT.ExCD2.colSet[i].fontOutline then
					VExRT.ExCD2.colSet[i].fontShadow = true
				end
			end
		end
	end
	if VExRT.Addon.Version < 2302 then
		if VExRT.ExCD2.colSet then
			for i=1,module.db.maxColumns+1 do
				if VExRT.ExCD2.colSet[i] then
					VExRT.ExCD2.colSet[i].textGeneral = true
				end
			end
		end
	end
	if VExRT.Addon.Version < 3247 then
		if VExRT.ExCD2.colSet then
			for i=1,module.db.maxColumns+1 do
				if VExRT.ExCD2.colSet[i] then
					VExRT.ExCD2.colSet[i].blacklistGeneral = true
				end
			end
		end
	end
	if VExRT.Addon.Version < 3755 then
		if VExRT.ExCD2.colSet then
			for i=1,module.db.maxColumns+1 do
				if VExRT.ExCD2.colSet[i] then
					VExRT.ExCD2.colSet[i].visibilityGeneral = true
				end
			end
		end
	end	
	
	if VExRT.ExCD2.Left and VExRT.ExCD2.Top then
		module.frame:ClearAllPoints()
		module.frame:SetPoint("TOPLEFT",UIParent,"BOTTOMLEFT",VExRT.ExCD2.Left,VExRT.ExCD2.Top)
	end
	
	VExRT.ExCD2.CDE = VExRT.ExCD2.CDE or {}
	VExRT.ExCD2.CDECol = VExRT.ExCD2.CDECol or {}
	if UnitFactionGroup("player") == "Alliance" then	--> BL Faction Fix
		for i,spellData in ipairs(module.db.spellDB) do
			if spellData[1] == 2825 then
				spellData[1] = 32182
				spellData[3][1] = 32182
				break
			end
		end
	end
	VExRT_CDE = VExRT.ExCD2.CDE
	
	if not VExRT.ExCD2.colSet then
		VExRT.ExCD2.colSet = {}
		for i=1,module.db.maxColumns+1 do
			VExRT.ExCD2.colSet[i] = {}
			for optName,optVal in pairs(module.db.colsInit) do
				VExRT.ExCD2.colSet[i][optName] = optVal
			end
			if i <= 3 then 
				VExRT.ExCD2.colSet[i].enabled = true
			end
		end
	end
	for i=1,module.db.maxColumns+1 do
		VExRT.ExCD2.colSet[i] = VExRT.ExCD2.colSet[i] or {}
	end
	
	VExRT.ExCD2.default_userCD = VExRT.ExCD2.default_userCD or {}
	VExRT.ExCD2.default_userDuration = VExRT.ExCD2.default_userDuration or {}
	do
		for spellID,spellData in pairs(VExRT.ExCD2.default_userCD) do
			for i=1,#module.db.spellDB do
				if module.db.spellDB[i][1] == spellID then
					for j=1,5 do
						if spellData[j] and module.db.spellDB[i][2+j] then
							if spellData[j] == module.db.spellDB[i][2+j][2] then
								spellData[j] = nil
							else
								module.db.spellDB[i][2+j][2] = spellData[j]
							end
						end
					end
				end
			end
		end
	
		for spellID,spellData in pairs(VExRT.ExCD2.default_userDuration) do
			for i=1,#module.db.spellDB do
				if module.db.spellDB[i][1] == spellID then
					for j=1,5 do
						if spellData[j] and module.db.spellDB[i][2+j] then
							if spellData[j] == module.db.spellDB[i][2+j][3] then
								spellData[j] = nil
							else
								module.db.spellDB[i][2+j][3] = spellData[j]
							end
						end
					end
				end
			end
		end
	end
	
	VExRT.ExCD2.userDB = VExRT.ExCD2.userDB or {}
	for i=1,#VExRT.ExCD2.userDB do
		module.db.spellDB[i+module.db.dbCountDef] = VExRT.ExCD2.userDB[i]
	end

	VExRT.ExCD2.Priority = VExRT.ExCD2.Priority or {}

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

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

	if not VExRT.ExCD2.enabled then
		if not VExRT.ExCD2.SplitOpt then 
			module.frame:Hide() 
		else
			for i=1,module.db.maxColumns 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.playerName = ExRT.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:UNIT_PET(arg)
	local name = UnitCombatlogname(arg)
	if name then
		local forceUpdateAllData = nil
		local petNow = UnitCreatureFamily(arg.."pet")
		if petNow ~= _db.session_Pets[name] then
			_db.session_Pets[name] = UnitCreatureFamily(arg.."pet")
			forceUpdateAllData = true
		end
		if _db.session_Pets[name] then
			_db.session_PetOwner[UnitGUID(arg.."pet")] = name
		end
		if forceUpdateAllData then
			UpdateAllData()
		end
	end
end

do
	local eventsView = nil
	--upvaules
	local spell_startCDbyAuraApplied = _db.spell_startCDbyAuraApplied
	local spell_reduceCdByAuraFade = _db.spell_reduceCdByAuraFade
	local spell_aura_list = _db.spell_aura_list
	local spell_startCDbyAuraFade = _db.spell_startCDbyAuraFade
	local spell_startCDbyAuraApplied_fix = _db.spell_startCDbyAuraApplied_fix
	local spell_isPetAbility = _db.spell_isPetAbility
	local spell_isTalent = _db.spell_isTalent
	local spell_resetOtherSpells = _db.spell_resetOtherSpells
	local spell_sharingCD = _db.spell_sharingCD
	local spell_reduceCdCast = _db.spell_reduceCdCast
	local spell_increaseDurationCast = _db.spell_increaseDurationCast
	local spell_runningSameSpell = _db.spell_runningSameSpell
	local spell_dispellsList = _db.spell_dispellsList
	
	local findspecspells = _db.findspecspells

	local session_gGUIDs = _db.session_gGUIDs
	local session_PetOwner = _db.session_PetOwner
	local CDList = _db.cdsNav
	
	function module.main:COMBAT_LOG_EVENT_UNFILTERED(_,_,event,_,sourceGUID,sourceName,sourceFlags,_,destGUID,destName,destFlags,_,spellID,_,_,_,_,_,_,_,_,critical)
		--dtime()
		local func = eventsView[event]
		if func then
			func(self,sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID,critical)
		end
		--dtime(ExRT.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
	
		local modifData = spell_reduceCdByAuraFade[spellID]
		if modifData then
			local CDspellID = modifData[1]
			if type(CDspellID) ~= "table" then
				local line = CDList[sourceName][CDspellID]
				if line and (GetTime() - line.lastUse - line.duration) > -0.5 then
					line.cd = line.cd + modifData[2]
					if line.bar and line.bar.data == line then
						line.bar:UpdateStatus()
					end
					forceSortAllData = true
				end
			else
				if session_gGUIDs[sourceName][ CDspellID[2] ] then
					local line = CDList[sourceName][ CDspellID[1] ]
					if line and (GetTime() - line.lastUse - line.duration) > -0.5 then
						line.cd = line.cd + modifData[2]
						if line.bar and line.bar.data == line then
							line.bar:UpdateStatus()
						end
						forceSortAllData = true
					end
				end
			end
		end
	
		local CDspellID = spell_aura_list[spellID]
		if CDspellID then
			local line = CDList[sourceName][ CDspellID ]
			if line then
				line.duration = 0
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				forceSortAllData = true
			end
		end
		
		if spell_startCDbyAuraFade[spellID] then
			local line = CDList[sourceName][spellID]
			if line then
				CLEUstartCD(line)
			end
		end
		
		if spellID == 195181 then
			local line = CDList[sourceName][221699]
			if line then
				line.lastUse = line.lastUse - 1
				if line.charge then
					line.charge = line.charge - 1
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif 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()
					end
				end
			end
		end
		
		if forceSortAllData then
			SortAllData()
		end
	end
	function module.main:SPELL_AURA_REMOVED_DOSE(sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID)
		if not sourceName then
			return
		end
		if spellID == 195181 then
			local line = CDList[sourceName][221699]
			if line then
				line.lastUse = line.lastUse - 1
				if line.charge then
					line.charge = line.charge - 1
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		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_isPetAbility[spellID] then
			sourceName = session_PetOwner[sourceGUID] or sourceName
		end
		
		if spellID == 187614 or spellID == 187615 or spellID == 187611 or spellID == 187613 or spellID == 187612 then
			if not UnitName(sourceName) then	--Not in Raid or Party
				return
			end
			if not session_gGUIDs[sourceName][spellID] then
				session_gGUIDs[sourceName] = spellID
				UpdateLegendaryRingState()
			end
			sourceName = "*"
		end
	 
		local findSpecSpell = findspecspells[spellID]
		if findSpecSpell and (GetUnitInfoByUnitFlag(sourceFlags,4) % 8) > 0 then
			if globalGUIDs[sourceName] ~= findSpecSpell then
				forceUpdateAllData = true
			end
			globalGUIDs[sourceName] = findSpecSpell
		end
		
		if spell_startCDbyAuraFade[spellID] or 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
			end
			session_gGUIDs[sourceName] = spellID
		end
		
		local modifData = spell_resetOtherSpells[spellID]
		if modifData then
			for i=1,#modifData do
				local resetSpellID = modifData[i]
				if type(resetSpellID)~='table' or session_gGUIDs[sourceName][ resetSpellID[2] ] then
					resetSpellID = type(resetSpellID)=='table' and resetSpellID[1] or resetSpellID
					local line = CDList[sourceName][ resetSpellID ]
					if line then
						line.cd = 0
						if line.bar and line.bar.data == line then
							line.bar:UpdateStatus()
						end
						forceUpdateAllData = true
						forceSortAllData = true
					end
				end
			end
		end
		
		local modifData = spell_sharingCD[spellID]
		if modifData then
			local nowTime = GetTime()
			for sharingSpellID,timeCD in pairs(modifData) do
				local line = CDList[sourceName][sharingSpellID]
				if line then
					local cd_timer_now = line.lastUse + line.cd - nowTime
					if (cd_timer_now > 0 and cd_timer_now < timeCD) or (nowTime - line.lastUse) > line.cd then
						line.cd = timeCD
						line.lastUse = nowTime
						line.duration = 0
						if line.bar and line.bar.data == line then
							line.bar:UpdateStatus()
						end
						forceUpdateAllData = true
						forceSortAllData = true
					end
				end
			end
		end
		
		local modifData = spell_reduceCdCast[spellID]
		if modifData then
			for i=1,#modifData,2 do
				local reduceSpellID = modifData[i]
				if type(reduceSpellID) ~= "table" then
					local line = CDList[sourceName][reduceSpellID]
					if line then
						line.cd = line.cd + modifData[i+1]
						if line.cd < 0 then 
							line.cd = 0 
						end
						if line.bar and line.bar.data == line then
							line.bar:UpdateStatus()
						end
						forceUpdateAllData = true
						forceSortAllData = true
					end
				else
					local specReduceCD = reduceSpellID[3]
					local effectOnlyDuringBuffActive = reduceSpellID[4]
					if session_gGUIDs[sourceName][ reduceSpellID[2] ] and (not specReduceCD or (specReduceCD < 0 and globalGUIDs[sourceName] ~= specReduceCD or globalGUIDs[sourceName] == specReduceCD)) and (not effectOnlyDuringBuffActive or UnitAura(sourceName,GetSpellInfo(effectOnlyDuringBuffActive),nil,"HELPFUL")) then
						local line = CDList[sourceName][ reduceSpellID[1] ]
						if line then
							line.cd = line.cd + modifData[i+1]
							if line.cd < 0 then 
								line.cd = 0 
							end
							if line.bar and line.bar.data == line then
								line.bar:UpdateStatus()
							end
							forceUpdateAllData = true
							forceSortAllData = true
						end
					end
				end
			end
		end
		
		local modifData = spell_increaseDurationCast[spellID]
		if modifData then
			for i=1,#modifData,2 do
				local increaseSpellID = modifData[i]
				if type(increaseSpellID) ~= "table" then
					local line = CDList[sourceName][increaseSpellID]
					if line and (GetTime() - line.lastUse) < line.duration  then
						line.duration = line.duration + modifData[i+1]
						if line.duration < 0 then 
							line.duration = 0 
						end
						if line.bar and line.bar.data == line then
							line.bar:UpdateStatus()
						end
						forceUpdateAllData = true
						forceSortAllData = true
					end
				else
					if session_gGUIDs[sourceName][ increaseSpellID[2] ] then
						local line = CDList[sourceName][ increaseSpellID[1] ]
						if line and (GetTime() - line.lastUse) < line.duration  then
							line.duration = line.duration + modifData[i+1]
							if line.duration < 0 then 
								line.duration = 0 
							end
							if line.bar and line.bar.data == line then
								line.bar:UpdateStatus()
							end
							forceUpdateAllData = true
							forceSortAllData = true
						end
					end
				end
			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
	function module.main:SPELL_DISPEL(sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID)
		if spell_dispellsList[spellID] and sourceName then
			_db.spell_dispellsFix[ sourceName ] = true
		end
	end
	
	local spellDamage_trackedSpells = {
		[46968] = true,
		[100130] = true,
		[11366] = true,
		[133] = true,
		[108853] = true,
		[222024] = true,
		[66198] = true,
		[222026] = true,
		[66196] = true,
		[31935] = true,
		[6343] = true,
		[116] = true,
		[115181] = true,
		[198013] = true,
		[178740] = true,
	}
	local spellDamage_trackedSpells_Register = {
		[46968] = true,
		[100130] = true,
		[190319] = true,
		[51271] = true,
		[86659] = true,
		[1160] = true,
		[12472] = true,
		[115203] = true,
		[198013] = true,
		[204021] = true,
	}	
	local spell46968_var = {}
	local spell115181_var = {0,0}
	function module.main:SPELL_DAMAGE(sourceGUID,sourceName,sourceFlags,destGUID,destName,destFlags,spellID,critical)
		if not spellDamage_trackedSpells[spellID] or not sourceName then
			return
		elseif spellID == 100130 and critical and session_gGUIDs[sourceName][185799] then
			local line = CDList[sourceName][1719]
			if line then
				line.cd = line.cd - 10
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif spellID == 46968 then
			local sourceData = spell46968_var[sourceName]
			if not sourceData then
				sourceData = {0,0}
				spell46968_var[sourceName] = sourceData
			end
			local t=GetTime()
			if (t - sourceData[1]) > 2 then
				sourceData[1] = t
				sourceData[2] = 0
			end
			sourceData[2] = sourceData[2] + 1
			if sourceData[2] == 3 then
				local line = CDList[sourceName][46968]
				if line then
					line.cd = line.cd - 20
					if line.cd < 0 then 
						line.cd = 0 
					end
					if line.bar and line.bar.data == line then
						line.bar:UpdateStatus()
					end
					UpdateAllData()
					SortAllData()
				end
			end
		elseif (spellID == 11366 or spellID == 133 or spellID == 108853) and critical and session_gGUIDs[sourceName][155148] then
			local line = CDList[sourceName][190319]
			if line then
				line.cd = line.cd - 1
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif (spellID == 222024 or spellID == 66198 or spellID == 222026 or spellID == 66196) and critical and session_gGUIDs[sourceName][207126] then
			local line = CDList[sourceName][51271]
			if line then
				line.cd = line.cd - 1
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif spellID == 31935 and session_gGUIDs[sourceName][207628] then
			local line = CDList[sourceName][86659]
			if line then
				line.cd = line.cd - 3
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif spellID == 6343 and session_gGUIDs[sourceName][215176] then
			local line = CDList[sourceName][1160]
			if line then
				line.cd = line.cd - 1
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif spellID == 116 and critical and session_gGUIDs[sourceName][195345] then
			local traits = GetArtifactTraitsKnown(sourceName, 195345)
			if traits > 0 then
				local line = CDList[sourceName][12472]
				if line then
					line.cd = line.cd - (traits * 0.5)
					if line.cd < 0 then 
						line.cd = 0 
					end
					if line.bar and line.bar.data == line then
						line.bar:UpdateStatus()
					end
					UpdateAllData()
					SortAllData()
				end
			end
		elseif spellID == 115181 and session_gGUIDs[sourceName][224489] then
			local line = CDList[sourceName][115203]
			if line then
				local t = GetTime()
				if (t - spell115181_var[2]) > 1.5 then
					spell115181_var[1] = 0
					spell115181_var[2] = t
				end
				spell115181_var[1] = spell115181_var[1] + 1
				if spell115181_var[1] > 4 then
					return
				end
			
				line.cd = line.cd - 1
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end
		elseif spellID == 198013 and critical and session_gGUIDs[sourceName][215149] then
			local line = CDList[sourceName][198013]
			if line then
				line.cd = line.cd - 0.1
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end			
		elseif spellID == 178740 and session_gGUIDs[sourceName][210970] then
			local line = CDList[sourceName][204021]
			if line then
				line.cd = line.cd - 2
				if line.cd < 0 then 
					line.cd = 0 
				end
				if line.bar and line.bar.data == line then
					line.bar:UpdateStatus()
				end
				UpdateAllData()
				SortAllData()
			end			
		end
	end
	
	
	eventsView = {
		SPELL_AURA_REMOVED=module.main.SPELL_AURA_REMOVED,
		SPELL_AURA_REMOVED_DOSE=module.main.SPELL_AURA_REMOVED_DOSE,
		SPELL_AURA_APPLIED=module.main.SPELL_AURA_APPLIED,
		SPELL_CAST_SUCCESS=module.main.SPELL_CAST_SUCCESS,
		SPELL_DISPEL=module.main.SPELL_DISPEL,
		--SPELL_DAMAGE=module.main.SPELL_DAMAGE,
	}
	
	local isSpellDamageAdded = nil
	function module:AddCLEUSpellDamage(spellID)
		if isSpellDamageAdded or not spellDamage_trackedSpells_Register[spellID] then 
			return 
		end
		eventsView.SPELL_DAMAGE = module.main.SPELL_DAMAGE
		isSpellDamageAdded = true
	end
end

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

	loadstring(module.db.AllClassSpellsInText)()
	module.db.AllClassSpellsInText = nil

	local SPELL_LINE_HEIGHT = 32
	local SPELL_PER_PAGE = 17
	local SPELL_PAGE_HEIGHT = 528

	self.decorationLine = CreateFrame("Frame",nil,self)
	self.decorationLine.texture = self.decorationLine:CreateTexture(nil, "BACKGROUND", nil, -5)
	self.decorationLine:SetPoint("TOPLEFT",self,-8,-25)
	self.decorationLine:SetPoint("BOTTOMRIGHT",self,"TOPRIGHT",8,-45)
	self.decorationLine.texture:SetAllPoints()
	self.decorationLine.texture:SetColorTexture(1,1,1,1)
	self.decorationLine.texture:SetGradientAlpha("VERTICAL",.24,.25,.30,1,.27,.28,.33,1)
	
	self.chkEnable = ELib:Check(self,L.senable,VExRT.ExCD2.enabled):Point(560,-26):Size(18,18):OnClick(function(self) 
		if self:GetChecked() then
			module:Enable()
		else
			module:Disable()
		end
	end)
	
	self.chkLock = ELib:Check(self,L.cd2fix,VExRT.ExCD2.lock):Point(430,-26):Size(18,18):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.lock = true
			ExRT.F.LockMove(module.frame,nil,module.frame.texture)
			ExRT.lib.AddShadowComment(module.frame,1)
			if VExRT.ExCD2.SplitOpt then 
				for i=1,module.db.maxColumns do 
					ExRT.F.LockMove(module.frame.colFrame[i],nil,module.frame.colFrame[i].lockTexture)
					ExRT.lib.AddShadowComment(module.frame.colFrame[i],1)
				end 
			end
		else
			VExRT.ExCD2.lock = nil
			ExRT.F.LockMove(module.frame,true,module.frame.texture)
			ExRT.lib.AddShadowComment(module.frame,nil,L.cd2)
			if VExRT.ExCD2.SplitOpt then 
				for i=1,module.db.maxColumns do 
					ExRT.F.LockMove(module.frame.colFrame[i],true,module.frame.colFrame[i].lockTexture)
					ExRT.lib.AddShadowComment(module.frame.colFrame[i],nil,L.cd2,i,72,"OUTLINE")
				end 
			end
		end
	end)

	self.tab = ELib:Tabs(self,0,L.cd2Spells,L.cd2Appearance,L.cd2History):Point(0,-45):Size(660,570):SetTo(1)
	self.tab:SetBackdropBorderColor(0,0,0,0)
	self.tab:SetBackdropColor(0,0,0,0)
	
	local function fastSetupFrameListClick(self,spellsList)
		for k=1,#spellsList do
			local bool = nil
			for j=1,#module.db.spellDB do
				if module.db.spellDB[j][1] == spellsList[k] then
					bool = true
					break
				end
			end
			if not bool then
				for class,classData in pairs(module.db.allClassSpells) do
					for j=1,#classData do
						if classData[j][1] == spellsList[k] then
							module.options:addNewSpell(class,classData[j],true)
							bool = true
							break
						end
					end
					if bool then
						break
					end
				end
			end
		end
		for j=1,#spellsList do
			VExRT.ExCD2.CDE[ spellsList[j] ] = true
		end
		UpdateRoster()
		module.options:ReloadSpellsPage()
		ELib:DropDownClose()
	end
	local function fastSetupFrameListEnter(self,tooltip)
		ELib.Tooltip.Show(self,"ANCHOR_LEFT",unpack(tooltip))
	end
	local function fastSetupFrameListLeave(self)
		ELib.Tooltip:Hide()
	end
	local function fastSetupFrameListClick2(self)
		local list = {
			{L.cd2fastSetupTitle1,{31821,204150,62618,98008,97462,31842,64843,108280,740,115310,196718,207399}},					--Raid Save
			{L.cd2fastSetupTitle2,{102342,47788,33206,6940,633,116849,207810,1022,204018}},								--Direct Save
			{L.cd2fastSetupTitle3,{20484,20707,61999,20608,161642}},										--Battle Res
			{L.cd2fastSetupTitle4,{6552,96231,147362,1766,15487,47528,47476,57994,2139,116705,106839,19647,91802,115781,78675,183752,}},	--Kicks
			{L.cd2fastSetupTitle5,{114192,355,62124,56222,49576,115546,6795,185245,}},								--Taunts
			{L.cd2fastSetupTitle6,{4987,32375,527,51886,115450,2782,475,115276,89808}},							--Dispels			
		}
		for i=1,#list do
			local tooltip = {list[i][1]..":"}
			for j=1,#list[i][2] do
				local spellName,_,spellTexture = GetSpellInfo(list[i][2][j])
				if spellName then
					tooltip[#tooltip + 1] = "|T"..spellTexture..":0|t |cffffffff"..spellName.."|r"
				end
			end
			self.List[i] = {
				text = list[i][1],
				arg1 = list[i][2],
				func = fastSetupFrameListClick,
				hoverFunc = fastSetupFrameListEnter,
				leaveFunc = fastSetupFrameListLeave,
				hoverArg = tooltip,
				justifyH = "CENTER",
			}
		end
		self.OnClick = nil
	end
	self.fastSetupFrame = ELib:ListButton(self.tab.tabs[1],L.cd2fastSetupTitle..":",200,6):Size(18,18):Point("TOPRIGHT",-15,-9):Left():OnClick(fastSetupFrameListClick2)
	self.fastSetupFrame.text:FontSize(11):Color(GameFontNormal:GetTextColor())
	
	self.borderList = CreateFrame("Frame",nil,self.tab.tabs[1])
	self.borderList:SetSize(650,SPELL_PAGE_HEIGHT)
	self.borderList:SetPoint("TOP", 0, -38)
	ELib:Border(self.borderList,2,.24,.25,.30,1)
	
	local function SyncUserDB()
		table.wipe(VExRT.ExCD2.userDB)
		local j = 1
		for i=module.db.dbCountDef+1,#module.db.spellDB do
			VExRT.ExCD2.userDB[j] = module.db.spellDB[i]
			j = j + 1
		end
	end
	
	local function CheckToNil(self)
		self.chk:SetChecked(nil) 
		VExRT.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 = floor(scrollBarValue / SPELL_LINE_HEIGHT) + 1
		page.butSpellsAdd:Hide()
		page.butSpellsFrame:Hide()
		local lineNum,lastLine = 0
		for i=pos,pos+SPELL_PER_PAGE+1 do
			lineNum = lineNum + 1
			if not module.db.spellDB[i] then
				for j=lineNum,#page.spellsList do
					page.spellsList[j]:Hide()
				end
				page.butSpellsAdd:ClearAllPoints()
				page.butSpellsAdd:SetPoint("TOPLEFT",lastLine,"BOTTOMLEFT",5,-5)
				page.butSpellsAdd:Show()
				page.butSpellsFrame:ClearAllPoints()
				page.butSpellsFrame:SetPoint("TOPLEFT",lastLine,"BOTTOMLEFT",317,-5)
				page.butSpellsFrame:Show()
				break
			end
			local spellData = module.db.spellDB[i]
			local SpellID = spellData[1]
			local line = module.options.spellsList[lineNum]
			lastLine = line
		
			line.chk:SetChecked(VExRT.ExCD2.CDE[SpellID])
			local SpellName,_,SpellTexture = GetSpellInfo(SpellID)
			if module.db.differentIcons[ SpellID ] then
				SpellTexture = module.db.differentIcons[SpellID]
			end
			if SpellID == 187614 then SpellName = "Legendary DD" end
			if SpellID == 187612 then SpellName = "Legendary Heal" end
			if SpellID == 187613 then SpellName = "Legendary Tank" end
			
			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 = ExRT.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()

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

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

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

				line.userClass:SetText("|c"..ExRT.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()
		ELib.Tooltip:HideAdd()
		page.ScrollBar:UpdateButtons()
	end
	
	self.ScrollBar = ELib:ScrollBar(self.borderList):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.spellDB+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
			VExRT.ExCD2.CDE[self:GetParent().sid] = true
		else
			VExRT.ExCD2.CDE[self:GetParent().sid] = nil
		end
		UpdateRoster()
	end
	local function SpellsListOnUpdate(self)
		if MouseIsOver(self) and not ExRT.lib.ScrollDropDown.DropDownList[1]:IsShown() and not module.options.spellsModifyFrame: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)
		ELib.Tooltip.Link(self,self:GetParent().spellName:GetText())
		if self:GetParent().additionalTooltip then
			ELib.Tooltip:Add(nil,{self:GetParent().additionalTooltip})
		end
	end
	local function SpellsListTooltipFrameOnLeave()
		GameTooltip_Hide()
		ELib.Tooltip:HideAdd()
	end
	local SpellsListDropDownPriorityDataList = {}
	local function SpellsListDropDownPrioritySelectFunc(self,arg)
		local list = self:GetParent().parent
		list:SetText(arg)
		VExRT.ExCD2.Priority[list:GetParent().sid] = arg
		ELib:DropDownClose()
		UpdateRoster()
	end
	for i=1,30 do
		SpellsListDropDownPriorityDataList[i] = {text=i,justifyH="CENTER",arg1=i,func=SpellsListDropDownPrioritySelectFunc}
	end
	local function SpellsListDropDownPriorityOnEnter(self)
		ELib.Tooltip.Show(self,"ANCHOR_LEFT",L.cd2Priority,{L.cd2PriorityTooltip,1,1,1,true})
	end
	local function SpellsListButtonModifyOnClick(self)
		local spellsModifyFrame = module.options.spellsModifyFrame
		spellsModifyFrame:Hide()
		local parent = self:GetParent()
		spellsModifyFrame.sid = parent.sid
		spellsModifyFrame.tid = parent.tid
		spellsModifyFrame.class = module.db.spellDB[parent.tid][2]
		spellsModifyFrame:ShowClick("TOPRIGHT")
	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.spellDB do
				if module.db.spellDB[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.spellDB[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
				ELib.Tooltip.Link(self,format("|Hspell:%d|hspell|h",spellID))
			else
				ELib.Tooltip.Std(self)
			end
		else
			ELib.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.classNames[classNum]
		CheckToNil(parentLine)
		ELib:DropDownClose()
		parent:SetText("|c"..ExRT.F.classColor(class)..L.classLocalizate[ class ])
		module.db.spellDB[parentLine.tid][2] = class
		local cR,cG,cB = ExRT.F.classColorNum(class)
		parentLine.backClassColorR = cR
		parentLine.backClassColorG = cG
		parentLine.backClassColorB = cB
		SyncUserDB()
	end
	for i=1,#module.db.classNames do
		SpellsListClassDropDownList[#SpellsListClassDropDownList + 1] = {
			text = "|c"..ExRT.F.classColor(module.db.classNames[i])..L.classLocalizate[ module.db.classNames[i] ],
			justifyH = "CENTER",
			arg1 = i,
			func = SpellsListUserClassDropDownClick,
		}
	end
	SpellsListClassDropDownList[#SpellsListClassDropDownList + 1] = {
		text = "|c"..ExRT.F.classColor("ALL")..L.classLocalizate[ "ALL" ],
		justifyH = "CENTER",
		arg1 = 0,
		arg2 = true,
		func = SpellsListUserClassDropDownClick,
	}	
	
	local function SpellsListUserRemoveOnClick(self)
		local parentLine = self:GetParent()
		VExRT.ExCD2.CDE[parentLine.sid] = nil
		
		for j=3,7 do
			if type(module.db.spellDB[parentLine.tid][j])=="table" then
				VExRT.ExCD2.CDECol[module.db.spellDB[parentLine.tid][j][1]..";"..(j-2)] = nil
			end
		end
		
		for j = parentLine.tid + 1,#module.db.spellDB do
			module.db.spellDB[j-1] = module.db.spellDB[j]
		end
		module.db.spellDB[#module.db.spellDB] = nil

		local current = module.options.ScrollBar:GetValue()
		local min_,max_ = module.options.ScrollBar:GetMinMaxValues()
		module.options.ScrollBar:UpdateRange()
		
		local newVal = current == max_ and max(current-SPELL_LINE_HEIGHT,1) or current
		if newVal ~= current then
			module.options.ScrollBar:SetValue(newVal)
		else
			module.options.ReloadSpellsPage()
		end

		SyncUserDB()
		UpdateRoster()
		
		module.options:CleanUPVariables()
	end
	
	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",-100,0)
		line:SetHeight(SPELL_LINE_HEIGHT)

		line.chk = ELib:Check(line):Point("LEFT",10,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)
		ELib: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 = ELib:Text(line):Size(155,SPELL_LINE_HEIGHT):Point("LEFT",70,0):Font(ExRT.F.defFont,12):Shadow()
	
		line.class = ELib:Text(line):Size(180,SPELL_LINE_HEIGHT):Point("LEFT",235,0):Font(ExRT.F.defFont,14):Shadow()
	
		line.dropDownPriority = ELib:DropDown(line,100,15):Size(80):Point("LEFT",375,0)
		line.dropDownPriority._i = i
		line.dropDownPriority.List = SpellsListDropDownPriorityDataList
		line.dropDownPriority:SetScript("OnEnter",SpellsListDropDownPriorityOnEnter)
		line.dropDownPriority:SetScript("OnLeave",ELib.Tooltip.Hide)
		
		line.buttonModify = ELib:Button(line,L.cd2ButtonModify):Size(130,20):Point("LEFT",465,0):OnClick(SpellsListButtonModifyOnClick)
		line.buttonModify._i = i

		line.userSpellName = ELib: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",ELib.Tooltip.Hide)
		
		line.userClass = ELib:DropDown(line,130,12):Size(140):Point("LEFT",225,0):SetText(L.cd2Class)
		line.userClass._i = i
		line.userClass.List = SpellsListClassDropDownList
	
		line.userRemove = ELib:Button(line,"","UIPanelCloseButton"):Size(18,18):Point("LEFT",600,0):OnClick(SpellsListUserRemoveOnClick)
		line.userRemove.tooltipText = L.cd2RemoveButton
		line.userRemove._i = i
		line.userRemove:SetScript("OnEnter",ELib.Tooltip.Std)
		line.userRemove:SetScript("OnLeave",ELib.Tooltip.Hide)

		line.userClass:Hide()
		line.userRemove:Hide()
	end

	self.butSpellsAdd = ELib:Button(self.spellsListScrollFrameContent,L.cd2AddSpell):Size(305,20):Point(5,-3-SPELL_PER_PAGE*SPELL_LINE_HEIGHT):OnClick(function(self) 
		module.options:addNewSpell(module.db.classNames[math.random(1,#module.db.classNames)])
		module.options:CleanUPVariables()
	end) 
	self.butSpellsAdd:Hide()
	
	self.butSpellsFrame = ELib:Button(self.spellsListScrollFrameContent,L.cd2AddSpellFromList):Size(305,20):Point(317,-3-SPELL_PER_PAGE*SPELL_LINE_HEIGHT):OnClick(function(self) 
		module.options.addSpellFrame:Show()
	end) 
	self.butSpellsFrame:Hide()
	
	self.spellsModifyFrame = ELib:Popup():Size(560,180)
	self.spellsModifyFrame.isDefaultSpell = nil
	
	self.spellsModifyFrame.OnShow = function(self)
		if not self.class or not self.sid or not self.tid then
			self:Hide()
			return
		end
		self:SetFrameLevel(120)
		
		local titleName,_,titleTexture = GetSpellInfo(self.sid)
		self.title:SetFormattedText("%s%s",titleTexture and "|T"..titleTexture..":16|t " or "",titleName or L.cd2TextSpell.." #"..self.sid)
		
		local spellData = module.db.spellDB[self.tid]

		local specByClassTable = module.db.specByClass[self.class] or {0}
		local specsCount = #specByClassTable
		for i=1,specsCount do
			local specID = specByClassTable[i]
			local icon = ""
			if module.db.specIcons[specID] then
				icon = "|T".. module.db.specIcons[specID] ..":20|t"
			else
				icon = ExRT.F.classIconInText(self.class,20) or ""
			end
			local line = module.options.spellsModifyFrame.el[i]
		
			line.spec:SetText(icon.." |c"..ExRT.F.classColor(self.class)..L.specLocalizate[module.db.specInLocalizate[specID]])
			line:Show()
			
			if spellData[i+2] then
				line.cd:SetText(spellData[i+2][2])
				line.dur:SetText(spellData[i+2][3])
				line.spellID:SetText(spellData[i+2][1])
				
				line.col:SetText( VExRT.ExCD2.CDECol[spellData[i+2][1]..";"..i] or module.db.def_col[spellData[i+2][1]..";"..i] or 1)
				
				line.add:Hide()
				line.col:Show()
				line.dur:Show()
				line.spellID:Show()
				line.cd:Show()
				line.remove:Show()
			else
				line.add:Show()
				line.col:Hide()
				line.dur:Hide()
				line.spellID:Hide()
				line.cd:Hide()
				line.remove:Hide()
			end
			
			if not spellData.user then
				line.spellID:Disable()
				line.remove:Disable()
				line.add:Hide()
			else
				line.spellID:Enable()
				line.remove:Enable()
			end
		end
		for i=specsCount+1,5 do
			self.el[i]:Hide()
		end
		if not spellData.user then
			self.isDefaultSpell = true
		else
			self.isDefaultSpell = nil
		end
		self:SetHeight(30+32*specsCount)
	end
	
	self.spellsModifyFrame.el = {}
	for i=1,5 do
		local line = CreateFrame("Frame",nil,self.spellsModifyFrame)
		self.spellsModifyFrame.el[i] = line
		line:SetPoint("TOPLEFT",15,-20-(i-1)*32)
		line:SetSize(self.spellsModifyFrame:GetWidth(),30)
		
		line.spec = ELib:Text(line):Size(160,30):Point(0,0):Font(ExRT.F.defFont,14):Shadow()
	
		line.spellID = ELib:Edit(line,6,true):Size(140,20):Point("LEFT",180,0):Tooltip(L.cd2SpellID):OnChange(function(self,isUser)
			local spellID = tonumber(self:GetText())
			if not spellID or not isUser then
				return
			end
			local spellName = GetSpellInfo(spellID)
			local modFrame = self:GetParent():GetParent()

			local c = VExRT.ExCD2.CDECol[module.db.spellDB[modFrame.tid][i+2][1]..";"..i]
			local tmp = nil
			for N1=1,#module.db.spellDB do
				for N2=3,7 do
					if module.db.spellDB[N1][N2] and module.db.spellDB[N1][N2] and module.db.spellDB[N1][N2][1] == module.db.spellDB[modFrame.tid][i+2][1] and not (modFrame.tid == N1 and (i+2) == N2) then
						tmp = true
					end
				end
			end
			if not tmp then
				VExRT.ExCD2.CDECol[module.db.spellDB[modFrame.tid][i+2][1]..";"..i] = nil
			end
			module.db.spellDB[modFrame.tid][i+2][1] = spellID
			if not VExRT.ExCD2.CDECol[spellID..";"..i] and not module.db.def_col[spellID..";"..i] then
				VExRT.ExCD2.CDECol[spellID..";"..i] = c
			else
				modFrame.el[i].col:SetText( VExRT.ExCD2.CDECol[spellID..";"..i] or module.db.def_col[spellID..";"..i])
			end
		end)
		line.spellID:SetScript("OnEnter",function(self)
			local spellID = tonumber(self:GetText())
			if spellID then
				local spellName = GetSpellInfo(spellID)
				if spellName then
					local link = format("|Hspell:%d|hspell|h",spellID)
					ELib.Tooltip.Link(self,link)
				else
					ELib.Tooltip.Std(self)
				end
			else
				ELib.Tooltip.Std(self)
			end
		end)
		line.spellID:SetScript("OnLeave",function(self)
			ELib.Tooltip:Hide()
		end)
		
		line.col = ELib:DropDown(line,100,10):Size(70):Point("LEFT",330,0):Tooltip(L.cd2ColNum)
		local function SpellsModifyFrameColSet(self,arg)
			module.options.spellsModifyFrame.el[i].col:SetText(arg)
			ELib:DropDownClose()
			VExRT.ExCD2.CDECol[module.db.spellDB[module.options.spellsModifyFrame.tid][i+2][1]..";"..i] = tonumber(arg)
			UpdateRoster()
		end
		for j=1,10 do
			line.col.List[j] = {
				text=j,
				justifyH="CENTER",
				arg1=j,
				func=SpellsModifyFrameColSet,
			}
		end
		
		
		line.cd = ELib:Edit(line,6,true):Size(50,20):Point("LEFT",410,0):Tooltip(L.cd2EditBoxCDTooltip):OnChange(function(self,isUser)
			if not isUser then
				return
			end
			local cd_num = tonumber(self:GetText())
			if not cd_num then
				return
			end
			local modFrame = self:GetParent():GetParent()
			module.db.spellDB[modFrame.tid][i+2][2] = cd_num
			if modFrame.isDefaultSpell then
				local spellID = module.db.spellDB[modFrame.tid][1]
				VExRT.ExCD2.default_userCD[spellID] = VExRT.ExCD2.default_userCD[spellID] or {}
				VExRT.ExCD2.default_userCD[spellID][i] = cd_num
			end
		end)
		
		line.dur = ELib:Edit(line,6,true):Size(50,20):Point("LEFT",470,0):Tooltip(L.cd2EditBoxDurationTooltip):OnChange(function(self,isUser)
			if not isUser then
				return
			end
			local duration = tonumber(self:GetText())
			if not duration then
				return
			end
			local modFrame = self:GetParent():GetParent()
			module.db.spellDB[modFrame.tid][i+2][3] = duration
			if modFrame.isDefaultSpell then
				local spellID = module.db.spellDB[modFrame.tid][1]
				VExRT.ExCD2.default_userDuration[spellID] = VExRT.ExCD2.default_userDuration[spellID] or {}
				VExRT.ExCD2.default_userDuration[spellID][i] = duration
			end
		end)
		line.dur:SetTextColor(0.5,1,0.5,1)
		
		line.remove = ELib:Button(line,"","UIPanelCloseButton"):Size(18,18):Point("LEFT",520,0):OnClick(function(self) 
			local parentLine = self:GetParent()
			parentLine.add:Show()
			parentLine.col:Hide()
			parentLine.dur:Hide()
			parentLine.spellID:Hide()
			parentLine.cd:Hide()
			parentLine.remove:Hide()
			
			module.db.spellDB[parentLine:GetParent().tid][i+2] = nil
		end) 
		line.remove.tooltipText = L.cd2RemoveButton
		line.remove:SetScript("OnEnter",ELib.Tooltip.Std)
		line.remove:SetScript("OnLeave",ELib.Tooltip.Hide)
		
		line.add = ELib:Button(line,0,1):Size(400,24):Point(140,-4):OnClick(function(self) 
			local parentLine = self:GetParent()
			local modFrame = parentLine:GetParent()
			self:Hide()
			parentLine.col:Show()
			parentLine.dur:Show()
			parentLine.spellID:Show()
			parentLine.cd:Show()
			parentLine.remove:Show()
			
			parentLine.spellID:SetText(modFrame.sid)
			
			module.db.spellDB[modFrame.tid][i+2] = {modFrame.sid,0,0}
			
			parentLine.cd:SetText(0)
			parentLine.dur:SetText(0)
			parentLine.col:SetText(VExRT.ExCD2.CDECol[module.db.spellDB[modFrame.tid][i+2][1]..";"..i] or 1)
		end)
		line.add.html = ELib:Text(line.add,L.cd2TextAdd):Point(0,0):Point("BOTTOMRIGHT",0,0):Center():Color()
		ExRT.lib.CreateHoverHighlight(line.add)
		line.add.hl:SetVertexColor(1,1,1,0.5)
		line.add:SetScript("OnEnter", function(self) self.hl:Show() end)
		line.add:SetScript("OnLeave", function(self) self.hl:Hide() end)
	end
	
	self.addSpellFrame = ELib:Popup(L.cd2AddSpellFrameName):Size(550,422+10)

	self.addSpellFrame.backClassColor = self.addSpellFrame:CreateTexture(nil, "BORDER",nil,0)
	self.addSpellFrame.backClassColor:SetPoint("TOP",0,-20)
	self.addSpellFrame.backClassColor:SetSize(550,40)
	self.addSpellFrame.backClassColor:SetColorTexture( 1, 1, 1, 1)
	self.addSpellFrame.backClassColor:Hide()
	
	self.addSpellFrame.backClassColorBottom = self.addSpellFrame:CreateTexture(nil, "BORDER",nil,0)
	self.addSpellFrame.backClassColorBottom:SetPoint("BOTTOM",0,0)
	self.addSpellFrame.backClassColorBottom:SetSize(550,15)
	self.addSpellFrame.backClassColorBottom:SetColorTexture( 1, 1, 1, 1)
	self.addSpellFrame.backClassColorBottom:Hide()
	
	self.addSpellFrame.sortedClasses = {}
	
	self.addSpellFrame.dropDown = ELib:DropDown(self.addSpellFrame,200,10):Size(210):Point("TOPRIGHT",-5,-25)
	function self.addSpellFrame.dropDown:SetValue(newValue)
		local addSpellFrame = module.options.addSpellFrame
		addSpellFrame.dropDown:SetText("|c"..ExRT.F.classColor(newValue)..(L.classLocalizate[newValue] or newValue == "RACIAL" and L.cd2Racial or newValue == "ITEMS" and L.cd2Items or "Unk"))
		ELib:DropDownClose()
		if not addSpellFrame.sortedClasses[newValue] then
			for i=1,#module.db.allClassSpells[newValue] do
				local spellName = GetSpellInfo(module.db.allClassSpells[newValue][i][1])
				module.db.allClassSpells[newValue][i].spellName = spellName or tostring(module.db.allClassSpells[newValue][i][1])
			end
			sort(module.db.allClassSpells[newValue],function(a,b) return a.spellName < b.spellName end)
			addSpellFrame.sortedClasses[newValue] = true
		end
		
		for i=1,#module.db.allClassSpells[newValue] do
			if i <= addSpellFrame.buttonsMax then
				local SpellID = module.db.allClassSpells[newValue][i][1]
				local spellName, _, spellTexture = GetSpellInfo(SpellID)
				if module.db.differentIcons[ SpellID ] then
					spellTexture = module.db.differentIcons[SpellID]
				end
				local buttonFrame = module.options.addSpellFrame.buttons[i]
				
				buttonFrame.icon:SetTexture(spellTexture or "Interface\\Icons\\INV_MISC_QUESTIONMARK")
				buttonFrame.text:SetText(spellName or "?")
				buttonFrame.spellID = SpellID
				buttonFrame.spellLink = GetSpellLink(SpellID)
				buttonFrame.colNum = module.db.allClassSpells[newValue][i][2]
				
				buttonFrame.line = module.db.allClassSpells[newValue][i]
				
				if newValue == "PET" then
					buttonFrame.text:SetText("|c"..ExRT.F.classColor(module.db.allClassSpells[newValue][i][3])..L.classLocalizate[module.db.allClassSpells[newValue][i][3]].."|r "..(spellName or "?"))
				end
				
				buttonFrame.disabled = nil
				for j=1,#module.db.spellDB do
					if module.db.spellDB[j][1] == SpellID then
							buttonFrame.icon:SetDesaturated(true)
							buttonFrame.text:SetTextColor(0.5,0.5,0.5,1)
							buttonFrame.disabled = true
						break
					end
				end
				if not buttonFrame.disabled then
					buttonFrame.icon:SetDesaturated(nil)
					buttonFrame.text:SetTextColor(1,1,1,1)
				end
	
				buttonFrame:Show()
			end
		end
		for i=#module.db.allClassSpells[newValue]+1,addSpellFrame.buttonsMax do
			addSpellFrame.buttons[i]:Hide()
		end
		addSpellFrame.class = newValue
		
		local cR,cG,cB = ExRT.F.classColorNum(newValue)
		addSpellFrame.backClassColor:SetGradientAlpha("VERTICAL", cR,cG,cB, 0, cR,cG,cB, 0.5)
		addSpellFrame.backClassColor:Show()
		addSpellFrame.backClassColorBottom:SetGradientAlpha("VERTICAL", cR,cG,cB, 0.5, cR,cG,cB, 0)		
		addSpellFrame.backClassColorBottom:Show()
	end
	for i=1,#module.db.classNames do
		local class = module.db.classNames[i]
		self.addSpellFrame.dropDown.List[#self.addSpellFrame.dropDown.List + 1] = {
			text = "|c"..ExRT.F.classColor(class)..L.classLocalizate[class],
			justifyH = "CENTER",
			func = self.addSpellFrame.dropDown.SetValue,
			arg1 = class,
		}
	end
	for i,noClassData in ipairs({{"PET",L.classLocalizate["PET"]},{"RACIAL",L.cd2Racial},{"ITEMS",L.cd2Items}}) do
		self.addSpellFrame.dropDown.List[#self.addSpellFrame.dropDown.List + 1] = {
			text = "|c"..ExRT.F.classColor(noClassData[1])..noClassData[2],
			justifyH = "CENTER",
			func = self.addSpellFrame.dropDown.SetValue,
			arg1 = noClassData[1],
		}
	end
	self.addSpellFrame.dropDown.Lines = #self.addSpellFrame.dropDown.List
	
	local function AddSpellFrameButtonsOnEnter(self)
		self:SetBackdropBorderColor(1,1,1,0.5)
		GameTooltip:SetOwner(self, "ANCHOR_LEFT")
		
		local isItem,isArtifact = nil
		for itemID,spellID in pairs(module.db.itemsToSpells) do
			if spellID == self.line[1] then
				if module.db.itemsArtifacts[itemID] then
					isArtifact = itemID
				else
					isItem = itemID
				end
				break
			end
		end
		
		if not isItem then
			GameTooltip:SetHyperlink(self.spellLink)
		else
			local _,itemLink = GetItemInfo(isItem)
			GameTooltip:SetHyperlink(itemLink or self.spellLink)
		end
		GameTooltip:AddLine(" ")
		
		local className = module.options.addSpellFrame.class
		if module.db.specByClass[className] then
			for i=1,#module.db.specByClass[className] do
				if self.line[2+i] then
					local icon = ""
					if module.db.specIcons[module.db.specByClass[className][i]] then
						icon = "|T".. module.db.specIcons[module.db.specByClass[className][i]] ..":20|t"
					else
						icon = ExRT.F.classIconInText(className,20) or ""
					end
					GameTooltip:AddLine(icon.." |c"..ExRT.F.classColor(className)..L.specLocalizate[module.db.specInLocalizate[module.db.specByClass[className][i]]].. ":|r|cffffffff "..L.cd2AddSpellFrameCDText.." "..format("%d:%02d",self.line[i+2][2]/60,self.line[i+2][2]%60).. (self.line[i+2][3] > 0 and ", "..L.cd2AddSpellFrameDurationText.." "..self.line[i+2][3] or ""))
				end
			end
		elseif className == "PET" then
			for petName,petData in pairs(module.db.petsAbilities) do
				for j=2,#petData do
					if petData[j][1] == self.line[1] then
						local petNameInTooltip = petName
						if tonumber(petNameInTooltip) then
							petNameInTooltip = L.creatureNames[tonumber(petNameInTooltip)]
						end
						GameTooltip:AddLine((ExRT.F.classIconInText(self.line[3],20) or "").." |c"..ExRT.F.classColor(self.line[3])..petNameInTooltip.. ":|r|cffffffff "..L.cd2AddSpellFrameCDText.." "..format("%d:%02d",petData[j][2]/60,petData[j][2]%60).. (petData[j][3] and ", "..L.cd2AddSpellFrameDurationText.." "..petData[j][3] or ""))
						break
					end
				end
			end
		else
			GameTooltip:AddLine("|cffffffff"..L.cd2AddSpellFrameCDText.." "..self.line[3][2].. (self.line[3][3] > 0 and ", "..L.cd2AddSpellFrameDurationText.." "..self.line[3][3] or ""))
		end
		if isArtifact then
			GameTooltip:AddLine(ARTIFACT_POWER)
		end
		GameTooltip:AddLine("|cffffffff"..L.cd2AddSpellFrameColumnText..": ".. self.colNum .."|r")
		if module.db.spell_isTalent[self.line[1]] and not className == "ITEMS" then
			GameTooltip:AddLine("|cffffffff"..L.cd2AddSpellFrameTalent.."|r")
		end
		if module.db.spell_durationByTalent_fix[self.line[1]] then
			GameTooltip:AddLine("|cffaaffaa"..L.cd2AddSpellFrameDuration..":|r")
			for j=1,#module.db.spell_durationByTalent_fix[self.line[1]],2 do
				local sname = GetSpellInfo(module.db.spell_durationByTalent_fix[self.line[1]][j]) or "???"
				local cd = module.db.spell_durationByTalent_fix[self.line[1]][j+1]
				if type(cd) == 'table' then
					cd = strjoin(",",unpack(cd))
				elseif not tonumber(cd) then
					cd = tonumber(string.sub(cd,2))
					if cd < 1 then
						cd = "-"..( (1-cd)*100 ).."%"
					else
						cd = "+"..( (cd-1)*100 ).."%"
					end
				end
				GameTooltip:AddLine("|cffffffff - "..sname .." (".. (tonumber(cd) and cd > 0 and "+" or "").. cd ..")|r")
				
				ELib.Tooltip:Add("spell:"..module.db.spell_durationByTalent_fix[self.line[1]][j])
			end
			
		end
		do
			local cdByTalent_fix = nil
			local readiness_lines = {}
			if module.db.spell_cdByTalent_fix[self.line[1]] then
				cdByTalent_fix = true
				for j=1,#module.db.spell_cdByTalent_fix[self.line[1]],2 do
					local sname = GetSpellInfo(module.db.spell_cdByTalent_fix[self.line[1]][j]) or "???"
					local cd = module.db.spell_cdByTalent_fix[self.line[1]][j+1]
					if type(cd) == 'table' then
						cd = strjoin(",",unpack(cd))
					elseif not tonumber(cd) then
						cd = tonumber(string.sub(cd,2))
						if cd < 1 then
							cd = "-"..( (1-cd)*100 ).."%"
						else
							cd = "+"..( (cd-1)*100 ).."%"
						end
					end
					table.insert(readiness_lines,"|cffffffff - "..sname .." (".. (tonumber(cd) and cd > 0 and "+" or "").. cd ..")|r")
					
					ELib.Tooltip:Add("spell:"..module.db.spell_cdByTalent_fix[self.line[1]][j])
				end
			end
			if cdByTalent_fix then
				GameTooltip:AddLine("|cffffaaaa"..L.cd2AddSpellFrameCDChange..": |r")
				for j=1,#readiness_lines do
					GameTooltip:AddLine(readiness_lines[j])
				end
			end
		end
		if module.db.spell_charge_fix[self.line[1]] then
			if module.db.spell_charge_fix[self.line[1]] == 1 then
				GameTooltip:AddLine("|cffffffaa"..L.cd2AddSpellFrameCharge.."|r")
			else
				GameTooltip:AddLine("|cffffffaa"..L.cd2AddSpellFrameChargeChange..":|r")
				local sname = GetSpellInfo(module.db.spell_charge_fix[self.line[1]]) or "???"
				GameTooltip:AddLine("|cffffffff - "..sname .."|r")
			end
		end
		do
			for auraID,sID in pairs(module.db.spell_aura_list) do
				if sID == self.line[1] then
					local sname = GetSpellInfo(auraID) or "???"
					GameTooltip:AddLine("|cffaaffaa"..L.cd2AddSpellFrameDurationLost..":|r")
					GameTooltip:AddLine("|cffffffff - \""..sname.."\"|r")
				end
			end
		end
		if module.db.spell_sharingCD[self.line[1]] then
			GameTooltip:AddLine("|cffffffaa"..L.cd2AddSpellFrameSharing..": |r")
			for otherID,otherCD in pairs(module.db.spell_sharingCD[self.line[1]]) do
				local sname = GetSpellInfo(otherID) or "???"
				GameTooltip:AddLine("|cffffffff - "..sname .." (".. otherCD ..")|r")
			end
		end
		if module.db.spell_dispellsList[self.line[1]] then
			GameTooltip:AddLine("|cffffffaa"..L.cd2AddSpellFrameDispel.."|r")
		end
		if module.db.spell_talentReplaceOther[self.line[1]] then
			local spellID = module.db.spell_talentReplaceOther[self.line[1]]
			local sname
			if type(spellID)=='table' then
				for i=1,#spellID do
					local sname = GetSpellInfo(spellID[i]) or "???"
					GameTooltip:AddLine("|cffffaaaa"..L.cd2AddSpellFrameReplace .." ".. sname .."|r")
				end
			else
				local sname = GetSpellInfo(spellID) or "???"
				GameTooltip:AddLine("|cffffaaaa"..L.cd2AddSpellFrameReplace .." ".. sname .."|r")
			end
		end
		GameTooltip:Show()
	end
	local function AddSpellFrameButtonsOnLeave(self)
	  	self:SetBackdropBorderColor(1,1,1,0)
	  	GameTooltip_Hide()
	  	ELib.Tooltip:HideAdd()
	end
	local function AddSpellFrameButtonsOnClick(self)
		if not self.disabled then
			local class = module.options.addSpellFrame.class
			module.options:addNewSpell((class == "RACIAL" or class == "ITEMS") and "ALL" or class,self.line)
			module.options.addSpellFrame:Hide()
		end
	end
	
	self.addSpellFrame.buttonsMax = 0
	for classNum=1,#module.db.classNames do
		local now = #module.db.allClassSpells[ module.db.classNames[classNum] ]
		self.addSpellFrame.buttonsMax = max(self.addSpellFrame.buttonsMax,now)
	end
	self.addSpellFrame.buttonsMax = max(self.addSpellFrame.buttonsMax,#module.db.allClassSpells["PET"])
	self.addSpellFrame:SetHeight( 82 + 35 * ceil( self.addSpellFrame.buttonsMax / 4 ) )
	
	self.addSpellFrame.buttons = {}
	for i=1,self.addSpellFrame.buttonsMax do
		local buttonFrame = CreateFrame("Button",nil,self.addSpellFrame)
		self.addSpellFrame.buttons[i] = buttonFrame
		buttonFrame:SetPoint("TOPLEFT",(i-1)%4 * 130 + 15,-floor((i-1)/4) * 35 - 60)
		buttonFrame:SetSize(130,35)
		buttonFrame:SetBackdrop({edgeFile = ExRT.F.defBorder, edgeSize = 8})
		buttonFrame:SetBackdropBorderColor(1,1,1,0)
		
		buttonFrame:SetScript("OnEnter",AddSpellFrameButtonsOnEnter)
		buttonFrame:SetScript("OnLeave",AddSpellFrameButtonsOnLeave)
		
		buttonFrame:SetScript("OnClick",AddSpellFrameButtonsOnClick)
		
		buttonFrame.icon = buttonFrame:CreateTexture(nil, "BACKGROUND")
		buttonFrame.icon:SetSize(24,24)
		buttonFrame.icon:SetPoint("TOPLEFT",5,-5)
		
		buttonFrame.text = ELib:Text(buttonFrame,"",12):Size(99,31):Point(33,-2):Color():Shadow()
	end

	function module.options:addNewSpell(class,line,doNotScroll)
		local sbmin,sbmax = module.options.ScrollBar:GetMinMaxValues()
		--module.options.ScrollBar:SetMinMaxValues(sbmin,sbmax+1)
		if line then
			if class ~= "PET" then
				module.db.spellDB[#module.db.spellDB+1] = {line[1],class,line[3],line[4],line[5],line[6],line[7],user=true}
				for j=3,7 do
					if line[j] and not VExRT.ExCD2.CDECol[ line[j][1] .. ";" .. (j-2) ] then
						VExRT.ExCD2.CDECol[ line[j][1] .. ";" .. (j-2) ] = line[2]
					end
				end
			else
				local cd,dur = 0,0
				for petName,petData in pairs(module.db.petsAbilities) do
					for j=2,#petData do
						if petData[j][1] == line[1] then
							cd = petData[j][2]
							dur = petData[j][3] or 0
							break
						end
					end
				end
				module.db.spellDB[#module.db.spellDB+1] = {line[1],line[3],{line[1],cd,dur},user=true}
				if not VExRT.ExCD2.CDECol[ line[1] .. ";1" ] then
					VExRT.ExCD2.CDECol[ line[1] .. ";1" ] = line[2]
				end
			end
		else
			module.db.spellDB[#module.db.spellDB+1] = {0,class,user=true}
		end
		module.options.ScrollBar:UpdateRange()
		if not doNotScroll then
			module.options.ScrollBar:SetValue(sbmax+31)
		end
		SyncUserDB()
		UpdateRoster()
	end
	
	self.addSpellFrame.OnShow = function (self)
		self.dropDown:SetValue(self.class or "WARRIOR")
	end
	
	self.tab.tabs[1].decorationLine = CreateFrame("Frame",nil,self.tab.tabs[1])
	self.tab.tabs[1].decorationLine.texture = self.tab.tabs[1].decorationLine:CreateTexture(nil, "BACKGROUND")
	self.tab.tabs[1].decorationLine:SetPoint("TOPLEFT",self.tab.tabs[1],-8,-8)
	self.tab.tabs[1].decorationLine:SetPoint("BOTTOMRIGHT",self.tab.tabs[1],"TOPRIGHT",8,-28)
	self.tab.tabs[1].decorationLine.texture:SetAllPoints()
	self.tab.tabs[1].decorationLine.texture:SetColorTexture(1,1,1,1)
	self.tab.tabs[1].decorationLine.texture:SetGradientAlpha("VERTICAL",.24,.25,.30,1,.27,.28,.33,1)
	
	self.tab1tab = ELib:Tabs(self.tab.tabs[1],0,L.cd2Spells,L.cd2Columns):Size(600,100):Point(0,0)
	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
	
	self.colsSpells = CreateFrame("Frame",nil,self.tab.tabs[1])
	self.colsSpells:SetSize(650,SPELL_PAGE_HEIGHT)
	self.colsSpells:SetPoint("TOP", 0, -38)
	ELib: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(650,SPELL_PAGE_HEIGHT+50)
	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 )
		val = floor( val / 24 ) + 1
		local line = 0
		local count = 0
		for i=1,#module.db.spellDB do
			local spellData = module.db.spellDB[i]
			local spellID = spellData[1]
			if VExRT_CDE[ spellID ] then
				local class = spellData[2]
				local specsCount = module.db.specByClass[class] and #module.db.specByClass[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)
							
							if j == 3 then
								lineFrame.iconSpec:Hide()
							else
								lineFrame.iconSpec:Show()
								lineFrame.iconSpec:SetTexture( module.db.specIcons[ module.db.specByClass[class][j - 2] ] or "" )
							end
							
							if CLASS_ICON_TCOORDS[class] then
								lineFrame.iconClass:SetTexture("Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES")
								lineFrame.iconClass:SetTexCoord(unpack(CLASS_ICON_TCOORDS[class]))
							else
								lineFrame.iconClass:SetTexture("")
							end
							
							for k=1,10 do
								lineFrame.chk[k]:SetChecked(false)
							end
							local checked = VExRT.ExCD2.CDECol[spellData[j][1]..";"..(j-2)] or module.db.def_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.spellDB do
			local spellData = module.db.spellDB[i]
			if VExRT_CDE[ spellData[1] ] then
				local class = spellData[2]
				local specsCount = module.db.specByClass[class] and #module.db.specByClass[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 = ELib: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)
		ELib.Tooltip.Link(self,self:GetParent().link)
	end
	local function ColsSpellsSpellCheckboxClick(self)
		for j=1,10 do
			if j ~= self._i then
				self.array[j]:SetChecked(false)
			end
		end
		if not self:GetChecked() then
			self:SetChecked(true)
		end
		VExRT.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)*24)
		frame:SetSize(577,24)
		
		frame.icon = frame:CreateTexture(nil, "ARTWORK")
		frame.icon:SetSize(22,22)
		frame.icon:SetPoint("TOPLEFT", 2, 0)
		frame.icon:SetTexCoord(.1,.9,.1,.9)
		ELib: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 = ELib:Text(frame):Size(156,24):Point(29,0):Font(ExRT.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,10 do
			frame.chk[j] = ELib:Check(frame):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 = ELib: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.maxColumns + 1)
		
		if isGeneralTab then
			VExRT.ExCD2.colSet[i].frameGeneral = nil
			VExRT.ExCD2.colSet[i].iconGeneral = nil
			VExRT.ExCD2.colSet[i].textureGeneral = nil
			VExRT.ExCD2.colSet[i].fontGeneral = nil
			VExRT.ExCD2.colSet[i].textGeneral = nil
			VExRT.ExCD2.colSet[i].methodsGeneral = nil
		end

		module.options.optColSet.chkEnable:SetChecked(VExRT.ExCD2.colSet[i].enabled)
		module.options.optColSet.chkGeneral:SetChecked(VExRT.ExCD2.colSet[i].frameGeneral)
		
		module.options.optColSet.sliderLinesNum:SetValue(VExRT.ExCD2.colSet[i].frameLines or module.db.colsDefaults.frameLines)
		module.options.optColSet.sliderAlpha:SetValue(VExRT.ExCD2.colSet[i].frameAlpha or module.db.colsDefaults.frameAlpha)
		module.options.optColSet.sliderScale:SetValue(VExRT.ExCD2.colSet[i].frameScale or module.db.colsDefaults.frameScale)
		module.options.optColSet.sliderWidth:SetValue(VExRT.ExCD2.colSet[i].frameWidth or module.db.colsDefaults.frameWidth)
		module.options.optColSet.sliderColsInCol:SetValue(VExRT.ExCD2.colSet[i].frameColumns or module.db.colsDefaults.frameColumns)
		module.options.optColSet.sliderBetweenLines:SetValue(VExRT.ExCD2.colSet[i].frameBetweenLines or module.db.colsDefaults.frameBetweenLines)
		module.options.optColSet.sliderBlackBack:SetValue(VExRT.ExCD2.colSet[i].frameBlackBack or module.db.colsDefaults.frameBlackBack)
		
		module.options.optColSet.chkGeneral:doAlphas()
		
		module.options.optColSet.sliderHeight:SetValue(VExRT.ExCD2.colSet[i].iconSize or module.db.colsDefaults.iconSize)
		module.options.optColSet.chkGray:SetChecked(VExRT.ExCD2.colSet[i].iconGray)
		module.options.optColSet.chkCooldown:SetChecked(VExRT.ExCD2.colSet[i].methodsCooldown)	
		module.options.optColSet.chkShowTitles:SetChecked(VExRT.ExCD2.colSet[i].iconTitles)	
		module.options.optColSet.chkHideBlizzardEdges:SetChecked(VExRT.ExCD2.colSet[i].iconHideBlizzardEdges)	
		module.options.optColSet.chkGeneralIcons:SetChecked(VExRT.ExCD2.colSet[i].iconGeneral)
		do
			local defIconPos = VExRT.ExCD2.colSet[i].iconPosition or module.db.colsDefaults.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,#ExRT.F.textureList do
				if ExRT.F.textureList[j] == (VExRT.ExCD2.colSet[i].textureFile or ExRT.F.barImg) then
					texturePos = j
					break
				end
			end
			if not texturePos and VExRT.ExCD2.colSet[i].textureFile then
				texturePos = select(3,string.find(VExRT.ExCD2.colSet[i].textureFile,"\\([^\\]*)$"))
			end
			texturePos = texturePos or "Standart"
			module.options.optColSet.dropDownTexture:SetText(L.cd2OtherSetTexture.." ["..texturePos.."]")
		end
		module.options.optColSet.colorPickerBorder.color:SetColorTexture(VExRT.ExCD2.colSet[i].textureBorderColorR or module.db.colsDefaults.textureBorderColorR,VExRT.ExCD2.colSet[i].textureBorderColorG or module.db.colsDefaults.textureBorderColorG,VExRT.ExCD2.colSet[i].textureBorderColorB or module.db.colsDefaults.textureBorderColorB, VExRT.ExCD2.colSet[i].textureBorderColorA or module.db.colsDefaults.textureBorderColorA)
		module.options.optColSet.sliderBorderSize:SetValue(VExRT.ExCD2.colSet[i].textureBorderSize or module.db.colsDefaults.textureBorderSize)
		module.options.optColSet.chkAnimation:SetChecked(VExRT.ExCD2.colSet[i].textureAnimation)
		module.options.optColSet.chkHideSpark:SetChecked(VExRT.ExCD2.colSet[i].textureHideSpark)
		module.options.optColSet.chkSmoothAnimation:SetChecked(VExRT.ExCD2.colSet[i].textureSmoothAnimation)
		module.options.optColSet.sliderSmoothAnimationDuration:SetValue(VExRT.ExCD2.colSet[i].textureSmoothAnimationDuration or module.db.colsDefaults.textureSmoothAnimationDuration)
		module.options.optColSet.chkGeneralColorize:SetChecked(VExRT.ExCD2.colSet[i].textureGeneral)
		
		module.options.optColSet.chkGeneralColorize:doAlphas()
			
		do
			local FontNameForDropDown = select(3,string.find(VExRT.ExCD2.colSet[i].fontName or module.db.colsDefaults.fontName,"\\([^\\]*)$"))
			module.options.optColSet.dropDownFont:SetText( (FontNameForDropDown or VExRT.ExCD2.colSet[i].fontName or module.db.colsDefaults.fontName or "?") )
		end
		module.options.optColSet.sliderFont:SetValue(VExRT.ExCD2.colSet[i].fontSize or module.db.colsDefaults.fontSize)
		module.options.optColSet.chkFontOutline:SetChecked(VExRT.ExCD2.colSet[i].fontOutline)
		module.options.optColSet.chkFontShadow:SetChecked(VExRT.ExCD2.colSet[i].fontShadow)
		do
			module.options.optColSet.chkFontOtherAvailable:SetChecked(VExRT.ExCD2.colSet[i].fontOtherAvailable)
			module.options.fontOtherAvailable(VExRT.ExCD2.colSet[i].fontOtherAvailable)
			if VExRT.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(VExRT.ExCD2.colSet[i].fontGeneral)
		
		module.options.optColSet.chkGeneralFont:doAlphas()
		
		module.options.optColSet.textLeftTemEdit:SetText(VExRT.ExCD2.colSet[i].textTemplateLeft or module.db.colsDefaults.textTemplateLeft)
		module.options.optColSet.textRightTemEdit:SetText(VExRT.ExCD2.colSet[i].textTemplateRight or module.db.colsDefaults.textTemplateRight)
		module.options.optColSet.textCenterTemEdit:SetText(VExRT.ExCD2.colSet[i].textTemplateCenter or module.db.colsDefaults.textTemplateCenter)
		module.options.optColSet.chkIconName:SetChecked(VExRT.ExCD2.colSet[i].textIconName)
		module.options.optColSet.chkGeneralText:SetChecked(VExRT.ExCD2.colSet[i].textGeneral)
		
		module.options.optColSet.chkGeneralText:doAlphas()

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

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

		module.options.optColSet.chkGeneralVisibility:doAlphas()

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

		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralIcons,not isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralColorize,not isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralFont,not isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralText,not isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralMethods,not isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralVisibility,not isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkGeneralBlackList,not isGeneralTab)
		
		ExRT.lib.ShowOrHide(module.options.optColSet.chkSortByAvailability,isGeneralTab)
		ExRT.lib.ShowOrHide(module.options.optColSet.chkSortByAvailability_activeToTop,isGeneralTab)
		ExRT.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 = {}
	do
		local tmpArr = {}
		for i=1,module.db.maxColumns do
			tmpArr[i] = tostring(i)
		end
		tmpArr[module.db.maxColumns+1] = L.cd2GeneralSet
		self.optColTabs = ELib:Tabs(self.tab.tabs[2],0,unpack(tmpArr)):Size(660,417):Point(0,-48):SetTo(module.db.maxColumns+1)
	end
	for i=1,module.db.maxColumns+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)
	
	self.tab.tabs[2].decorationLine = CreateFrame("Frame",nil,self.tab.tabs[2])
	self.tab.tabs[2].decorationLine.texture = self.tab.tabs[2].decorationLine:CreateTexture(nil, "BACKGROUND")
	self.tab.tabs[2].decorationLine:SetPoint("TOPLEFT",self.tab.tabs[2],-8,-28)
	self.tab.tabs[2].decorationLine:SetPoint("BOTTOMRIGHT",self.tab.tabs[2],"TOPRIGHT",8,-48)
	self.tab.tabs[2].decorationLine.texture:SetAllPoints()
	self.tab.tabs[2].decorationLine.texture:SetColorTexture(1,1,1,1)
	self.tab.tabs[2].decorationLine.texture:SetGradientAlpha("VERTICAL",.24,.25,.30,1,.27,.28,.33,1)

	 
	self.optColSet.superTabFrame = ExRT.lib:ScrollTabsFrame(self.optColTabs,L.cd2OtherSetTabNameGeneral,L.cd2OtherSetTabNameIcons,L.cd2OtherSetTabNameColors,L.cd2OtherSetTabNameFont,L.cd2OtherSetTabNameText,L.cd2OtherSetTabNameOther,L.cd2OtherSetTabNameVisibility,L.cd2OtherSetTabNameBlackList,L.cd2OtherSetTabNameTemplate):Size(660,450):Point("TOP",0,-10)	
	
	self.optColSet.chkEnable = ELib:Check(self.optColSet.superTabFrame.tab[1],"|cff00ff00 >>>"..L.senable.."<<<"):Point(10,-10):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].enabled = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].enabled = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneral = ELib:Check(self.optColSet.superTabFrame.tab[1],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneral:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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 = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2lines):Size(400):Point("TOP",0,-50):Range(1,module.db.maxLinesInCol):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameLines = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()		
	end)
	
	self.optColSet.sliderWidth = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2width):Size(400):Point("TOP",0,-85):Range(1,400):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameWidth = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderAlpha = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2alpha):Size(400):Point("TOP",0,-120):Range(0,100):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameAlpha = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderScale = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2scale):Size(400):Point("TOP",0,-155):Range(5,200):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameScale = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits("ScaleFix")
	end)
	
	self.optColSet.sliderColsInCol = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2ColSetColsInCol):Size(400):Point("TOP",0,-190):Range(1,module.db.maxLinesInCol):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameColumns = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderBetweenLines = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2ColSetBetweenLines):Size(400):Point("TOP",0,-225):Range(0,20):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameBetweenLines = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderBlackBack = ELib:Slider(self.optColSet.superTabFrame.tab[1],L.cd2BlackBack):Size(400):Point("TOP",0,-260):Range(0,100):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameBlackBack = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)

	self.optColSet.butToCenter = ELib:Button(self.optColSet.superTabFrame.tab[1],L.cd2ColSetResetPos):Size(200,20):Point("TOP",0,-295):OnClick(function(self) 
		if (module.db.maxColumns + 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 = ELib:Slider(self.optColSet.superTabFrame.tab[2],L.cd2OtherSetIconSize):Size(400):Point("TOP",0,-50):Range(6,128):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconSize = event
		module:ReloadAllSplits()
		self.tooltipText = event
		self:tooltipReload(self)
	end)
	
	self.optColSet.chkGray = ELib:Check(self.optColSet.superTabFrame.tab[2],L.cd2graytooltip):Point(10,-110):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconGray = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconGray = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.textIconPos = ELib:Text(self.optColSet.superTabFrame.tab[2],L.cd2OtherSetIconPosition..":"):Size(200,20):Point(10,-85)
	self.optColSet.dropDownIconPos = ELib: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)
				ELib:DropDownClose()
				VExRT.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 = ELib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetMethodCooldown):Point(10,-135):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsCooldown = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsCooldown = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkShowTitles = ELib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetShowTitles):Point(10,-160):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconTitles = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconTitles = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkHideBlizzardEdges = ELib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetIconHideBlizzardEdges):Point(10,-185):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconHideBlizzardEdges = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconHideBlizzardEdges = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneralIcons = ELib:Check(self.optColSet.superTabFrame.tab[2],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralIcons:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].iconGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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)
	end
	
	--> Texture and colors Options
	
	local function dropDownTextureButtonClick(self,arg,name)
		ELib:DropDownClose()
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureFile = arg
		module:ReloadAllSplits()
		module.options.optColSet.dropDownTexture:SetText(L.cd2OtherSetTexture.." ["..name.."]")
	end

	self.optColSet.textDDTexture = ELib:Text(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetTexture..":"):Size(200,20):Point(10,-35)
	self.optColSet.dropDownTexture = ELib:DropDown(self.optColSet.superTabFrame.tab[3],200,15):Size(200):Point(180,-35)
	for i=1,#ExRT.F.textureList do
		self.optColSet.dropDownTexture.List[i] = {}
		local info = self.optColSet.dropDownTexture.List[i]
		info.text = i
		info.arg1 = ExRT.F.textureList[i]
		info.arg2 = i
		info.func = dropDownTextureButtonClick
		info.texture = ExRT.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 = ELib:Text(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetBorder..":"):Size(200,20):Point(10,-65)
	self.optColSet.sliderBorderSize = ELib:Slider(self.optColSet.superTabFrame.tab[3],""):Size(170):Point(180,-68):Range(0,20):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderSize = event
		self.tooltipText = event
		self:tooltipReload(self)
		module:ReloadAllSplits()
	end)
	self.optColSet.colorPickerBorder = ExRT.lib.CreateColorPickButton(self.optColSet.superTabFrame.tab[3],20,20,nil,361,-65)
	self.optColSet.colorPickerBorder:SetScript("OnClick",function (self)
		ColorPickerFrame.previousValues = {VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorR or module.db.colsDefaults.textureBorderColorR,VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorG or module.db.colsDefaults.textureBorderColorG,VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorB or module.db.colsDefaults.textureBorderColorB, VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorA or module.db.colsDefaults.textureBorderColorA}
		ColorPickerFrame.hasOpacity = true
		local nilFunc = ExRT.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
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorR = newR
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorG = newG
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorB = newB
			VExRT.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 = VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorA or module.db.colsDefaults.textureBorderColorA
		ColorPickerFrame:SetColorRGB(VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorR or module.db.colsDefaults.textureBorderColorR,VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorG or module.db.colsDefaults.textureBorderColorG,VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureBorderColorB or module.db.colsDefaults.textureBorderColorB)
		ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = changedCallback, changedCallback, changedCallback
		ColorPickerFrame:Show()
	end)
		
	self.optColSet.chkAnimation = ELib:Check(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetAnimation):Point(10,-97):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureAnimation = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureAnimation = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkHideSpark = ELib:Check(self.optColSet.superTabFrame.tab[3],L.cd2OtherSetHideSpark):Point(200,-97):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureHideSpark = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureHideSpark = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkSmoothAnimation = ELib:Check(self.optColSet.superTabFrame.tab[3],L.cd2TextureSmoothAnim):Point(10,-122):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureSmoothAnimation = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureSmoothAnimation = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderSmoothAnimationDuration = ELib:Slider(self.optColSet.superTabFrame.tab[3],""):Size(140):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
		VExRT.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 = ELib:Slider(self.colorSetupFrame,L.cd2OtherSetColorFrameAlpha):Size(400):Point("TOP",0,-163):Range(0,100)
	self.colorSetupFrame.backCDAlpha = ELib:Slider(self.colorSetupFrame,L.cd2OtherSetColorFrameAlphaCD):Size(400):Point("TOP",0,-198):Range(0,100)
	self.colorSetupFrame.backCooldownAlpha = ELib:Slider(self.colorSetupFrame,L.cd2OtherSetColorFrameAlphaCooldown):Size(400):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 = {VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."R"] or module.db.colsDefaults[self.inOptName.."R"],VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."G"] or module.db.colsDefaults[self.inOptName.."G"],VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."B"] or module.db.colsDefaults[self.inOptName.."B"], 1}
		local nilFunc = ExRT.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
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."R"] = newR
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."G"] = newG
			VExRT.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(VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."R"] or module.db.colsDefaults[self.inOptName.."R"],VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."G"] or module.db.colsDefaults[self.inOptName.."G"],VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName.."B"] or module.db.colsDefaults[self.inOptName.."B"])
		ColorPickerFrame.func, ColorPickerFrame.cancelFunc = changedCallback, changedCallback
		ColorPickerFrame:Show()
	end

	local function colorPickerSliderValue(self,newval)
		VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName] = newval / 100
		module:ReloadAllSplits()
		self.tooltipText = ExRT.F.Round(newval)
		self:tooltipReload(self)
	end

	local function colorPickerCheckBoxClick(self)
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][self.inOptName] = true
		else
			VExRT.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] = ELib: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]] = ExRT.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]] = ELib: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]] = ELib:Check(self.colorSetupFrame,""):Point(241+(i-1)*40,-117):Size(18,18):OnClick(colorPickerCheckBoxClick)	
		self.colorSetupFrame["colorClass"..colorSetupFrameColorsObjectsNames[i]].inOptName = checksInOptNames[i]
	end
	self.colorSetupFrame["textClass"] = ELib: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 = ELib:Button(self.colorSetupFrame,L.cd2OtherSetColorFrameReset):Size(160,20):Point("TOP",-81,-265)
	self.colorSetupFrame.softenButton = ELib: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 = VExRT.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] or module.db.colsDefaults["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]]
					maxColor = max(maxColor,color)
				end
				for n=1,3 do
					local color = VExRT.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] or module.db.colsDefaults["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]]
					if color < maxColor then
						VExRT.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
					VExRT.ExCD2.colSet[module.options.optColTabs.selected]["textureColor"..colorSetupFrameColorsObjectsNames[i]..colorSetupFrameColorsNames[j]..tmpColors[n]] = nil
				end
			end
		end
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureAlphaBackground = nil
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureAlphaTimeLine = nil
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureAlphaCooldown = nil
		for i=1,3 do
			VExRT.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(VExRT.ExCD2.colSet[module.options.optColTabs.selected][this.inOptName.."R"] or module.db.colsDefaults[this.inOptName.."R"],VExRT.ExCD2.colSet[module.options.optColTabs.selected][this.inOptName.."G"] or module.db.colsDefaults[this.inOptName.."G"],VExRT.ExCD2.colSet[module.options.optColTabs.selected][this.inOptName.."B"] or module.db.colsDefaults[this.inOptName.."B"],1)
			end
		end
		for i=1,3 do
			module.options.colorSetupFrame["colorClass"..colorSetupFrameColorsObjectsNames[i]]:SetChecked( VExRT.ExCD2.colSet[module.options.optColTabs.selected][ checksInOptNames[i] ] )
		end

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

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

	
	self.optColSet.chkGeneralColorize = ELib:Check(self.optColSet.superTabFrame.tab[3],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralColorize:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].textureGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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 = ELib: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(VExRT.ExCD2.colSet[i][self.fontMark.."Name"] or module.db.colsDefaults.fontName,"\\([^\\]*)$"))
			module.options.optColSet.dropDownFont:SetText(  (FontNameForDropDown or VExRT.ExCD2.colSet[i][self.fontMark.."Name"] or module.db.colsDefaults.fontName or "?") )
		end
		module.options.optColSet.sliderFont:SetValue(VExRT.ExCD2.colSet[i][self.fontMark.."Size"] or module.db.colsDefaults.fontSize)
		module.options.optColSet.chkFontOutline:SetChecked(VExRT.ExCD2.colSet[i][self.fontMark.."Outline"])
		module.options.optColSet.chkFontShadow:SetChecked(VExRT.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 = ELib:Check(self.optColSet.superTabFrame.tab[4],L.cd2ColSetFontOtherAvailable):Point(10,-220):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].fontOtherAvailable = true --fontOtherAvailable
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].fontOtherAvailable = nil
		end
		module:ReloadAllSplits()
		module.options.fontOtherAvailable( self:GetChecked() )
	end)

	self.optColSet.sliderFont = ELib:Slider(self.optColSet.fontsTab,L.cd2OtherSetFontSize):Size(400):Point("TOP",0,-60):Range(8,72):OnChange(function(self,event) 
		event = event - event%1
		VExRT.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 = ELib:Text(self.optColSet.fontsTab,L.cd2OtherSetFont..":"):Size(200,20):Point(10,-15)

	local function dropDownFontButtonClick(self,arg1,arg2)
		ELib:DropDownClose()
		VExRT.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Name"] = arg1 --fontName
		module:ReloadAllSplits()
		local FontNameForDropDown = select(3,string.find(arg1,"\\([^\\]*)$"))
		if arg2 <= #ExRT.F.fontList then
			module.options.optColSet.dropDownFont:SetText(FontNameForDropDown or ExRT.F.fontList[arg2])
		else
			module.options.optColSet.dropDownFont:SetText(FontNameForDropDown or arg2)
		end
	end
	
	self.optColSet.dropDownFont = ELib:DropDown(self.optColSet.fontsTab,350,10):Size(200):Point(180,-15)
	for i=1,#ExRT.F.fontList do
		self.optColSet.dropDownFont.List[i] = {}
		local info = self.optColSet.dropDownFont.List[i]
		info.text = ExRT.F.fontList[i]
		info.arg1 = ExRT.F.fontList[i]
		info.arg2 = i
		info.func = dropDownFontButtonClick
		info.font = ExRT.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 = ELib:Check(self.optColSet.fontsTab,L.cd2OtherSetOutline):Point(10,-95):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Outline"] = true --fontOutline
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Outline"] = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkFontShadow = ELib:Check(self.optColSet.fontsTab,L.cd2OtherSetFontShadow):Point(10,-120):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Shadow"] = true -- fontShadow
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected][module.options.optColSet.nowFont.."Shadow"] = nil
		end
		module:ReloadAllSplits()
	end)

	self.optColSet.chkGeneralFont = ELib:Check(self.optColSet.superTabFrame.tab[4],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].fontGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].fontGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)	
	function self.optColSet.chkGeneralFont:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].fontGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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 = ELib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextLeft..":"):Size(200,20):Point(10,-40)
	self.optColSet.textLeftTemEdit = ELib:Edit(self.optColSet.superTabFrame.tab[5]):Size(220,20):Point(180,-40):OnChange(function(self,isUser)
		if isUser then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textTemplateLeft = self:GetText()
			module:ReloadAllSplits()
		end
	end)
	
	self.optColSet.textRightTemText = ELib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextRight..":"):Size(200,20):Point(10,-65)
	self.optColSet.textRightTemEdit = ELib:Edit(self.optColSet.superTabFrame.tab[5]):Size(220,20):Point(180,-65):OnChange(function(self,isUser)
		if isUser then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textTemplateRight = self:GetText()
			module:ReloadAllSplits()
		end
	end)
	
	self.optColSet.textCenterTemText = ELib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextCenter..":"):Size(200,20):Point(10,-90)
	self.optColSet.textCenterTemEdit = ELib:Edit(self.optColSet.superTabFrame.tab[5]):Size(220,20):Point(180,-90):OnChange(function(self,isUser)
		if isUser then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textTemplateCenter = self:GetText()
			module:ReloadAllSplits()
		end
	end)
	
	self.optColSet.textAllTemplates = ELib:Text(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextTooltip,11):Size(450,200):Point(10,-115):Top():Color()

	self.optColSet.textResetButton = ELib:Button(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextReset):Size(340,20):Point("TOP",0,-225):OnClick(function(self)
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textTemplateLeft = nil
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textTemplateRight = nil
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].textTemplateCenter = nil
		module:ReloadAllSplits()
		module.options.optColSet.textLeftTemEdit:SetText(module.db.colsDefaults.textTemplateLeft)
		module.options.optColSet.textRightTemEdit:SetText(module.db.colsDefaults.textTemplateRight)
		module.options.optColSet.textCenterTemEdit:SetText(module.db.colsDefaults.textTemplateCenter)
	end)
	
	self.optColSet.chkIconName = ELib:Check(self.optColSet.superTabFrame.tab[5],L.cd2ColSetTextIconName):Point(10,-250):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textIconName = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textIconName = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneralText = ELib:Check(self.optColSet.superTabFrame.tab[5],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].textGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralText:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].textGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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 = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetOnlyOnCD):Point(10,-30):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsShownOnCD = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsShownOnCD = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkBotToTop = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetBotToTop):Point(10,-55):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameAnchorBottom = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].frameAnchorBottom = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.textStyleAnimation = ELib:Text(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetStyleAnimation..":",11):Size(200,20):Point(10,-80)
	self.optColSet.dropDownStyleAnimation = ELib: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)
				ELib:DropDownClose()
				VExRT.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 = ELib:Text(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetTimeLineAnimation..":",11):Size(200,20):Point(10,-105)
	self.optColSet.dropDownTimeLineAnimation = ELib: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)
				ELib:DropDownClose()
				VExRT.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 = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetIconToolip):Point(10,-130):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsIconTooltip = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsIconTooltip = nil
		end
		module:ReloadAllSplits()
	end)
		
	self.optColSet.chkLineClick = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2OtherSetLineClick):Point(10,-155):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsLineClick = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsLineClick = nil
		end
		module:ReloadAllSplits()
	end)
	
	
	self.optColSet.chkNewSpellNewLine = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2NewSpellNewLine):Point(10,-180):Tooltip(L.cd2NewSpellNewLineTooltip):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsNewSpellNewLine = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsNewSpellNewLine = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.textSortingRules= ELib:Text(self.optColSet.superTabFrame.tab[6],L.cd2MethodsSortingRules..":",11):Size(200,20):Point(10,-205)
	self.optColSet.dropDownSortingRules = ELib:DropDown(self.optColSet.superTabFrame.tab[6],405,6):Size(220):Point(180,-205)
	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)
				ELib:DropDownClose()
				VExRT.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 = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2MethodsDisableOwn):Point(10,-230):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsHideOwnSpells = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsHideOwnSpells = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkAlphaNotInRange = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2MethodsAlphaNotInRange):Point(10,-255):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsAlphaNotInRange = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsAlphaNotInRange = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.sliderAlphaNotInRange = ELib:Slider(self.optColSet.superTabFrame.tab[6],""):Size(140):Point("TOPLEFT",self.optColSet.chkAlphaNotInRange,270,-3):Range(0,100):OnChange(function(self,event) 
		event = event - event%1
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsAlphaNotInRangeNum = event
		module:ReloadAllSplits()
		self.tooltipText = event
		self:tooltipReload(self)
	end)
	
	self.optColSet.chkDisableActive = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetDisableActive):Point(10,-280):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsDisableActive = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsDisableActive = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkOneSpellPerCol = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetOneSpellPerCol):Point(10,-305):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsOneSpellPerCol = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsOneSpellPerCol = nil
		end
		module:ReloadAllSplits()
	end):Tooltip(L.cd2ColSetOneSpellPerColTooltip)
	
	self.optColSet.chkGeneralMethods = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralMethods:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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)
	end
	
	self.optColSet.chkSortByAvailability = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2SortByAvailability,VExRT.ExCD2.SortByAvailability):Point(10,-330):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.SortByAvailability = true
		else
			VExRT.ExCD2.SortByAvailability = nil
			module.main:GROUP_ROSTER_UPDATE()
		end
	end)
	
	self.optColSet.chkSortByAvailability_activeToTop = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2SortByAvailabilityActiveToTop,VExRT.ExCD2.SortByAvailabilityActiveToTop):Point("TOPLEFT",self.optColSet.chkSortByAvailability,0,-25):Tooltip(L.cd2SortByAvailabilityActiveToTopTooltip):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.SortByAvailabilityActiveToTop = true
		else
			VExRT.ExCD2.SortByAvailabilityActiveToTop = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkReverseSorting = ELib:Check(self.optColSet.superTabFrame.tab[6],L.cd2ReverseSorting,VExRT.ExCD2.ReverseSorting):Point("TOPLEFT",self.optColSet.chkSortByAvailability_activeToTop,0,-25):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.ReverseSorting = true
		else
			VExRT.ExCD2.ReverseSorting = nil
		end
		module:ReloadAllSplits()
	end)

	--> Visibility
	
	
	self.optColSet.chkOnlyInCombat = ELib:Check(self.optColSet.superTabFrame.tab[7],L.TimerOnlyInCombat):Point(10,-30):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsOnlyInCombat = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].methodsOnlyInCombat = nil
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.visibilityTextPartyType = ELib:Text(self.optColSet.superTabFrame.tab[7],L.cd2OtherVisibilityPartyType..":",10):Point(10,-60):Color()
	
	self.optColSet.chkVisibilityPartyTypeAlways = ELib: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)
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityPartyType = nil
		module:ReloadAllSplits()
	end)
	self.optColSet.chkVisibilityPartyTypeParty = ELib: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)
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityPartyType = 1
		module:ReloadAllSplits()
	end)
	self.optColSet.chkVisibilityPartyTypeRaid = ELib: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)
		VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityPartyType = 2
		module:ReloadAllSplits()
	end)
	
	self.optColSet.visibilityTextZoneType = ELib:Text(self.optColSet.superTabFrame.tab[7],L.cd2OtherVisibilityZoneType..":",10):Point(10,-140):Color()
	
	self.optColSet.chkVisibilityZoneArena = ELib:Check(self.optColSet.superTabFrame.tab[7],ARENA):Point(10,-155):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableArena = nil
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableArena = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneBG = ELib:Check(self.optColSet.superTabFrame.tab[7],BATTLEGROUND):Point(10,-180):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableBG = nil
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableBG = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneScenario = ELib:Check(self.optColSet.superTabFrame.tab[7],TRACKER_HEADER_SCENARIO):Point(10,-205):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable3ppl = nil
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable3ppl = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZone5ppl = ELib:Check(self.optColSet.superTabFrame.tab[7],CALENDAR_TYPE_DUNGEON):Point(10,-230):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable5ppl = nil
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisable5ppl = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneRaid = ELib:Check(self.optColSet.superTabFrame.tab[7],RAID):Point(10,-255):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableRaid = nil
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableRaid = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkVisibilityZoneOutdoor = ELib:Check(self.optColSet.superTabFrame.tab[7],WORLD):Point(10,-280):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableWorld = nil
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityDisableWorld = true
		end
		module:ReloadAllSplits()
	end)
	
	self.optColSet.chkGeneralVisibility = ELib:Check(self.optColSet.superTabFrame.tab[7],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralVisibility:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].visibilityGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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 = ELib:Text(self.optColSet.superTabFrame.tab[8],L.cd2ColSetBlacklistTooltip,11):Size(430,200):Point(10,-30):Top():Color()
	
	self.optColSet.blacklistEditBox = ELib:MultiEdit(self.optColSet.superTabFrame.tab[8]):Size(430,140):Point("TOP",0,-85)
	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
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].blacklistText = strtrim( self:GetText() )
			if not scheluded then
				scheluded = ExRT.F.ScheduleTimer(ScheludeFunc, 1)
			end
		end
	end

	self.optColSet.whitelistText = ELib:Text(self.optColSet.superTabFrame.tab[8],L.cd2ColSetWhitelistTooltip,11):Size(430,200):Point(10,-235):Top():Color()
	
	self.optColSet.whitelistEditBox = ELib:MultiEdit(self.optColSet.superTabFrame.tab[8]):Size(430,140):Point("TOP",0,-290)
	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
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].whitelistText = strtrim( self:GetText() )
			if not scheluded then
				scheluded = ExRT.F.ScheduleTimer(ScheludeFunc, 1)
			end
		end
	end
		
	self.optColSet.chkGeneralBlackList = ELib:Check(self.optColSet.superTabFrame.tab[8],L.cd2ColSetGeneral):Point("TOPRIGHT",-10,-10):Left():OnClick(function(self) 
		if self:GetChecked() then
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].blacklistGeneral = true
		else
			VExRT.ExCD2.colSet[module.options.optColTabs.selected].blacklistGeneral = nil
		end
		module:ReloadAllSplits()
		self:doAlphas()
	end)
	function self.optColSet.chkGeneralBlackList:doAlphas()
		ExRT.lib.SetAlphas(VExRT.ExCD2.colSet[module.options.optColTabs.selected].blacklistGeneral and module.options.optColTabs.selected ~= (module.db.maxColumns + 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 = ExRT.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = ExRT.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 = ExRT.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = ExRT.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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = ExRT.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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = false,
			textureFile = ExRT.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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = true,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = true,
			fontShadow = false,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ExRT.F.defFont,
			fontOutline = false,
			fontShadow = true,
			textureFile = "Interface\\AddOns\\ExRT\\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 = ELib:ScrollFrame(self.optColSet.superTabFrame.tab[9]):Size(430,380):Point("TOP",0,-50):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 = ExRT.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 = {}
		  	ExRT.F.table_copy(VExRT.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
		  					VExRT.ExCD2.colSet[module.options.optColTabs.selected][val] = module.options.optColSet.templateData[i][key2]
		  				elseif key2 == "frameWidth" then
		  					VExRT.ExCD2.colSet[module.options.optColTabs.selected][val] = max(110,VExRT.ExCD2.colSet[module.options.optColTabs.selected][val] or 110)
		  				end
		  			elseif val:find("General") then
		  				VExRT.ExCD2.colSet[module.options.optColTabs.selected][val] = nil
		  			else
		  				VExRT.ExCD2.colSet[module.options.optColTabs.selected][val] = module.options.optColSet.templateData[i][key]
		  			end
		  		else
		  			for k=1,#val do
		  				VExRT.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.colsDefaults.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 = ExRT.F.Round( ((j-1) - inLine) / self.optColSet.templateData[i].frameColumns )
				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)
			
			local spellClass = DiffSpellData and DiffSpellData.spellsClass[j] or self.optColSet.templateData.spellsClass[j]
		
			bar.data = {
				name = ExRT.SDB.charName,
				fullName = ExRT.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.notAClass,
				
				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("TOP",0,-10)
	self.optColSet.templateRestore:SetSize(430,30)
	self.optColSet.templateRestore:SetBackdrop({edgeFile = ExRT.F.defBorder, edgeSize = 8})
	self.optColSet.templateRestore:SetBackdropBorderColor(1,0.5,0.5,1)
	self.optColSet.templateRestore.text = ELib: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)
		VExRT.ExCD2.colSet[module.options.optColTabs.selected] = {}
		ExRT.F.table_copy(module.options.optColSet.templateSaveData,VExRT.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.maxColumns+1
		module.options.tab.tabs[2]:SetScript("OnShow",function ()
			module.options.selectColumnTab(self.optColTabs.tabs[module.db.maxColumns+1].button)
			module.options.tab.tabs[2]:SetScript("OnShow",nil)
		end)
	end	
	
	--> Other setts
	self.optSetTab = ELib:OneTab(self.tab.tabs[2],L.cd2OtherSet):Size(652,34):Point("TOP",0,-532)
	
	self.chkSplit = ELib:Check(self.optSetTab,L.cd2split,VExRT.ExCD2.SplitOpt):Point("LEFT",10,0):Tooltip(L.cd2splittooltip):OnClick(function(self,event)
		if self:GetChecked() then
			VExRT.ExCD2.SplitOpt = true
		else
			VExRT.ExCD2.SplitOpt = nil
		end
		module:SplitExCD2Window()
		module:ReloadAllSplits()
	end)
	
	self.chkNoRaid = ELib:Check(self.optSetTab,L.cd2noraid,VExRT.ExCD2.NoRaid):Point("LEFT",165,0):OnClick(function(self,event)
		if self:GetChecked() then
			VExRT.ExCD2.NoRaid = true
		else
			VExRT.ExCD2.NoRaid = nil
		end
		UpdateRoster()
	end)
	
	self.testMode = ELib:Check(self.optSetTab,L.cd2GeneralSetTestMode,module.db.testMode):Point("LEFT",325,0):Tooltip(L.cd2HelpTestButton):OnClick(function(self,event)
		if self:GetChecked() then
			module.db.testMode = true
		else
			module.db.testMode = nil
			TestMode(1)
		end
		UpdateRoster()
	end)

	self.butResetToDef = ELib:Button(self.optSetTab,L.cd2OtherSetReset):Size(160,20):Point("LEFT",480,0):Tooltip(L.cd2HelpButtonDefault):OnClick(function()
		StaticPopupDialogs["EXRT_EXCD_DEFAULT"] = {
			text = L.cd2OtherSetReset,
			button1 = L.YesText,
			button2 = L.NoText,
			OnAccept = function()
				table_wipe2(VExRT.ExCD2.colSet[module.options.optColTabs.selected])
				for optName,optVal in pairs(module.db.colsInit) do
					VExRT.ExCD2.colSet[module.options.optColTabs.selected][optName] = optVal
				end
				VExRT.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("EXRT_EXCD_DEFAULT")
	end) 
	
	
	
	--> OPTIONS TAB3: History
	self.butHistoryClear = ELib:Button(self.tab.tabs[3],L.cd2HistoryClear):Size(180,20):Point("TOPRIGHT",-3,-6):OnClick(function()
		table_wipe2(module.db.historyUsage)
		module.options.historyBox.EditBox:SetText("")
	end)
	
	local historyBoxUpdateTable = {}
	local function historyBoxUpdate(v)
		table_wipe2(historyBoxUpdateTable)
		local count = 0
		for i=1,#module.db.historyUsage do
			if VExRT.ExCD2.CDE[module.db.historyUsage[i][2]] then
				count = count + 1
			end
			if count >= v and VExRT.ExCD2.CDE[module.db.historyUsage[i][2]] then
				local tm = date("%X",module.db.historyUsage[i][1])
				local bosshpstr = module.db.historyUsage[i][4] and format(" (%d:%.2d)",module.db.historyUsage[i][4]/60,module.db.historyUsage[i][4]%60) or ""
				local spellName,_,spellIcon = GetSpellInfo(module.db.historyUsage[i][2])
				historyBoxUpdateTable [#historyBoxUpdateTable + 1] = format("|cffffff00[%s]%s|r %s |Hspell:%d|h|T%s:0|t%s|h",tm,bosshpstr,module.db.historyUsage[i][3] or "?",module.db.historyUsage[i][2] or 0,spellIcon or "Interface\\Icons\\Trade_Engineering",spellName or "?")
			end
			if #historyBoxUpdateTable > 44 then
				break
			end
		end
		module.options.historyBox.EditBox:SetText(strjoin("\n",unpack(historyBoxUpdateTable)))
	end
	
	self.historyBox = ELib:MultiEdit2(self.tab.tabs[3]):Size(652,530):Point("TOP",0,-36):Hyperlinks()
	self.historyBox.EditBox:SetScript("OnShow",function(self)
		historyBoxUpdate(1)
		local count = 0
		for i=1,#module.db.historyUsage do
			if VExRT.ExCD2.CDE[module.db.historyUsage[i][2]] then
				count = count + 1
			end
		end
		module.options.historyBox.ScrollBar:SetMinMaxValues(1,max(count,1))
		module.options.historyBox.ScrollBar:UpdateButtons()
	end)
	self.historyBox.ScrollBar:SetScript("OnValueChanged",function (self,val)
		val = ExRT.F.Round(val)
		historyBoxUpdate(val)
		self:UpdateButtons()
	end)
	
	self.HelpPlate = {
		[1] = {
			FramePos = { x = 0, y = 0 },FrameSize = { width = 660, height = 615 },
			[1] = { ButtonPos = { x = 500,	y = -40 },  	HighLightBox = { x = 485, y = -50, width = 170, height = 25 },		ToolTipDir = "LEFT",	ToolTipText = L.cd2HelpFastSetup },
			[2] = { ButtonPos = { x = 0,  y = -135 }, 	HighLightBox = { x = 7, y = -85, width = 34, height = 495 },		ToolTipDir = "RIGHT",	ToolTipText = L.cd2HelpOnOff },
			[3] = { ButtonPos = { x = 250,  y = -135 }, 	HighLightBox = { x = 225, y = -85, width = 150, height = 495 },		ToolTipDir = "DOWN",	ToolTipText = L.cd2HelpCol },
			[4] = { ButtonPos = { x = 375,  y = -135},  	HighLightBox = { x = 380, y = -85, width = 85, height = 495 },		ToolTipDir = "DOWN",	ToolTipText = L.cd2HelpPriority },
			[5] = { ButtonPos = { x = 470,  y = -135 },  	HighLightBox = { x = 465, y = -85, width = 165, height = 495 },		ToolTipDir = "LEFT",	ToolTipText = L.cd2HelpTime },
			[6] = { ButtonPos = { x = 370,  y = -570 },  	HighLightBox = { x = 7, y = -580, width = 625, height = 30 },		ToolTipDir = "UP",	ToolTipText = L.cd2HelpAddButton },
		},
		[2] = {
			FramePos = { x = 0, y = 0 },FrameSize = { width = 660, height = 615 },
			[1] = { ButtonPos = { x = 50,	y = -130 },  	HighLightBox = { x = 0, y = -70, width = 660, height = 480 },		ToolTipDir = "RIGHT",	ToolTipText = L.cd2HelpColSetup },
			[2] = { ButtonPos = { x = 320,	y = -570 },  	HighLightBox = { x = 315, y = -580, width = 140, height = 30 },		ToolTipDir = "LEFT",	ToolTipText = L.cd2HelpTestButton },
			[3] = { ButtonPos = { x = 500,	y = -570 },  	HighLightBox = { x = 490, y = -580, width = 160, height = 30 },		ToolTipDir = "LEFT",	ToolTipText = L.cd2HelpButtonDefault },
		},
		[3] = {
			FramePos = { x = 0, y = 0 },FrameSize = { width = 660, height = 615 },
			[1] = { ButtonPos = { x = 310,	y = -50 },  	HighLightBox = { x = 0, y = -50, width = 660, height = 565 },		ToolTipDir = "DOWN",	ToolTipText = L.cd2HelpHistory },		
		}
	}
	self.HELPButton = ExRT.lib.CreateHelpButton(self,self.HelpPlate,self.tab)
	self.HELPButton:SetPoint("CENTER",self,"TOPLEFT",0,15)
	
	function self.HELPButton:Click2()
		local min,max=module.options.ScrollBar:GetMinMaxValues()
		module.options.ScrollBar:SetValue(max)
	end
end

function module.options:CleanUPVariables()
	local cleanUP = {}
	for sett,col in pairs(VExRT.ExCD2.CDECol) do
		local bool = nil
		for i=1,#module.db.spellDB do
			for j=3,7 do
				if module.db.spellDB[i][j] then
					if tonumber( string.gsub(sett,";%d",""),nil ) == module.db.spellDB[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
		VExRT.ExCD2.CDECol[cleanUP[i]] = nil
	end
	table_wipe2(cleanUP)
	for sid,val in pairs(VExRT.ExCD2.CDE) do
		local bool = nil
		for i=1,#module.db.spellDB do
			if sid == module.db.spellDB[i][1] then
				bool = true
			end
		end
		if not bool then
			cleanUP [#cleanUP + 1] = sid
		end
	end
	for i=1,#cleanUP do
		VExRT.ExCD2.CDE[cleanUP[i]] = nil
	end
	table_wipe2(cleanUP)
	for sid,val in pairs(VExRT.ExCD2.Priority) do
		local bool = nil
		for i=1,#module.db.spellDB do
			if sid == module.db.spellDB[i][1] then
				bool = true
			end
		end
		if not bool then
			cleanUP [#cleanUP + 1] = sid
		end
	end
	for i=1,#cleanUP do
		VExRT.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 VExRT_ColumnOptions = VExRT.ExCD2.colSet
	local Width = 0
	local maxHeight = 0
	local maxLine = VExRT_ColumnOptions[module.db.maxColumns+1].frameLines or module.db.colsDefaults.frameLines
	local maxBetweenLines = 0
	if VExRT_ColumnOptions[module.db.maxColumns+1].frameColumns then
		maxLine = ceil(maxLine / VExRT_ColumnOptions[module.db.maxColumns+1].frameColumns)
	end	

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

		local frameColumns = (not VExRT_ColumnOptions[i].frameGeneral and VExRT_ColumnOptions[i].frameColumns) or (VExRT_ColumnOptions[i].frameGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].frameColumns) or module.db.colsDefaults.frameColumns
		columnFrame.frameColumns = frameColumns
		local linesShown = (not VExRT_ColumnOptions[i].frameGeneral and VExRT_ColumnOptions[i].frameLines) or (VExRT_ColumnOptions[i].frameGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].frameLines) or module.db.colsDefaults.frameLines	
		linesShown = ceil(linesShown / frameColumns)
		local linesTotal = linesShown * frameColumns
		if VExRT.ExCD2.SplitOpt then 
			columnFrame:SetHeight(columnFrame.iconSize*linesShown+frameBetweenLines*(linesShown-1)) 
		else
			columnFrame:SetHeight(columnFrame.iconSize*linesShown)
			if VExRT_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.maxLinesInCol
		
		if VExRT_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 VExRT_ColumnOptions[i].frameGeneral and VExRT_ColumnOptions[i].frameAlpha) or (VExRT_ColumnOptions[i].frameGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].frameAlpha) or module.db.colsDefaults.frameAlpha
		columnFrame:SetAlpha(frameAlpha/100) 

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

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

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

		columnFrame.textureBorderColorR = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureBorderColorR) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureBorderColorR) or module.db.colsDefaults.textureBorderColorR
		columnFrame.textureBorderColorG = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureBorderColorG) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureBorderColorG) or module.db.colsDefaults.textureBorderColorG
		columnFrame.textureBorderColorB = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureBorderColorB) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureBorderColorB) or module.db.colsDefaults.textureBorderColorB
		columnFrame.textureBorderColorA = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureBorderColorA) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureBorderColorA) or module.db.colsDefaults.textureBorderColorA

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

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

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

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

		columnFrame.fontIconSize = (not fontOtherAvailable and columnFrame.fontSize) or (not VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[i].fontIconSize) or (VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].fontIconSize) or module.db.colsDefaults.fontSize
		columnFrame.fontIconName = (not fontOtherAvailable and columnFrame.fontName) or (not VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[i].fontIconName) or (VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].fontIconName) or module.db.colsDefaults.fontName
		columnFrame.fontIconOutline = (not fontOtherAvailable and columnFrame.fontOutline) or (fontOtherAvailable and ((not VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[i].fontIconOutline) or (VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].fontIconOutline)))
		columnFrame.fontIconShadow = (not fontOtherAvailable and columnFrame.fontShadow) or (fontOtherAvailable and ((not VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[i].fontIconShadow) or (VExRT_ColumnOptions[i].fontGeneral and VExRT_ColumnOptions[module.db.maxColumns+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 VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i]["textureColor"..object..state.."R"]) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1]["textureColor"..object..state.."R"]) or module.db.colsDefaults["textureColor"..object..state.."R"]
				columnFrame["optionColor"..object..state].g = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i]["textureColor"..object..state.."G"]) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1]["textureColor"..object..state.."G"]) or module.db.colsDefaults["textureColor"..object..state.."G"]
				columnFrame["optionColor"..object..state].b = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i]["textureColor"..object..state.."B"]) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1]["textureColor"..object..state.."B"]) or module.db.colsDefaults["textureColor"..object..state.."B"]
			end
		end

		columnFrame.optionAlphaBackground = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureAlphaBackground) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureAlphaBackground) or module.db.colsDefaults.textureAlphaBackground
		columnFrame.optionAlphaTimeLine = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureAlphaTimeLine) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureAlphaTimeLine) or module.db.colsDefaults.textureAlphaTimeLine
		columnFrame.optionAlphaCooldown = (not VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[i].textureAlphaCooldown) or (VExRT_ColumnOptions[i].textureGeneral and VExRT_ColumnOptions[module.db.maxColumns+1].textureAlphaCooldown) or module.db.colsDefaults.textureAlphaCooldown

		if VExRT_ColumnOptions[i].enabled then
			for n=1,linesTotal do
				columnFrame.lines[n]:UpdateStyle()
				if columnFrame.lines[n]:IsVisible() then
					columnFrame.lines[n]:UpdateStatus()
				end
			end
		
			local frameAnchorBottom = (not VExRT_ColumnOptions[i].methodsGeneral and VExRT_ColumnOptions[i].frameAnchorBottom) or (VExRT_ColumnOptions[i].methodsGeneral and VExRT_ColumnOptions[module.db.maxColumns+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 = ExRT.F.Round( ((n-1) - inLine) / frameColumns )
					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 VExRT_ColumnOptions[i].enabled and VExRT.ExCD2.enabled then
			columnFrame.optionIsEnabled = true
			columnFrame:Show()
		else
			columnFrame.optionIsEnabled = nil
			columnFrame:Hide()
		end
		if not VExRT.ExCD2.SplitOpt then
			columnFrame:ClearAllPoints()
			columnFrame:SetPoint("TOPLEFT",module.frame,Width, 0)
		else
			if VExRT_ColumnOptions[i].posX and VExRT_ColumnOptions[i].posY then
				columnFrame:ClearAllPoints()
				columnFrame:SetPoint("TOPLEFT",UIParent,"BOTTOMLEFT",VExRT_ColumnOptions[i].posX,VExRT_ColumnOptions[i].posY)
			else
				columnFrame:ClearAllPoints()
				columnFrame:SetPoint("CENTER",UIParent,"CENTER",0,0)
			end
		end
		if VExRT_ColumnOptions[i].enabled then
			Width = Width + frameWidth*frameColumns
		end
	end
	module.frame:SetWidth(Width)
	module.frame:SetHeight(maxHeight*maxLine + maxBetweenLines)
	module.frame:SetAlpha((VExRT_ColumnOptions[module.db.maxColumns+1].frameAlpha or module.db.colsDefaults.frameAlpha)/100)
	if argScaleFix == "ScaleFix" then
		ExRT.F.SetScaleFix(module.frame,(VExRT_ColumnOptions[module.db.maxColumns+1].frameScale or module.db.colsDefaults.frameScale)/100)
	else
		module.frame:SetScale((VExRT_ColumnOptions[module.db.maxColumns+1].frameScale or module.db.colsDefaults.frameScale)/100) 
	end
	
	module:updateCombatVisibility()
	
 	SortAllData()
 	UpdateAllData()
end

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

			if not VExRT.ExCD2.lock then 
				ExRT.F.LockMove(module.frame.colFrame[i],true,module.frame.colFrame[i].lockTexture)
				ExRT.lib.AddShadowComment(module.frame.colFrame[i],nil,L.cd2,i,72,"OUTLINE")
			end
		end
		module.frame:Hide()
	else
		for i=1,module.db.maxColumns do 
			module.frame.colFrame[i]:SetParent(module.frame)
			ExRT.F.LockMove(module.frame.colFrame[i],nil,module.frame.colFrame[i].lockTexture)
			ExRT.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.cdsNav[name][sid]
			if j then
				j[3] = 0
			end
		end
	end
end

module.db.AllClassSpellsInText = [[
--16:38 18.07.2016, Build 22248 Pre-patch
local module = GExRT.A.ExCD2
module.db.allClassSpells = {
["WARRIOR"] = {
	{107574,3,	{107574,90,	20},	nil,			nil,			nil,			},	--Аватара
	{184364,4,	nil,			nil,			{184364,120,	8},	nil,			},	--Безудержное восстановление
	{2565,	4,	nil,			nil,			nil,			{2565,	13,	6},	},	--Блок щитом
	{1719,	3,	{1719,	60,	5},	nil,			nil,			nil,			},	--Боевой крик
	{118038,4,	nil,			{118038,180,	8},	nil,			nil,			},	--Бой насмерть
	{202168,4,	nil,			nil,			nil,			{202168,30,	0},	},	--Верная победа
	{46924,	3,	nil,			nil,			{46924,	90,	6},	nil,			},	--Вихрь клинков
	{227847,3,	nil,			{227847,90,	6},	nil,			nil,			},	--Вихрь клинков
	{6544,	4,	{52174,	45,	0},	nil,			nil,			nil,			},	--Героический прыжок
	{871,	4,	nil,			nil,			nil,			{871,	240,	8},	},	--Глухая оборона
	{1160,	4,	nil,			nil,			nil,			{1160,	90,	8},	},	--Деморализующий крик
	{6552,	5,	{6552,	15,	0},	nil,			nil,			nil,			},	--Зуботычина
	{12292,	3,	nil,			nil,			{12292,	30,	10},	nil,			},	--Кровавая баня
	{213915,1,	nil,			nil,			nil,			{213915,30,	0},	},	--Массовое отражение заклинания
	{209577,3,	nil,			{209577,60,	0},	nil,			nil,			},	--Миротворец
	{12975,	4,	nil,			nil,			nil,			{12975,	180,	15},	},	--Ни шагу назад
	{97462,	3,	nil,			{97462,	180,	10},	{97462,	180,	10},	nil,			},	--Ободряющий клич
	{197690,4,	nil,			{197690,10,	0},	nil,			nil,			},	--Оборонительная стойка
	{152277,3,	nil,			{152277,60,	6.5},	nil,			nil,			},	--Опустошитель
	{228920,3,	nil,			nil,			nil,			{228920,60,	6.5},	},	--Опустошитель
	{23920,	4,	nil,			nil,			nil,			{23920,	25,	5},	},	--Отражение заклинания
	{198304,2,	nil,			nil,			nil,			{198304,15,	10},	},	--Перехват
	{355,	5,	{355,	8,	0},	nil,			nil,			nil,			},	--Провокация
	{118000,3,	nil,			nil,			{118000,25,	0},	nil,			},	--Рев дракона
	{100,	3,	{100,	20,	0},	nil,			nil,			nil,			},	--Рывок
	{107570,3,	{107570,30,	0},	nil,			nil,			nil,			},	--Удар громовержца
	{167105,3,	nil,			{167105,45,	8},	nil,			nil,			},	--Удар колосса
	{46968,	1,	{46968,	40,	0},	nil,			nil,			nil,			},	--Ударная волна
	{5246,	3,	nil,			{5246,	90,	0},	{5246,	90,	0},	nil,			},	--Устрашающий крик
	{203524,4,	nil,			nil,			nil,			{203524,45,	3},	},	--Ярость Нелтариона
	{205546,3,	nil,			nil,			{205546,45,	0},	nil,			},	--Ярость Одина
	{18499,	3,	{18499,	60,	6},	nil,			nil,			nil,			},	--Ярость берсерка
},
["PALADIN"] = {
	{204035,4,	nil,			nil,			{204035,180,	0},	nil,			},	--Бастион Света
	{1022,	2,	{1022,	300,	10},	nil,			nil,			nil,			},	--Благословение защиты
	{204018,2,	nil,			nil,			{204018,180,	10},	nil,			},	--Благословение защиты от заклинаний
	{1044,	2,	{1044,	25,	8},	nil,			nil,			nil,			},	--Благословенная свобода
	{498,	4,	nil,			{498,	60,	8},	{498,	60,	8},	nil,			},	--Божественная защита
	{114165,3,	nil,			{114165,20,	0},	nil,			nil,			},	--Божественная призма
	{190784,3,	{190784,45,	3},	nil,			nil,			nil,			},	--Божественный скакун
	{642,	4,	{642,	300,	8},	nil,			nil,			nil,			},	--Божественный щит
	{214202,3,	nil,			{214202,30,	10},	nil,			nil,			},	--Верховенство закона
	{31821,	1,	nil,			{31821,	180,	6},	nil,			nil,			},	--Владение аурами
	{633,	2,	{633,	600,	0},	nil,			nil,			nil,			},	--Возложение рук
	{31884,	3,	nil,			nil,			{31884,	120,	20},	{31884,	120,	20},	},	--Гнев карателя
	{31842,	1,	nil,			{31842,	120,	20},	nil,			nil,			},	--Гнев карателя
	{210220,3,	nil,			nil,			nil,			{210220,180,	0},	},	--Гнев небес
	{223306,3,	nil,			{223306,12,	5},	nil,			nil,			},	--Дарование веры
	{62124,	5,	{62124,	8,	0},	nil,			nil,			nil,			},	--Длань расплаты
	{6940,	2,	nil,			{6940,	150,	0},	{6940,	150,	0},	nil,			},	--Жертвенное благословление
	{86659,	4,	nil,			nil,			{86659,	300,	8},	nil,			},	--Защитник древних королей
	{200652,3,	nil,			{200652,90,	0},	nil,			nil,			},	--Избавление Тира
	{205273,3,	nil,			nil,			nil,			{205273,30,	0},	},	--Испепеляющий след
	{114158,3,	nil,			{114158,60,	14},	nil,			nil,			},	--Молот Света
	{853,	3,	{853,	60,	0},	nil,			nil,			nil,			},	--Молот правосудия
	{209202,4,	nil,			nil,			{209202,60,	0},	nil,			},	--Око Тира
	{205191,4,	nil,			nil,			nil,			{205191,60,	10},	},	--Око за око
	{4987,	5,	nil,			{4987,	8,	0},	{213644,8,	0},	{213644,8,	0},	},	--Очищение
	{20066,	3,	{20066,	15,	0},	nil,			nil,			nil,			},	--Покаяние
	{183218,3,	nil,			nil,			nil,			{183218,30,	10},	},	--Преграждающая длань
	{31850,	4,	nil,			nil,			{31850,	120,	8},	nil,			},	--Ревностный защитник
	{85222,	3,	nil,			{85222,	12,	0},	nil,			nil,			},	--Свет зари
	{184092,3,	nil,			nil,			{184092,15,	0},	nil,			},	--Свет защитника
	{105809,3,	nil,			{105809,90,	20},	nil,			nil,			},	--Святой каратель
	{224668,3,	nil,			nil,			nil,			{224668,120,	20},	},	--Священная война
	{152262,3,	nil,			nil,			{152262,30,	16},	nil,			},	--Серафим
	{115750,3,	{115750,90,	6},	nil,			nil,			nil,			},	--Слепящий свет
	{213757,3,	nil,			nil,			nil,			{213757,20,	6.5},	},	--Смертный приговор
	{210191,3,	nil,			nil,			nil,			{210191,60,	0},	},	--Торжество
	{96231,	5,	nil,			nil,			{96231,	15,	0},	{96231,	15,	0},	},	--Укор
	{200025,3,	nil,			{200025,15,	8},	nil,			nil,			},	--Частица добродетели
	{184662,4,	nil,			nil,			nil,			{184662,120,	15},	},	--Щит мстителя
	{204150,1,	nil,			nil,			{204150,300,	6},	nil,			},	--Эгида Света
},
["HUNTER"] = {
	{191241,3,	nil,			nil,			nil,			{191241,30,	3},	},	--Бомба-липучка
	{191433,3,	nil,			nil,			nil,			{191433,30,	0},	},	--Взрывная ловушка
	{186387,3,	nil,			nil,			{186387,30,	0},	nil,			},	--Взрывной выстрел
	{147362,5,	nil,			{147362,24,	0},	{147362,24,	0},	{187707,15,	0},	},	--Встречный выстрел
	{190925,3,	nil,			nil,			nil,			{190925,20,	0},	},	--Гарпун
	{194855,3,	nil,			nil,			nil,			{194855,30,	8},	},	--Граната пламени дракона
	{207068,3,	nil,			{207068,60,	0},	nil,			nil,			},	--Гром титанов
	{186257,4,	{186257,180,	12},	nil,			nil,			nil,			},	--Дух гепарда
	{193530,3,	nil,			{193530,120,	10},	nil,			nil,			},	--Дух дикой природы
	{186289,3,	nil,			nil,			nil,			{186289,120,	10},	},	--Дух орла
	{186265,4,	{186265,180,	8},	nil,			nil,			nil,			},	--Дух черепахи
	{194291,4,	nil,			nil,			{194291,120,	0},	nil,			},	--Живость
	{109304,4,	nil,			{109304,120,	0},	nil,			{109304,120,	0},	},	--Живость
	{187650,3,	nil,			nil,			nil,			{187650,30,	0},	},	--Замораживающая ловушка
	{19574,	3,	nil,			{19574,	90,	15},	nil,			nil,			},	--Звериный гнев
	{201430,3,	nil,			{201430,180,	12},	nil,			nil,			},	--Звериный натиск
	{199483,4,	nil,			nil,			{199483,60,	60},	{199483,60,	60},	},	--Камуфляж
	{162488,3,	nil,			nil,			nil,			{162488,60,	0},	},	--Капкан
	{5116,	3,	nil,			{5116,	5,	6},	{5116,	5,	6},	nil,			},	--Контузящий выстрел
	{136,	3,	{136,	10,	0},	nil,			nil,			nil,			},	--Лечение питомца
	{209997,3,	{209997,30,	0},	nil,			nil,			nil,			},	--Ложная смерть
	{193526,3,	nil,			nil,			{193526,180,	15},	nil,			},	--Меткий выстрел
	{1543,	3,	{1543,	20,	0},	nil,			nil,			nil,			},	--Осветительная ракета
	{781,	4,	{781,	20,	0},	nil,			nil,			nil,			},	--Отрыв
	{201078,3,	nil,			nil,			nil,			{201078,90,	0},	},	--Охотник на змей
	{34477,	3,	nil,			{34477,	30,	8},	{34477,	30,	8},	nil,			},	--Перенаправление
	{194407,3,	nil,			nil,			nil,			{194407,60,	0},	},	--Плюющаяся кобра
	{5384,	4,	{5384,	30,	0},	nil,			nil,			nil,			},	--Притвориться мертвым
	{210000,3,	{210000,30,	0},	nil,			nil,			nil,			},	--Пробуждение
	{198670,3,	nil,			nil,			{198670,30,	0},	nil,			},	--Пронзающий выстрел
	{212431,3,	nil,			nil,			{212431,30,	0},	nil,			},	--Разрывной выстрел
	{185855,3,	nil,			nil,			nil,			{185855,10,	0},	},	--Режущий удар
	{109248,3,	nil,			{109248,45,	0},	{109248,45,	0},	nil,			},	--Связующий выстрел
	{187698,3,	nil,			nil,			nil,			{187698,30,	0},	},	--Смоляная ловушка
	{206505,3,	nil,			nil,			nil,			{206505,60,	0},	},	--Стая воронов
	{131894,3,	nil,			{131894,60,	15},	{131894,60,	15},	nil,			},	--Стая воронов
	{217200,3,	nil,			{217200,15,	0},	nil,			nil,			},	--Ужасное бешенство
	{19386,	3,	nil,			{19386,	45,	0},	{19386,	45,	0},	nil,			},	--Укус виверны
	{19577,	3,	nil,			{19577,	60,	0},	nil,			nil,			},	--Устрашение
	{194277,3,	nil,			nil,			nil,			{194277,15,	0},	},	--Шипы
	{120360,3,	nil,			{120360,20,	0},	{120360,20,	0},	nil,			},	--Шквал
	{204147,3,	nil,			nil,			{204147,20,	0},	nil,			},	--Шквальный ветер
	{203415,3,	nil,			nil,			nil,			{203415,45,	0},	},	--Ярость орла
},
["ROGUE"] = {
	{195457,4,	nil,			nil,			{195457,30,	0},	nil,			},	--Абордажный крюк
	{185311,4,	{185311,30,	6},	nil,			nil,			nil,			},	--Алый фиал
	{79140,	3,	nil,			{79140,	120,	20},	nil,			nil,			},	--Вендетта
	{13750,	3,	nil,			nil,			{13750,	180,	15},	nil,			},	--Выброс адреналина
	{1856,	3,	{1856,	120,	3},	nil,			nil,			nil,			},	--Исчезновение
	{57934,	3,	{57934,	30,	6},	nil,			nil,			nil,			},	--Маленькие хитрости
	{137619,3,	{137619,60,	0},	nil,			nil,			nil,			},	--Метка смерти
	{185767,3,	nil,			nil,			{185767,60,	0},	nil,			},	--Обстрел ядрами
	{2094,	3,	nil,			nil,			{2094,	120,	0},	{2094,	120,	0},	},	--Ослепление
	{1725,	3,	{1725,	30,	10},	nil,			nil,			nil,			},	--Отвлечение
	{199754,3,	nil,			nil,			{199754,120,	10},	nil,			},	--Отражение ударов
	{199743,3,	nil,			nil,			{199743,20,	0},	nil,			},	--Парламентер
	{1766,	5,	{1766,	15,	0},	nil,			nil,			nil,			},	--Пинок
	{31224,	4,	{31224,	90,	5},	nil,			nil,			nil,			},	--Плащ Теней
	{192759,3,	nil,			{192759,45,	0},	nil,			nil,			},	--Погибель королей
	{199740,3,	nil,			nil,			{199740,1800,	0},	nil,			},	--Подкуп
	{202665,3,	nil,			nil,			{202665,90,	0},	nil,			},	--Проклятие Клинков Ужаса
	{200806,3,	nil,			{200806,45,	0},	nil,			nil,			},	--Пускание крови
	{212283,3,	nil,			nil,			nil,			{212283,10,	35},	},	--Символы смерти
	{152150,3,	{152150,20,	0},	nil,			nil,			nil,			},	--Смерть с небес
	{2983,	4,	{2983,	60,	8},	nil,			nil,			nil,			},	--Спринт
	{185313,3,	nil,			nil,			nil,			{185313,60,	3},	},	--Танец теней
	{121471,3,	nil,			nil,			nil,			{121471,180,	15},	},	--Теневые клинки
	{408,	3,	nil,			{408,	20,	0},	nil,			{408,	20,	0},	},	--Удар по почкам
	{209782,3,	nil,			nil,			nil,			{209782,60,	0},	},	--Укус Кровавой Пасти
	{5277,	4,	nil,			{5277,	120,	10},	nil,			{5277,	120,	10},	},	--Ускользание
	{51690,	3,	nil,			nil,			{51690,	120,	3},	nil,			},	--Череда убийств
	{36554,	3,	nil,			{36554,	30,	2},	nil,			{36554,	30,	2},	},	--Шаг сковзь тень
},
["PRIEST"] = {
	{15487,	5,	nil,			nil,			nil,			{15487,	45,	0},	},	--Безмолвие
	{110744,3,	nil,			{110744,15,	0},	{110744,15,	0},	nil,			},	--Божественная звезда
	{121536,3,	{121536,20,	0},	nil,			nil,			nil,			},	--Божественное перышко
	{64843,	1,	nil,			nil,			{64843,	180,	8},	nil,			},	--Божественный гимн
	{47536,	3,	nil,			{47536,	120,	8},	nil,			nil,			},	--Вознесение
	{73325,	2,	nil,			{73325,	90,	0},	{73325,	90,	0},	nil,			},	--Духовное рвение
	{228260,3,	nil,			nil,			nil,			{228260,3,	0},	},	--Извержение Бездны
	{34433,	3,	nil,			{34433,	180,	12},	nil,			{34433,	180,	12},	},	--Исчадие Тьмы
	{204883,3,	nil,			nil,			{204883,15,	0},	nil,			},	--Круг исцеления
	{32375,	1,	{32375,	15,	0},	nil,			nil,			nil,			},	--Массовое рассеивание
	{8122,	3,	nil,			{8122,	60,	0},	nil,			{8122,	60,	0},	},	--Ментальный крик
	{19236,	4,	nil,			nil,			{19236,	90,	10},	nil,			},	--Молитва отчаяния
	{205369,3,	nil,			nil,			nil,			{205369,30,	2},	},	--Мыслебомба
	{47788,	2,	nil,			nil,			{47788,	240,	10},	nil,			},	--Оберегающий дух
	{15286,	1,	nil,			nil,			nil,			{15286,	180,	15},	},	--Объятия вампира
	{527,	5,	nil,			{527,	8,	0},	{527,	8,	0},	{213634,8,	0},	},	--Очищение
	{33206,	2,	nil,			{33206,	240,	8},	nil,			nil,			},	--Подавление боли
	{123040,3,	nil,			{123040,60,	12},	nil,			nil,			},	--Подчиняющий разум
	{200174,3,	nil,			nil,			nil,			{200174,60,	15},	},	--Подчиняющий разум
	{193223,3,	nil,			nil,			nil,			{193223,600,	0},	},	--Покорение безумию
	{205065,3,	nil,			nil,			nil,			{205065,60,	0},	},	--Поток Бездны
	{10060,	3,	nil,			{10060,	120,	20},	nil,			{10060,	120,	20},	},	--Придание сил
	{200183,3,	nil,			nil,			{200183,180,	30},	nil,			},	--Прославление
	{64901,	1,	nil,			nil,			{64901,	360,	10},	nil,			},	--Символ надежды
	{120517,3,	nil,			{120517,40,	0},	{120517,40,	0},	nil,			},	--Сияние
	{204263,3,	nil,			{204263,60,	3},	{204263,60,	3},	nil,			},	--Сияющая мощь
	{47585,	4,	nil,			nil,			nil,			{47585,	120,	6},	},	--Слияние с Тьмой
	{2050,	3,	nil,			nil,			{2050,	60,	0},	nil,			},	--Слово Света: Безмятежность
	{88625,	3,	nil,			nil,			{88625,	60,	0},	nil,			},	--Слово Света: Наказание
	{34861,	3,	nil,			nil,			{34861,	60,	0},	nil,			},	--Слово Света: Освящение
	{62618,	1,	nil,			{62618,	180,	10},	nil,			nil,			},	--Слово силы: Барьер
	{129250,3,	nil,			{129250,12,	0},	nil,			nil,			},	--Слово силы: Утешение
	{17,	3,	nil,			{17,	7,	0},	nil,			{17,	7,	0},	},	--Слово силы: Щит
	{214121,3,	nil,			nil,			{214121,10,	4},	nil,			},	--Тело и разум
	{205385,3,	nil,			nil,			nil,			{205385,30,	0},	},	--Темное сокрушение
	{586,	4,	{586,	30,	10},	nil,			nil,			nil,			},	--Уход в тень
	{207946,3,	nil,			{207946,90,	0},	nil,			nil,			},	--Ярость Света
},
["DEATHKNIGHT"] = {
	{48707,	4,	{48707,	60,	5},	nil,			nil,			nil,			},	--Антимагический панцирь
	{220143,3,	nil,			nil,			nil,			{220143,90,	0},	},	--Апокалипсис
	{221562,3,	nil,			{221562,45,	5},	nil,			nil,			},	--Асфиксия
	{108194,3,	nil,			nil,			nil,			{108194,45,	5},	},	--Асфиксия
	{196770,3,	nil,			nil,			{196770,20,	8},	nil,			},	--Беспощадность зимы
	{212552,4,	{212552,45,	3},	nil,			nil,			nil,			},	--Блуждающий дух
	{194844,4,	nil,			{194844,60,	0},	nil,			nil,			},	--Буря костей
	{42650,	3,	nil,			nil,			nil,			{42650,	600,	40},	},	--Войско мертвых
	{46584,	3,	nil,			nil,			nil,			{46584,	60,	0},	},	--Воскрешение мертвых
	{61999,	2,	{61999,	600,	0},	nil,			nil,			nil,			},	--Воскрешение союзника
	{152279,3,	nil,			nil,			{152279,120,	0},	nil,			},	--Дыхание Синдрагосы
	{130736,3,	nil,			nil,			nil,			{130736,45,	5},	},	--Жнец душ
	{47528,	5,	{47528,	15,	0},	nil,			nil,			nil,			},	--Заморозка разума
	{194918,3,	nil,			nil,			nil,			{194918,60,	0},	},	--Зачумленное руническое оружие
	{194679,4,	nil,			{194679,25,	3},	nil,			nil,			},	--Захват рун
	{57330,	3,	nil,			nil,			{57330,	30,	0},	nil,			},	--Зимний горн
	{206977,3,	nil,			{206977,120,	0},	nil,			nil,			},	--Кровавое зеркало
	{221699,4,	nil,			{221699,60,	0},	nil,			nil,			},	--Кровоотвод
	{206931,4,	nil,			{206931,30,	0},	nil,			nil,			},	--Кровопийца
	{55233,	4,	nil,			{55233,	90,	10},	nil,			nil,			},	--Кровь вампира
	{51271,	3,	nil,			nil,			{51271,	60,	20},	nil,			},	--Ледяной столп
	{219809,4,	nil,			{219809,60,	0},	nil,			nil,			},	--Надгробный камень
	{48792,	4,	nil,			nil,			{48792,	180,	8},	{48792,	180,	8},	},	--Незыблемость льда
	{152280,3,	nil,			nil,			nil,			{152280,30,	10},	},	--Осквернение
	{207167,3,	nil,			nil,			{207167,60,	0},	nil,			},	--Ослепляющая наледь
	{49206,	3,	nil,			nil,			nil,			{49206,	180,	40},	},	--Призыв горгульи
	{43265,	3,	nil,			{43265,	15,	10},	nil,			{43265,	30,	10},	},	--Смерть и разложение
	{49028,	3,	nil,			{49028,	180,	8},	nil,			nil,			},	--Танцующее руническое оружие
	{56222,	5,	{56222,	8,	0},	nil,			nil,			nil,			},	--Темная власть
	{63560,	3,	nil,			nil,			nil,			{63560,	60,	20},	},	--Темное превращение
	{207349,3,	nil,			nil,			nil,			{207349,180,	15},	},	--Темный судья
	{207319,4,	nil,			nil,			nil,			{207319,60,	10},	},	--Трупный щит
	{205223,4,	nil,			{205223,45,	0},	nil,			nil,			},	--Увядание
	{207256,3,	nil,			nil,			{207256,90,	8},	nil,			},	--Уничтожение
	{47568,	3,	nil,			nil,			{46578,	180,	0},	nil,			},	--Усиление рунического оружия
	{108199,1,	nil,			{108199,180,	0},	nil,			nil,			},	--Хватка Кровожада
	{49576,	3,	nil,			{49576,	15,	0},	{49576,	25,	0},	{49576,	25,	0},	},	--Хватка смерти
	{190778,3,	nil,			nil,			{190778,300,	0},	nil,			},	--Ярость Синдрагосы
},
["SHAMAN"] = {
	{108271,4,	{108271,90,	8},	nil,			nil,			nil,			},	--Астральный сдвиг
	{79206,	3,	nil,			nil,			nil,			{79206,	120,	15},	},	--Благосклонность предков
	{204945,3,	nil,			nil,			{204945,60,	0},	nil,			},	--Ветра Рока
	{73685,	3,	nil,			nil,			nil,			{73685,	15,	0},	},	--Высвободить чары жизни
	{32182,	3,	{32182,	300,	0},	nil,			nil,			nil,			},	--Героизм
	{51490,	3,	nil,			{51490,	45,	0},	nil,			nil,			},	--Гром и молния
	{207778,3,	nil,			nil,			nil,			{207778,45,	0},	},	--Дар королевы
	{51533,	3,	nil,			nil,			{51533,	120,	15},	nil,			},	--Дух дикого зверя
	{2825,	3,	{2825,	300,	40},	nil,			nil,			nil,			},	--Жажда крови
	{210714,3,	nil,			{210714,30,	0},	nil,			nil,			},	--Ледяная ярость
	{215864,3,	nil,			nil,			{215864,10,	0},	nil,			},	--Ливень
	{108281,3,	nil,			{108281,120,	10},	nil,			{108281,120,	10},	},	--Наставления предков
	{51886,	5,	nil,			{51886,	8,	0},	{51886,	8,	0},	{77130,	8,	0},	},	--Очищение духа
	{114052,1,	nil,			nil,			nil,			{114052,180,	15},	},	--Перерождение
	{114051,3,	nil,			nil,			{114051,180,	15},	nil,			},	--Перерождение
	{114050,3,	nil,			{114050,180,	15},	nil,			nil,			},	--Перерождение
	{201898,3,	nil,			nil,			{201898,45,	20},	nil,			},	--Песнь ветра
	{16166,	3,	nil,			{16166,	120,	20},	nil,			nil,			},	--Покорение стихий
	{192063,4,	nil,			{192063,15,	0},	nil,			{192063,15,	0},	},	--Порыв ветра
	{58875,	3,	nil,			nil,			{58875,	60,	8},	nil,			},	--Поступь духа
	{57994,	5,	{57994,	12,	0},	nil,			nil,			nil,			},	--Пронизывающий ветер
	{197214,3,	nil,			nil,			{197214,40,	0},	nil,			},	--Раскол
	{20608,	2,	{21169,	1800,	0},	nil,			nil,			nil,			},	--Реинкарнация
	{197995,3,	nil,			nil,			nil,			{197995,20,	0},	},	--Родник
	{196884,3,	nil,			nil,			{196884,30,	0},	nil,			},	--Свирепый выпад
	{51514,	3,	{51514,	30,	0},	nil,			nil,			nil,			},	--Сглаз
	{192077,1,	{192077,120,	15},	nil,			nil,			nil,			},	--Тотем ветряного порыва
	{196932,3,	{196932,30,	10},	nil,			nil,			nil,			},	--Тотем вуду
	{192058,3,	{192058,45,	2},	nil,			nil,			nil,			},	--Тотем выброса тока
	{98008,	1,	nil,			nil,			nil,			{98008,	180,	6},	},	--Тотем духовной связи
	{192222,3,	nil,			{192222,60,	15},	nil,			nil,			},	--Тотем жидкой магмы
	{207399,1,	nil,			nil,			nil,			{207399,300,	30},	},	--Тотем защиты Предков
	{198838,4,	nil,			nil,			nil,			{198838,60,	15},	},	--Тотем земного щита
	{5394,	3,	nil,			nil,			nil,			{5394,	30,	15},	},	--Тотем исцеляющего потока
	{157153,3,	nil,			nil,			nil,			{157153,30,	15},	},	--Тотем разразившегося ливня
	{51485,	3,	{51485,	30,	20},	nil,			nil,			nil,			},	--Тотем хватки земли
	{108280,1,	nil,			nil,			nil,			{108280,180,	10},	},	--Тотем целительного прилива
	{205495,3,	nil,			{205495,60,	0},	nil,			nil,			},	--Хранитель бурь
	{73920,	3,	nil,			nil,			nil,			{73920,	10,	0},	},	--Целительный ливень
	{192249,3,	nil,			{192249,300,	60},	nil,			nil,			},	--Элементаль бури
	{198103,3,	nil,			{198103,120,	15},	nil,			nil,			},	--Элементаль земли
	{198067,3,	nil,			{198067,300,	60},	nil,			nil,			},	--Элементаль огня
},
["MAGE"] = {
	{2139,	5,	{2139,	24,	0},	nil,			nil,			nil,			},	--Антимагия
	{205029,3,	nil,			nil,			{205029,45,	0},	nil,			},	--Ба-бах!
	{153595,3,	nil,			nil,			nil,			{153595,30,	0},	},	--Буря комет
	{110959,4,	nil,			{110959,120,	20},	nil,			nil,			},	--Великая невидимость
	{205025,3,	nil,			{205025,60,	0},	nil,			nil,			},	--Величие разума
	{157981,3,	nil,			nil,			{157981,25,	0},	nil,			},	--Взрывная волна
	{190319,3,	nil,			nil,			{190319,120,	10},	nil,			},	--Возгорание
	{205022,3,	nil,			{205022,10,	0},	nil,			nil,			},	--Волшебный фамилиар
	{31661,	3,	nil,			nil,			{31661,	20,	0},	nil,			},	--Дыхание дракона
	{55342,	3,	{55342,	120,	40},	nil,			nil,			nil,			},	--Зеркальное изображение
	{224968,3,	nil,			{224968,60,	0},	nil,			nil,			},	--Знак Алунета
	{80353,	3,	{80353,	300,	40},	nil,			nil,			nil,			},	--Искажение времени
	{122,	3,	{122,	30,	0},	nil,			nil,			nil,			},	--Кольцо льда
	{113724,3,	{113724,45,	10},	nil,			nil,			nil,			},	--Кольцо мороза
	{157997,3,	nil,			nil,			nil,			{157997,25,	0},	},	--Кольцо обледенения
	{120,	3,	nil,			nil,			nil,			{120,	12,	0},	},	--Конус холода
	{45438,	4,	{45438,	300,	10},	nil,			nil,			nil,			},	--Ледяная глыба
	{11426,	4,	{11426,	25,	60},	nil,			nil,			nil,			},	--Ледяная преграда
	{84714,	3,	nil,			nil,			nil,			{84714,	60,	0},	},	--Ледяной шар
	{212653,4,	nil,			{212653,15,	0},	nil,			nil,			},	--Мерцание
	{153561,3,	nil,			nil,			{153561,45,	3},	nil,			},	--Метеор
	{205030,3,	nil,			nil,			nil,			{205030,30,	0},	},	--Морозное касание
	{205021,3,	nil,			nil,			nil,			{205021,60,	10},	},	--Морозный луч
	{12042,	3,	nil,			{12042,	90,	10},	nil,			nil,			},	--Мощь тайной магии
	{205032,3,	nil,			{205032,40,	0},	nil,			nil,			},	--Наполнение силой
	{66,	4,	nil,			nil,			{66,	300,	0},	{66,	300,	0},	},	--Невидимость
	{108839,3,	{108839,20,	15},	nil,			nil,			nil,			},	--Плавучая льдина
	{214634,3,	nil,			nil,			nil,			{214634,45,	0},	},	--Полярная стрела
	{31687,	3,	nil,			nil,			nil,			{31687,	60,	0},	},	--Призыв элементаля воды
	{12051,	3,	nil,			{12051,	90,	6},	nil,			nil,			},	--Прилив сил
	{116011,3,	{116011,40,	0},	nil,			nil,			nil,			},	--Руна мощи
	{157980,3,	nil,			{157980,25,	0},	nil,			nil,			},	--Сверхновая
	{135029,3,	nil,			nil,			nil,			{135029,25,	0},	},	--Сильная струя воды
	{1953,	4,	{1953,	15,	0},	nil,			nil,			nil,			},	--Скачок
	{195676,4,	nil,			{195676,30,	0},	nil,			nil,			},	--Смещение
	{12472,	3,	nil,			nil,			nil,			{12472,	180,	20},	},	--Стылая кровь
	{153626,3,	nil,			{153626,20,	0},	nil,			nil,			},	--Чародейский шар
},
["WARLOCK"] = {
	{5484,	3,	nil,			{5484,	40,	0},	nil,			nil,			},	--Вой ужаса
	{111771,3,	{111771,10,	0},	nil,			nil,			nil,			},	--Демонические врата
	{48018,	4,	{48020,	30,	0},	nil,			nil,			nil,			},	--Демонический круг
	{196098,3,	{196098,120,	10},	nil,			nil,			nil,			},	--Жатва душ
	{20707,	2,	{20707,	600,	0},	nil,			nil,			nil,			},	--Камень души
	{152108,3,	nil,			nil,			nil,			{152108,45,	0},	},	--Катаклизм
	{6789,	4,	{6789,	45,	0},	nil,			nil,			nil,			},	--Лик тлена
	{30283,	3,	nil,			nil,			{30283,	30,	4},	{30283,	30,	4},	},	--Неистовство Тьмы
	{205181,3,	nil,			nil,			{205181,14,	0},	nil,			},	--Пламя тьмы
	{211714,3,	nil,			nil,			{211714,45,	0},	nil,			},	--Поглощение Тал'киэля
	{205179,3,	nil,			{205179,60,	15},	nil,			nil,			},	--Призрачная сингулярность
	{104316,3,	nil,			nil,			{104316,15,	12},	nil,			},	--Призыв зловещих охотников
	{1122,	3,	{1122,	180,	25},	nil,			nil,			nil,			},	--Призыв инфернала
	{205180,3,	nil,			nil,			{205180,24,	12},	nil,			},	--Призыв созерцателя Тьмы
	{18540,	3,	{18540,	180,	25},	nil,			nil,			nil,			},	--Призыв стража ужаса
	{698,	3,	{698,	120,	0},	nil,			nil,			nil,			},	--Ритуал призыва
	{29893,	3,	{29893,	120,	0},	nil,			nil,			nil,			},	--Создание источника душ
	{104773,4,	{104773,180,	8},	nil,			nil,			{104773,90,	8},	},	--Твердая решимость
	{108416,4,	{108416,60,	20},	nil,			nil,			nil,			},	--Темный пакт
	{80240,	3,	nil,			nil,			nil,			{80240,	20,	8},	},	--Хаос
},
["MONK"] = {
	{152173,3,	nil,			nil,			{152173,90,	8},	nil,			},	--Безмятежность
	{115288,3,	nil,			nil,			{115288,60,	0},	nil,			},	--Будоражащий отвар
	{137639,3,	nil,			nil,			{137639,90,	15},	nil,			},	--Буря, земля и огонь
	{214326,3,	nil,			{214326,75,	0},	nil,			nil,			},	--Взрывной бочонок
	{115098,3,	nil,			{115098,15,	0},	{115098,15,	0},	nil,			},	--Волна ци
	{115310,1,	nil,			nil,			nil,			{115310,180,	0},	},	--Восстановление сил
	{123986,3,	{123986,30,	0},	nil,			nil,			nil,			},	--Выброс ци
	{115546,5,	{115546,8,	0},	nil,			nil,			nil,			},	--Вызов
	{116680,3,	nil,			nil,			nil,			{116680,30,	0},	},	--Громовой чай
	{115450,5,	nil,			{218164,8,	0},	{218164,8,	0},	{115450,8,	0},	},	--Детоксикация
	{124081,3,	nil,			nil,			nil,			{124081,15,	0},	},	--Дзен-импульс
	{115176,4,	nil,			{115176,300,	0},	nil,			nil,			},	--Дзен-медитация
	{122470,4,	nil,			nil,			{122470,90,	10},	nil,			},	--Закон кармы
	{116849,2,	nil,			nil,			nil,			{116849,180,	12},	},	--Исцеляющий кокон
	{116844,1,	{116844,45,	8},	nil,			nil,			nil,			},	--Круг мира
	{119381,1,	{119381,45,	5},	nil,			nil,			nil,			},	--Круговой удар ногой
	{109132,4,	{109132,20,	0},	nil,			nil,			nil,			},	--Кувырок
	{197908,3,	nil,			nil,			nil,			{197908,90,	10},	},	--Маначай
	{113656,3,	nil,			nil,			{113656,24,	4},	nil,			},	--Неистовые кулаки
	{115308,4,	nil,			{115308,21,	0},	nil,			nil,			},	--Отвар железной шкуры
	{115399,3,	nil,			{115399,90,	0},	nil,			nil,			},	--Отвар Черного Быка
	{119582,3,	nil,			{119582,21,	0},	nil,			nil,			},	--Очищающий отвар
	{115078,3,	{115078,15,	0},	nil,			nil,			nil,			},	--Паралич
	{198898,3,	nil,			nil,			nil,			{198898,30,	0},	},	--Песнь Чи-Цзи
	{132578,3,	nil,			{132578,180,	45},	nil,			nil,			},	--Призыв Нюцзао, Черного Быка
	{123904,3,	nil,			nil,			{123904,180,	45},	nil,			},	--Призыв Сюэня, Белого Тигра
	{198664,3,	nil,			nil,			nil,			{198664,180,	45},	},	--Призыв Чи-Цзи, Красного Журавля
	{115313,3,	nil,			nil,			nil,			{115313,10,	0},	},	--Призыв статуи Нефритовой Змеи
	{115315,3,	nil,			{115315,10,	0},	nil,			nil,			},	--Призыв статуи Черного Быка
	{122783,4,	{122783,120,	6},	nil,			nil,			nil,			},	--Распыление магии
	{116705,5,	nil,			{116705,15,	0},	{116705,15,	0},	nil,			},	--Рука-копье
	{115080,3,	nil,			nil,			{115080,120,	8},	nil,			},	--Смертельное касание
	{122278,4,	{122278,120,	45},	nil,			nil,			nil,			},	--Смягчение удара
	{197945,3,	nil,			nil,			nil,			{197945,20,	0},	},	--Странник туманов
	{116841,3,	{116841,30,	6},	nil,			nil,			nil,			},	--Тигриное рвение
	{101643,4,	{101643,10,	0},	nil,			nil,			nil,			},	--Трансцендентность
	{119996,4,	{119996,25,	0},	nil,			nil,			nil,			},	--Трансцендентность: перенос
	{205320,3,	nil,			nil,			{205320,40,	0},	nil,			},	--Удар Владыки Ветра
	{101545,3,	nil,			nil,			{101545,25,	0},	nil,			},	--Удар летящего змея
	{115203,4,	nil,			{115203,420,	15},	nil,			nil,			},	--Укрепляющий отвар
	{122281,4,	{122281,30,	0},	nil,			nil,			nil,			},	--Целебный элексир
	{115008,4,	{115008,20,	10},	nil,			nil,			nil,			},	--Ци-полет
},
["DRUID"] = {
	{202359,3,	nil,			{202359,80,	0},	nil,			nil,			nil,			},	--Астральное единение
	{102280,4,	{102280,30,	4},	nil,			nil,			nil,			nil,			},	--Астральный скачок
	{106951,3,	nil,			nil,			{106951,180,	15},	nil,			nil,			},	--Берсерк
	{210722,3,	nil,			nil,			{210722,75,	0},	nil,			nil,			},	--Бешенство Пеплошкурой
	{202360,3,	nil,			{202360,15,	0},	nil,			nil,			nil,			},	--Благословение Древних
	{18562,	3,	nil,			nil,			nil,			nil,			{18562,	30,	0},	},	--Быстрое восстановление
	{102793,1,	nil,			nil,			nil,			nil,			{102793,60,	10},	},	--Вихрь Урсола
	{20484,	2,	{20484,	600,	0},	nil,			nil,			nil,			nil,			},	--Возрождение
	{202425,3,	nil,			{202425,45,	0},	nil,			nil,			nil,			},	--Воин Элуны
	{33891,	3,	nil,			nil,			nil,			nil,			{33891,	180,	30},	},	--Воплощение: Древо Жизни
	{102560,3,	nil,			{102560,180,	30},	nil,			nil,			nil,			},	--Воплощение: Избранный Элуны
	{102543,3,	nil,			nil,			{102543,180,	30},	nil,			nil,			},	--Воплощение: Король джунглей
	{102558,3,	nil,			nil,			nil,			{102558,180,	30},	nil,			},	--Воплощение: Страж Урсока
	{22812,	4,	nil,			{22812,	60,	12},	nil,			{22812,	90,	12},	{22812,	60,	12},	},	--Дубовая кожа
	{102342,2,	nil,			nil,			nil,			nil,			{102342,90,	12},	},	--Железная кора
	{61336,	4,	nil,			nil,			{61336,	120,	6},	{61336,	240,	6},	nil,			},	--Инстинкты выживания
	{155835,3,	nil,			nil,			nil,			{155835,40,	8},	nil,			},	--Колючий мех
	{5215,	3,	{5215,	10,	0},	nil,			nil,			nil,			nil,			},	--Крадущийся зверь
	{106839,5,	nil,			nil,			{106839,15,	0},	{106839,15,	0},	nil,			},	--Лобовая атака
	{204066,3,	nil,			nil,			nil,			{204066,90,	8},	nil,			},	--Лунный луч
	{102359,1,	{102359,30,	20},	nil,			nil,			nil,			nil,			},	--Массовое оплетение
	{5211,	3,	{5211,	50,	5},	nil,			nil,			nil,			nil,			},	--Мощное оглушение
	{202060,3,	nil,			nil,			{202060,45,	0},	nil,			nil,			},	--Наставление Элуны
	{22842,	4,	nil,			nil,			nil,			{22842,	24,	3},	nil,			},	--Неистовствое восстановление
	{108238,4,	{108238,120,	0},	nil,			nil,			nil,			nil,			},	--Обновление
	{29166,	2,	nil,			{29166,	180,	10},	nil,			nil,			{29166,	180,	10},	},	--Озарение
	{194223,3,	nil,			{194223,180,	15},	nil,			nil,			nil,			},	--Парад планет
	{99,	3,	nil,			nil,			nil,			{99,	30,	0},	nil,			},	--Парализующий рык
	{1850,	4,	{1850,	180,	15},	nil,			nil,			nil,			nil,			},	--Порыв
	{197721,3,	nil,			nil,			nil,			nil,			{197721,60,	6},	},	--Расцвет
	{6795,	5,	{6795,	8,	0},	nil,			nil,			nil,			nil,			},	--Рык
	{205636,3,	nil,			{205636,60,	10},	nil,			nil,			nil,			},	--Сила Природы
	{2782,	5,	{2782,	8,	0},	nil,			nil,			nil,			{88423,	8,	0},	},	--Снятие порчи
	{740,	1,	nil,			nil,			nil,			nil,			{740,	180,	8},	},	--Спокойствие
	{78675,	5,	nil,			{78675,	60,	8},	nil,			nil,			nil,			},	--Столп солнечного света
	{102401,3,	{102401,15,	0},	nil,			nil,			nil,			nil,			},	--Стремительный рывок
	{208253,3,	nil,			nil,			nil,			nil,			{208253,90,	10},	},	--Сущность Г'ханира
	{132469,3,	{132469,30,	6},	nil,			nil,			nil,			nil,			},	--Тайфун
	{5217,	3,	nil,			nil,			{5217,	30,	8},	nil,			nil,			},	--Тигриное неистовство
	{106898,1,	nil,			nil,			{77764,	120,	8},	{77761,	120,	8},	nil,			},	--Тревожный рев
	{102351,3,	nil,			nil,			nil,			nil,			{102351,30,	0},	},	--Щит Кенария
	{200851,4,	nil,			nil,			nil,			{200851,90,	10},	nil,			},	--Ярость Спящего
	{202770,3,	nil,			{202770,90,	0},	nil,			nil,			nil,			},	--Ярость Элуны
},
["DEMONHUNTER"] = {
	{203720,4,	nil,			nil,			{203720,15,	6},	},	--Демоническаие шипы
	{178740,3,	nil,			nil,			{178740,15,	6},	},	--Жар преисподней
	{206491,3,	nil,			{206491,120,	60},	nil,			},	--Заклятый враг
	{198589,3,	nil,			{198589,60,	10},	nil,			},	--Затуманивание
	{211881,3,	{211881,35,	0},	nil,			nil,			},	--Извержение Скверны
	{189110,4,	nil,			nil,			{189110,20,	0},	},	--Инфернальный удар
	{198793,4,	nil,			{198793,25,	3},	nil,			},	--Коварное отступление
	{179057,1,	{179057,60,	5},	nil,			nil,			},	--Кольцо Хаоса
	{187827,3,	nil,			nil,			{187827,180,	15},	},	--Метаморфоза
	{191427,3,	nil,			{191427,300,	30},	nil,			},	--Метаморфоза
	{196718,1,	nil,			{196718,180,	8},	nil,			},	--Мрак
	{185245,5,	nil,			nil,			{185245,8,	0},	},	--Мучение
	{204021,3,	nil,			nil,			{204021,60,	8},	},	--Огненное клеймо
	{212084,3,	nil,			nil,			{212084,60,	0},	},	--Опустошение Скверны
	{202137,3,	nil,			nil,			{202137,60,	8},	},	--Печать немоты
	{204596,3,	nil,			nil,			{204596,30,	8},	},	--Печать огня
	{207684,3,	nil,			nil,			{207684,60,	2},	},	--Печать страдания
	{202138,3,	nil,			nil,			{202138,60,	2},	},	--Печать цепей
	{217832,3,	{217832,10,	0},	nil,			nil,			},	--Пленение
	{183752,5,	{183752,15,	0},	nil,			nil,			},	--Поглощение магии
	{188501,3,	{188501,30,	10},	nil,			nil,			},	--Призрачное зрение
	{227225,4,	nil,			nil,			{227225,20,	8},	},	--Призрачный барьер
	{198013,3,	nil,			{198013,45,	0},	nil,			},	--Пронзающий взгляд
	{196555,4,	nil,			{196555,90,	5},	nil,			},	--Путь Пустоты
	{207407,3,	nil,			nil,			{207407,40,	0},	},	--Разрубатель душ
	{195072,4,	nil,			{195072,10,	0},	nil,			},	--Рывок Скверны
	{207810,2,	nil,			nil,			{207810,120,	15},	},	--Узы Пустоты
	{218256,4,	nil,			nil,			{218256,20,	6},	},	--Усиление оберегов
	{201467,3,	nil,			{201467,60,	0},	nil,			},	--Ярость иллидари
},

["PET"] = {

},
["RACIAL"] = {
	{68992,	3,	{68992,	120,	10},	},	--Worgen
	{20589,	3,	{20589,	60,	0},	},	--Gnome
	{20594,	3,	{20594,	120,	8},	},	--Dwarf
	{121093,3,	{121093,180,	5},	},	--Draenei
	{58984,	3,	{58984,	120,	0},	},	--NightElf
	{59752,	3,	{59752,	120,	0},	},	--Human
	{69041,	3,	{69041,	90,	0},	},	--Goblin
	{69070,	3,	{69070,	90,	0},	},	--Goblin
	{7744,	3,	{7744,	120,	0},	},	--Undead
	{20577,	3,	{20577,	120,	10},	},	--Undead
	{20572,	3,	{20572,	120,	15},	},	--Orc
	{20549,	3,	{20549,	90,	0},	},	--Tauren
	{26297,	3,	{26297,	180,	10},	},	--Troll
	{28730,	3,	{28730,	90,	0},	},	--BloodElf
	{107079,3,	{107079,120,	4},	},	--Pandaren
},
["ITEMS"] = {
	{67826,	3,	{67826,	3600,	0},	},	--Jeevs
	--{177592,3,	{177592,120,	0},	},	--Candle
	--{176873,3,	{176873,120,	20},	},	--Tank BRF
	--{176875,3,	{176875,120,	20},	},	--Shard of nothing
	--{177597,3,	{177597,120,	20},	},	--Coin
	--{177594,3,	{177594,120,	20},	},	--Couplend
	--{177189,3,	{177189,90,	15},	},	--Kyanos
	--{176460,3,	{176460,120,	20},	},	--Kyb
	--{183929,3,	{183929,90,	15},	},	--Intuition's Gift
	--{184270,3,	{184270,60,	20},	},	--Mirror of the Blademaster
	{201414,3,	{201414,60,	0},	},	--Purified Shard of the Third Moon
	{201371,3,	{201371,60,	0},	},	--Judgment of the Naaru
	{90633,	3,	{90633,	600,	0},	},	--Guild Battle Standard
	{90632,	3,	{90632,	600,	0},	},	--Guild Battle Standard
	{90631,	3,	{90631,	600,	0},	},	--Guild Battle Standard
	{215956,3,	{215956,120,	30},	},	--Horn of Valor
	{215648,3,	{215648,90,	20},	},	--Moonlit Prism
	{214962,3,	{214962,120,	30},	},	--Faulty Countermeasure
	{215936,3,	{215936,120,	20},	},	--Orb of Torment
	{215658,3,	{215658,75,	15},	},	--Tirathon's Betrayal
	{214980,3,	{214980,120,	6},	},	--Windscar Whetstone
	{215206,3,	{215206,20,	0},	},	--Jewel of Insatiable Desire
	{214584,3,	{214584,60,	10},	},	--Shivermaw's Jawbone
	{215467,3,	{215467,60,	15},	},	--Obelisk of the Void
	{214971,3,	{214971,60,	8},	},	--Giant Ornamental Pearl
	{214423,3,	{214423,60,	15},	},	--Talisman of the Cragshaper
	{214366,3,	{214366,120,	30},	},	--Shard of Rokmora
	{215670,3,	{215670,120,	15},	},	--Figurehead of the Naglfar
	{214203,3,	{214203,60,	0},	},	--Gift of Radiance
	{214198,3,	{214198,90,	0},	},	--Mote of Sanctification
	{221837,3,	{221837,120,	10},	},	--Cocoon of Enforced Solitude
	{221992,3,	{221992,60,	0},	},	--Horn of Cenarius
	{221695,3,	{221695,120,	25},	},	--Unbridled Fury
	{222046,3,	{222046,120,	0},	},	--Wriggling Sinew
	{221803,3,	{221803,60,	10},	},	--Ravaged Seed Pod
	
},
}
]]


-------------------------------------------
-----------------         -----------------
----------------- Inspect -----------------
-----------------         -----------------
-------------------------------------------


local moduleInspect = ExRT.mod:New("Inspect",nil,true)

moduleInspect.db.inspectDB = {}
moduleInspect.db.inspectDBAch = {}
moduleInspect.db.inspectQuery = {}
moduleInspect.db.inspectItemsOnly = {}
moduleInspect.db.inspectID = nil
moduleInspect.db.inspectCleared = nil

module.db.inspectDB = moduleInspect.db.inspectDB	--Quick fix for other modules

local inspectForce = false
function moduleInspect:Force() inspectForce = true end
function moduleInspect:Slowly() inspectForce = false end

moduleInspect.db.statsNames = {
	haste = {L.cd2InspectHaste,L.cd2InspectHasteGem},
	mastery = {L.cd2InspectMastery,L.cd2InspectMasteryGem},
	crit = {L.cd2InspectCrit,L.cd2InspectCritGem,L.cd2InspectCritGemLegendary},
	spirit = {L.cd2InspectSpirit,L.cd2InspectAll},
	
	intellect = {L.cd2InspectInt,L.cd2InspectIntGem,L.cd2InspectAll},
	agility = {L.cd2InspectAgi,L.cd2InspectAll},
	strength = {L.cd2InspectStr,L.cd2InspectStrGem,L.cd2InspectAll},
	spellpower = {L.cd2InspectSpd},
	
	versatility = {L.cd2InspectVersatility,L.cd2InspectVersatilityGem},
	leech = {L.cd2InspectLeech},
	armor = {L.cd2InspectBonusArmor},
	avoidance = {L.cd2InspectAvoidance},
	speed = {L.cd2InspectSpeed},
	
}

moduleInspect.db.itemsSlotTable = {
	1,	--INVSLOT_HEAD
	2,	--INVSLOT_NECK
	3,	--INVSLOT_SHOULDER
	15,	--INVSLOT_BACK
	5,	--INVSLOT_CHEST
	9,	--INVSLOT_WRIST
	10,	--INVSLOT_HAND
	6,	--INVSLOT_WAIST
	7,	--INVSLOT_LEGS
	8,	--INVSLOT_FEET
	11,	--INVSLOT_FINGER1
	12,	--INVSLOT_FINGER2
	13,	--INVSLOT_TRINKET1
	14,	--INVSLOT_TRINKET2
	16,	--INVSLOT_MAINHAND
	17,	--INVSLOT_OFFHAND
}

local inspectScantip = CreateFrame("GameTooltip", "ExRTInspectScanningTooltip", nil, "GameTooltipTemplate")
inspectScantip:SetOwner(UIParent, "ANCHOR_NONE")

local inspectLastTime = 0
local function InspectNext()
	if RaidInCombat() or (InspectFrame and InspectFrame:IsShown()) then
		return
	end
	local nowTime = GetTime()
	for name,timeAdded in pairs(moduleInspect.db.inspectQuery) do
		if name and CanInspect(name) then--and CheckInteractDistance(name,1) then
			NotifyInspect(name)
			
			if (VExRT and VExRT.InspectViewer and VExRT.InspectViewer.EnableA4ivs) and not moduleInspect.db.inspectDBAch[name] then
				if AchievementFrameComparison then
					AchievementFrameComparison:UnregisterEvent("INSPECT_ACHIEVEMENT_READY")
					ExRT.F.Timer(AchievementFrameComparison.RegisterEvent, inspectForce and 1 or 2.5, AchievementFrameComparison, "INSPECT_ACHIEVEMENT_READY")
				end
				ClearAchievementComparisonUnit()
				SetAchievementComparisonUnit(name)
			end
			
			moduleInspect.db.inspectQuery[name] = nil
			return
		elseif (timeAdded + 300) < nowTime or not UnitName(name) then
			moduleInspect.db.inspectQuery[name] = nil
		end
	end
end

local function InspectQueue()
	local n = GetNumGroupMembers() or 0
	local timeAdded = GetTime()
	for j=1,n do
		local name,_,subgroup,_,_,_,_,online = GetRaidRosterInfo(j)
		if name and not moduleInspect.db.inspectDB[name] and online then
			moduleInspect.db.inspectQuery[name] = timeAdded
		end
	end
end

function moduleInspect:AddToQueue(name) 
	if not moduleInspect.db.inspectQuery[name] then
		moduleInspect.db.inspectQuery[name] = GetTime()
	end
end


local function ExCD2_ClearTierSetsInfoFromUnit(name)
	for tierUID,tierData in pairs(module.db.tierSetsSpells) do
		if tierData[1] then
			if type(tierData[1]) ~= "table" then
				module.db.session_gGUIDs[name] = -tierData[1]
			else
				for i=1,#tierData[1] do
					module.db.session_gGUIDs[name] = -tierData[1][i]
				end
			end
		end
		if tierData[2] then
			if type(tierData[2]) ~= "table" then
				module.db.session_gGUIDs[name] = -tierData[2]
			else
				for i=1,#tierData[2] do
					module.db.session_gGUIDs[name] = -tierData[2][i]
				end
			end
		end
	end
	for itemID,spellID in pairs(module.db.itemsToSpells) do
		module.db.session_gGUIDs[name] = -spellID
	end
end

local InspectItems = nil
do
	local ITEM_LEVEL = (ITEM_LEVEL or "NO DATA FOR ITEM_LEVEL"):gsub("%%d","(%%d+)")
	function InspectItems(name,inspectedName,inspectSavedID)
		if moduleInspect.db.inspectCleared or moduleInspect.db.inspectID ~= inspectSavedID then
			return
		end
		moduleInspect.db.inspectDB[name] = moduleInspect.db.inspectDB[name] or {}
		local inspectData = moduleInspect.db.inspectDB[name]
		inspectData['ilvl'] = 0
		inspectData['tiersets'] = {}
		inspectData['items'] = {}
		inspectData['items_ilvl'] = {}
		for stateName,stateData in pairs(moduleInspect.db.statsNames) do
			inspectData[stateName] = 0
		end
		local ilvl_count = 0
		
		ExCD2_ClearTierSetsInfoFromUnit(name)	--------> ExCD2
		
		local isArtifactEqipped = 0
		local ArtifactIlvlSlot1,ArtifactIlvlSlot2 = 0,0
		for i=1,#moduleInspect.db.itemsSlotTable do
			local itemSlotID = moduleInspect.db.itemsSlotTable[i]
			--local itemLink = GetInventoryItemLink(inspectedName, itemSlotID)
			inspectScantip:SetInventoryItem(inspectedName, itemSlotID)
			
			local _,itemLink = inspectScantip:GetItem()
			if itemLink then
				inspectData['items'][itemSlotID] = itemLink
				--inspectScantip:SetInventoryItem(inspectedName, itemSlotID)
				local itemID = itemLink:match("item:(%d+):")
				
				if itemSlotID == 16 or itemSlotID == 17 then
					local _,_,quality = GetItemInfo(itemLink)
					if quality == 6 then
						isArtifactEqipped = isArtifactEqipped + 1
					end
				end
				
				for j=2, inspectScantip:NumLines() do
					local tooltipLine = _G["ExRTInspectScanningTooltipTextLeft"..j]
					local text = tooltipLine:GetText()
					if text and text ~= "" then
						for stateName,stateData in pairs(moduleInspect.db.statsNames) do
							inspectData[stateName] = inspectData[stateName] or 0
							local findText = text:gsub(",","")
							for k=1,#stateData do
								local findData = findText:match(stateData[k])
								if findData then
									local cR,cG,cB = tooltipLine:GetTextColor()
									cR = abs(cR - 0.5)
									cG = abs(cG - 0.5)
									cB = abs(cB - 0.5)
									if cR < 0.01 and cG < 0.01 and cB < 0.01 then
										findData = 0
									end
									inspectData[stateName] = inspectData[stateName] + tonumber(findData)
								end
							end
						end
						
						local ilvl = text:match(ITEM_LEVEL)
						if ilvl then
							ilvl = tonumber(ilvl)
							inspectData['ilvl'] = inspectData['ilvl'] + ilvl
							ilvl_count = ilvl_count + 1
							
							inspectData['items_ilvl'][itemSlotID] = ilvl
							
							if isArtifactEqipped > 0 then
								if itemSlotID == 16 then
									ArtifactIlvlSlot1 = ilvl
								else
									ArtifactIlvlSlot2 = ilvl
								end
							end
						end
					end
				end
				
				itemID = tonumber(itemID or 0)
				
				--------> ExCD2
				local tierSetID = module.db.tierSetsList[itemID]
				if tierSetID then
					inspectData['tiersets'][tierSetID] = inspectData['tiersets'][tierSetID] and inspectData['tiersets'][tierSetID] + 1 or 1
				end
				local isTrinket = module.db.itemsToSpells[itemID]
				if isTrinket then
					module.db.session_gGUIDs[name] = isTrinket
				end
				
				if itemID == 124634 or itemID == 124636 or itemID == 124635 or itemID == 124637 or itemID == 124638 then
					UpdateLegendaryRingState()
				end
			end
			
			inspectScantip:ClearLines()
		end
		if isArtifactEqipped > 0 then
			inspectData['ilvl'] = inspectData['ilvl'] - ArtifactIlvlSlot1 - ArtifactIlvlSlot2 + max(ArtifactIlvlSlot1,ArtifactIlvlSlot2) * 2
		end
		inspectData['ilvl'] = inspectData['ilvl'] / ((inspectData['items'][17] or isArtifactEqipped > 0) and 16 or 15)

		--------> ExCD2
		for tierUID,count in pairs(inspectData['tiersets']) do
			local p2 = module.db.tierSetsSpells[tierUID][1]
			local p4 = module.db.tierSetsSpells[tierUID][2]
			if p2 and count >= 2 then
				if type(p2) ~= "table" then
					module.db.session_gGUIDs[name] = p2
				else
					for i=1,#p2 do
						module.db.session_gGUIDs[name] = p2[i]
					end
				end
			end
			if p4 and count >= 4 then
				if type(p4) ~= "table" then
					module.db.session_gGUIDs[name] = p4
				else
					for i=1,#p4 do
						module.db.session_gGUIDs[name] = p4[i]
					end
				end
			end
		end
		UpdateAllData()
	end
end

hooksecurefunc("NotifyInspect", function() moduleInspect.db.inspectID = GetTime() moduleInspect.db.inspectCleared = nil end)
hooksecurefunc("ClearInspectPlayer", function() moduleInspect.db.inspectCleared = true end)

hooksecurefunc("SetAchievementComparisonUnit", function() moduleInspect.db.achievementCleared = nil end)
hooksecurefunc("ClearAchievementComparisonUnit", function() moduleInspect.db.achievementCleared = true end)

do
	local tmr = 0
	local queueTimer = 0
	function moduleInspect:timer(elapsed)
		tmr = tmr + elapsed
		if tmr > (inspectForce and 1.2 or 3.5) then
			queueTimer = queueTimer + tmr
			tmr = 0
			if queueTimer > 60 then
				queueTimer = 0
				InspectQueue()
			end
			InspectNext()
		end
	end
	function moduleInspect:ResetTimer() tmr = 0 end
	function moduleInspect:AddonLoaded() tmr = -5 end
end

function moduleInspect:Enable()
	moduleInspect:RegisterTimer()
	moduleInspect:RegisterEvents('PLAYER_SPECIALIZATION_CHANGED','INSPECT_READY','UNIT_INVENTORY_CHANGED','PLAYER_EQUIPMENT_CHANGED','GROUP_ROSTER_UPDATE','ZONE_CHANGED_NEW_AREA','INSPECT_ACHIEVEMENT_READY','ENCOUNTER_START')
end
function moduleInspect:Disable()
	moduleInspect:UnregisterTimer()
	moduleInspect:UnregisterEvents('PLAYER_SPECIALIZATION_CHANGED','INSPECT_READY','UNIT_INVENTORY_CHANGED','PLAYER_EQUIPMENT_CHANGED','GROUP_ROSTER_UPDATE','ZONE_CHANGED_NEW_AREA','INSPECT_ACHIEVEMENT_READY','ENCOUNTER_START')	
end

local Inspect_Artifact_ADDON_LOADED

function moduleInspect.main:ADDON_LOADED()
	if ExRT.SDB.charName then
		moduleInspect.db.inspectQuery[ExRT.SDB.charName] = GetTime()
	end
	moduleInspect:Enable()
	moduleInspect:AddonLoaded()
	moduleInspect:RegisterAddonMessage()
	
	VExRT.InspectArtifact = VExRT.InspectArtifact or {}
	VExRT.InspectArtifact.players = VExRT.InspectArtifact.players or {}
	
	Inspect_Artifact_ADDON_LOADED()
end

function moduleInspect.main:PLAYER_SPECIALIZATION_CHANGED(arg)
	if arg and UnitName(arg) then
		local name = UnitCombatlogname(arg)
		moduleInspect.db.inspectDB[name] = nil
		
		--------> ExCD2
		VExRT.ExCD2.gnGUIDs[name] = nil		
		local _,class = UnitClass(name)
		if module.db.spell_talentsList[class] then
			for specID,specTalents in pairs(module.db.spell_talentsList[class]) do
				for i=1,18 do
					if type(specTalents[i]) == "table" then
						for j=1,#specTalents[i] do
							module.db.session_gGUIDs[name] = -(specTalents[i][j] or 0)
						end
					else
						module.db.session_gGUIDs[name] = -(specTalents[i] or 0)
					end
				end
			end
		end
		if module.db.spell_glyphsList[class] then
			for spellId,_ in pairs(module.db.spell_glyphsList[class]) do
				module.db.session_gGUIDs[name] = -spellId
			end
		end
		
		UpdateAllData()
		--------> / ExCD2
		
		moduleInspect.db.inspectQuery[name] = GetTime()
	end
end

do
	local scheludedQueue = nil
	local function funcScheduledUpdate()
		scheludedQueue = nil
		InspectQueue()
	end
	function moduleInspect.main:GROUP_ROSTER_UPDATE()
		if not scheludedQueue then
			scheludedQueue = ScheduleTimer(funcScheduledUpdate,2)
		end
	end


	local prevDiff = nil
	function moduleInspect.main:ZONE_CHANGED_NEW_AREA()
		local _,_,difficulty = GetInstanceInfo()
		if difficulty == 8 or prevDiff == 8 then
			local n = GetNumGroupMembers() or 0
			if IsInRaid() then
				n = min(n,5)
				for j=1,n do
					local name,_,subgroup = GetRaidRosterInfo(j)
					if name and subgroup == 1 then
						moduleInspect.db.inspectItemsOnly[name] = true
						moduleInspect.db.inspectQuery[name] = GetTime()
					end
				end
			else
				for j=1,5 do
					local uid = "party"..j
					if j==5 then
						uid = "player"
					end
					local name = UnitCombatlogname(uid)
					if name then
						moduleInspect.db.inspectItemsOnly[name] = true
						moduleInspect.db.inspectQuery[name] = GetTime()
					end
				end
			end
		end
		prevDiff = difficulty
		
		if not scheludedQueue then
			scheludedQueue = ScheduleTimer(funcScheduledUpdate,4)
		end
	end
end

do
	local lastInspectTime = {}
	function moduleInspect.main:INSPECT_READY(arg)
		if not moduleInspect.db.inspectCleared then
			ExRT.F.dprint('INSPECT_READY',arg)
			local time_ = GetTime()
			if arg and lastInspectTime[arg] and (time_ - lastInspectTime[arg]) < 0.2 then
				return
			end
			if arg then
				lastInspectTime[arg] = time_
			end
			local _,_,_,race,_,name,realm = GetPlayerInfoByGUID(arg)
			if name then
				if realm and realm ~= "" then name = name.."-"..realm end
				local inspectedName = name
				if UnitName("target") == DelUnitNameServer(name) then 
					inspectedName = "target"
				elseif not UnitName(name) then
					return
				end
				moduleInspect:ResetTimer()
				local _,class,classID = UnitClass(inspectedName)
				
				for i,slotID in ipairs(moduleInspect.db.itemsSlotTable) do
					local link = GetInventoryItemLink(inspectedName, slotID)
				end
				ScheduleTimer(InspectItems, inspectForce and 0.8 or 1.5, name, inspectedName, moduleInspect.db.inspectID)
	
				if moduleInspect.db.inspectDB[name] and moduleInspect.db.inspectItemsOnly[name] then
					moduleInspect.db.inspectItemsOnly[name] = nil
					return
				end
				moduleInspect.db.inspectItemsOnly[name] = nil
				
				if moduleInspect.db.inspectDB[name] then
					wipe(moduleInspect.db.inspectDB[name])
				else
					moduleInspect.db.inspectDB[name] = {}
				end
				local data = moduleInspect.db.inspectDB[name]
				
				data.spec = round( GetInspectSpecialization(inspectedName) )
				if data.spec < 1000 then
					VExRT.ExCD2.gnGUIDs[name] = data.spec
				end
				data.class = class
				data.level = UnitLevel(inspectedName)
				data.race = race
				data.time = time()
				data.GUID = UnitGUID(inspectedName)
				
				local specIndex = 1
				for i=1,GetNumSpecializationsForClassID(classID) do
					if GetSpecializationInfoForClassID(classID,i) == data.spec then
						specIndex = i
						break
					end
				end
				
				
				for i=1,6 do
					data[i] = 0
				end
				data.talentsIDs = {}
				
				local classTalents = module.db.spell_talentsList[class]
				local specTalents = classTalents and classTalents[data.spec]
				if specTalents then
					for i=0,20 do
						local row,col = (i-i%3)/3+1,i%3+1
					
						local t_id,_,_,t = GetTalentInfo(row,col,specIndex,true,inspectedName)
						if t then
							data[row] = col
							data.talentsIDs[row] = t_id
						end
						
						--------> ExCD2
						local talentID = specTalents[i+1]
						if talentID then
							if type(talentID) == "table" then
								for j,sID in ipairs(talentID) do
									if t then
										module.db.session_gGUIDs[name] = sID
									else
										module.db.session_gGUIDs[name] = -sID
									end
								end
							else
								if t then
									module.db.session_gGUIDs[name] = talentID
								else
									module.db.session_gGUIDs[name] = -talentID
								end
							end
						end
						--------> /ExCD2
					end
				end
				for i=0,17 do
					local row,col = (i-i%3)/3+1,i%3+1
				
					local t_id,_,_,t = GetPvpTalentInfo(row,col,specIndex,true,inspectedName)
					if t then
						data[row+7] = col
						data.talentsIDs[row+7] = t_id
					end
				end
				InspectItems(name, inspectedName, moduleInspect.db.inspectID)
				
				UpdateAllData() 	--------> ExCD2
			end
		end
	end
end

do
	local lastInspectTime,lastInspectGUID = 0
	moduleInspect.db.acivementsIDs = {} 
	function moduleInspect.main:INSPECT_ACHIEVEMENT_READY(guid)
		ExRT.F.dprint('INSPECT_ACHIEVEMENT_READY',guid)
		if moduleInspect.db.achievementCleared then
			C_Timer.NewTimer(.3,ClearAchievementComparisonUnit)	--prevent client crash on opening statistic 
			return
		end
		local currTime = GetTime()
		if not guid or (lastInspectGUID == guid and (currTime - lastInspectTime) < 0.2) then
			C_Timer.NewTimer(.3,ClearAchievementComparisonUnit)	--prevent client crash on opening statistic 
			return
		end
		lastInspectGUID = guid
		lastInspectTime = currTime
		local _,_,_,_,_,name,realm = GetPlayerInfoByGUID(guid)
		if name then
			if realm and realm ~= "" then name = name.."-"..realm end
			
			if moduleInspect.db.inspectDBAch[name] then
				wipe(moduleInspect.db.inspectDBAch[name])
			else
				moduleInspect.db.inspectDBAch[name] = {}
			end
			local data = moduleInspect.db.inspectDBAch[name]
			data.guid = guid
			for _,id in pairs(moduleInspect.db.acivementsIDs) do
				if id > 0 then
					local completed, month, day, year, unk1 = GetAchievementComparisonInfo(id)
					if completed then
						data[id] = month..":"..day..":"..year
					end
				else
					id = -id
					local info = GetComparisonStatistic(id)
					info = tonumber(info or "-")
					if info then
						data[id] = info
					end
				end
			end
		end
		if not AchievementFrame or not AchievementFrame:IsShown() then
			C_Timer.NewTimer(.3,ClearAchievementComparisonUnit)	--prevent client crash on opening statistic 
		end
	end
end

function moduleInspect.main:UNIT_INVENTORY_CHANGED(arg)
	if arg=='player' then return end
	local name = UnitCombatlogname(arg or "?")
	if name and name ~= ExRT.SDB.charName then
		moduleInspect.db.inspectItemsOnly[name] = true
		moduleInspect.db.inspectQuery[name] = GetTime()
	end
end

local Inspect_Artifact_PLAYER_EQUIPMENT_CHANGED

function moduleInspect.main:PLAYER_EQUIPMENT_CHANGED(arg)
	local name = UnitCombatlogname("player")
	moduleInspect.db.inspectItemsOnly[name] = true
	moduleInspect.db.inspectQuery[name] = GetTime()
	
	Inspect_Artifact_PLAYER_EQUIPMENT_CHANGED(arg)
end

-------------------------------------------
-------------                --------------
------------- Legendary ring --------------
-------------                --------------
-------------------------------------------

if not ExRT.isLegionContent then

local module_legendary = ExRT.mod:New("LegendaryRing",ExRT.L.LegendaryRing,nil,true)

local module_legendary_ring = nil

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

	self.enableChk = ELib:Check(self,L.LegendaryRingEnable,VExRT.LegendaryRing.enabled):Point(5,-30):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.LegendaryRing.enabled = true
			module_legendary:RegisterEvents("COMBAT_LOG_EVENT_UNFILTERED")
			module_legendary:RegisterAddonMessage()
		else
			VExRT.LegendaryRing.enabled = nil
			module_legendary:UnregisterEvents("COMBAT_LOG_EVENT_UNFILTERED")
			module_legendary:UnregisterAddonMessage()
		end
	end)
	
	self.typeChk = ELib:Check(self,L.LegendaryRingType,VExRT.LegendaryRing.ShowType):Point(5,-55):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.LegendaryRing.ShowType = true
		else
			VExRT.LegendaryRing.ShowType = nil
		end
	end)
	
	self.raidWarningChk = ELib:Check(self,RAID_WARNING,VExRT.LegendaryRing.raidWarning):Point(5,-80):OnClick(function(self) 
		if self:GetChecked() then
			VExRT.LegendaryRing.raidWarning = true
		else
			VExRT.LegendaryRing.raidWarning = nil
		end
	end)	
	

end

function module_legendary.main:ADDON_LOADED()
	if not VExRT then
		return
	end
	VExRT.LegendaryRing = VExRT.LegendaryRing or {}
	
	if VExRT.LegendaryRing.enabled then
		module_legendary:RegisterAddonMessage()
		module_legendary:RegisterEvents("COMBAT_LOG_EVENT_UNFILTERED")
	end
end

do
	local isSendByMe = true
	local function SendToChat(name,ringtype)
		if isSendByMe then
			local chat_type,chat_tar = ExRT.F.chatType()
			ringtype = VExRT.LegendaryRing.ShowType and ringtype
			if chat_type == "RAID" and VExRT.LegendaryRing.raidWarning then
				chat_type = "raid_warning"
			elseif chat_type == "WHISPER" then
				return
			end
			SendChatMessage(format("%s: %s",L.LegendaryRingFrodo,name)..(ringtype and " ["..ringtype.."]" or ""),chat_type,nil,chat_tar)
		end
	end
	function module_legendary.Ring(name,ringtype)
		if not VExRT.LegendaryRing or not VExRT.LegendaryRing.enabled then
			return
		end
		isSendByMe = true
		ExRT.F.ScheduleTimer(ExRT.F.SendExMsg, 0.15, "legendary","RING")
		local dealy = ExRT.F.IsPlayerRLorOfficer(ExRT.SDB.charName) == 2 and 0.01 or 1.3
		ExRT.F.ScheduleTimer(SendToChat, dealy, name, ringtype)
	end
	
	function module_legendary:addonMessage(sender, prefix, sub_type)
		if prefix == "legendary" then
			if sender then
				if ExRT.F.IsPlayerRLorOfficer(ExRT.SDB.charName) == 2 then
					return
				end
				if sender < ExRT.SDB.charName or ExRT.F.IsPlayerRLorOfficer(sender) == 2 then
					if sub_type == "RING" then
						isSendByMe = nil
					end
				end
			end
		end
	end
end
module_legendary_ring = module_legendary.Ring

module_legendary.db.types = {
	[187614] = DAMAGER,
	[187615] = DAMAGER,
	[187611] = DAMAGER,
	[187613] = TANK,
	[187612] = HEALER,
} 
function module_legendary.main:COMBAT_LOG_EVENT_UNFILTERED(_,_,event,_,sourceGUID,sourceName,_,_,_,_,_,_,spellID)
	if event == "SPELL_CAST_SUCCESS" and (spellID == 187614 or spellID == 187615 or spellID == 187611 or spellID == 187613 or spellID == 187612) then
		if not sourceName or not UnitName(sourceName) then
			return
		end
		module_legendary_ring(sourceName,module_legendary.db.types[spellID])
	end
end

end


-------------------------------------------
-------------                --------------
-------------    Artifact    --------------
-------------                --------------
-------------------------------------------

moduleInspect.db.artifactDB = {}
moduleInspect.db.artifactNoResDB = {}

local ArtifactCache = {}
moduleInspect.db.selfArtifactCache = ArtifactCache

moduleInspect.db.relicTypeToID = {
	["Fel"] = 0,
	["Fire"] = 1,
	["Blood"] = 2,
	["Life"] = 3,
	["Holy"] = 4,
	["Frost"] = 5,
	["Shadow"] = 6,
	["Iron"] = 7,
	["Arcane"] = 8,
	["Wind"] = 9,
}

local function ScanArtifactData()
	wipe(ArtifactCache)
	
	local powers = C_ArtifactUI.GetPowers()
	
	if not powers then
		return
	end

	local traits = {}
	ArtifactCache.traits = traits
	for i = 1, #powers do
		local traitID = powers[i]
		local spellID, _, currentRank, maxRank, bonusRanks, _, _, _, isStart, isGold, isFinal = C_ArtifactUI.GetPowerInfo(traitID)
		traits[#traits + 1] = {
			traitID = traitID,
			currentRank = currentRank,
			maxRank = maxRank,
			sort = (isStart and 100) or (isFinal and -100) or (isGold and 50) or 0,
		}
	end
	
	sort(traits,function(a,b) 
		if a and b then
			if a.sort == b.sort then
				return a.traitID > b.traitID
			else
				return a.sort > b.sort
			end
		end 
	end)
	
	ArtifactCache.KnowledgeLevel = C_ArtifactUI.GetArtifactKnowledgeLevel()
	ArtifactCache.KnowledgeMultiplier = C_ArtifactUI.GetArtifactKnowledgeMultiplier()
	local itemID, _, _, _, _, aLevel = C_ArtifactUI.GetArtifactInfo()
	ArtifactCache.AftifactLevel = aLevel
	ArtifactCache.itemID = itemID
	
	for i=1,3 do
		local _,_,_,relicLink = C_ArtifactUI.GetRelicInfo(i)
		if relicLink then
			relicLink = relicLink:match("(item:.-)|h")
		end
		ArtifactCache["relic"..i] = relicLink
		
		local relicType = C_ArtifactUI.GetRelicSlotType(i)
		relicType = moduleInspect.db.relicTypeToID[ relicType or "?" ]
		ArtifactCache["relicType"..i] = relicType
	end
end

local function UpdateArtifactData()
	if not C_ArtifactUI.GetEquippedArtifactInfo() then
		return
	end
	local isArtifactFrameShown = ArtifactFrame and ArtifactFrame:IsShown()
	if not isArtifactFrameShown then
		SocketInventoryItem(16)
	end
	ScanArtifactData()
	if not isArtifactFrameShown then
		C_ArtifactUI.Clear()
	end
end

do
	--Fix Blizzard Errors
	local def = C_ArtifactUI.GetTotalPurchasedRanks
	C_ArtifactUI.GetTotalPurchasedRanks = function(...)
		local arg1,arg2,arg3 = def(...)
		if not arg1 then
			return 0
		end
		return arg1,arg2,arg3
	end
end

local artifactUIfixTimer
local function artifactUI_CheckMajorFrames(self)
	if (not WorldMapFrame or not WorldMapFrame:IsVisible()) and (not PlayerTalentFrame or not PlayerTalentFrame:IsVisible()) and (not OrderHallMissionFrame or not OrderHallMissionFrame:IsVisible()) then
		if artifactUIfixTimer then
			artifactUIfixTimer:Cancel()
		end
		if self then
			self:Cancel()
		end
		
		UIParent:UnregisterEvent("ARTIFACT_UPDATE")
		C_Timer.After(.1,function()
			UIParent:RegisterEvent("ARTIFACT_UPDATE")
		end)
		
		UpdateArtifactData()
		return true
	end
end

local artifactUIfix = CreateFrame'Frame'
artifactUIfix:RegisterEvent('LOADING_SCREEN_DISABLED')
artifactUIfix:SetScript("OnEvent",function(self)
	C_Timer.NewTimer(9,function()
		artifactUIfixTimer = C_Timer.NewTicker(1,artifactUI_CheckMajorFrames)
		moduleInspect:RegisterEvents('ARTIFACT_XP_UPDATE')
	end)
	self:UnregisterAllEvents()
end)


function moduleInspect:ArtifactAddToQueue(name)
	ExRT.F.SendExMsg("inspect", ExRT.F.CreateAddonMsg("art","GET",name))
end


local function Inspect_SendArtifactData()
	if not ArtifactCache.AftifactLevel then
		ExRT.F.SendExMsg("inspect", ExRT.F.CreateAddonMsg("art","NO"))
		return
	end
	local equippedItemID = C_ArtifactUI.GetEquippedArtifactInfo()
	if not equippedItemID then
		ExRT.F.SendExMsg("inspect", ExRT.F.CreateAddonMsg("art","NO"))
		return
	end
	if ArtifactCache.itemID ~= equippedItemID then
		UpdateArtifactData()
		if not ArtifactCache.AftifactLevel then
			ExRT.F.SendExMsg("inspect", ExRT.F.CreateAddonMsg("art","NO"))
			return
		end
	end
	
	local res = ArtifactCache.AftifactLevel..":"..ArtifactCache.KnowledgeLevel..":"
	for i=1,#ArtifactCache.traits do
		res = res .. ArtifactCache.traits[i].traitID .. "-" ..ArtifactCache.traits[i].currentRank .. "-" .. ArtifactCache.traits[i].maxRank .. ":"
	end
	res = res .. equippedItemID
	
	ExRT.F.SendExMsg("inspect", ExRT.F.CreateAddonMsg("art","R",res))
	
	local res = ""
	for i=1,3 do
		res = res .. (ArtifactCache["relicType"..i] or "-") .. "^" .. (ArtifactCache["relic"..i] or "-") .. (i < 3 and "^" or "")
	end
	
	ExRT.F.SendExMsg("inspect", ExRT.F.CreateAddonMsg("art","AR",res))
end

function moduleInspect.main:ENCOUNTER_START()
	C_Timer.NewTimer(3,function()
		Inspect_SendArtifactData()
	end)
end

function moduleInspect.main:ARTIFACT_XP_UPDATE()	
	artifactUIfixTimer = nil
	if not artifactUI_CheckMajorFrames() then
		artifactUIfixTimer = C_Timer.NewTicker(1,artifactUI_CheckMajorFrames)
	end
end

local function Inspect_ParseArtifactString(db,string)
	local al,ak,tr = strsplit(":",string,3)
	
	db.Level = tonumber(al)
	db.KnowledgeLevel = tonumber(ak)
	
	while tr do
		local trait,o = strsplit(":",tr,2)
	
		local id,cr,mr = strsplit("-",trait)
		if id and cr and mr then
			db[#db+1] = {tonumber(id),tonumber(cr),tonumber(mr)}
		else
			break
		end
	
		tr = o
	end
	
	local itemID,rest = strsplit(":",tr or "",2)
	if itemID then
		db.itemID = tonumber(itemID)
	end
	tr = rest
	
	return db
end

local function Inspect_ParseArtifactRelicString(db,string)
	for i=1,3 do
		if not string then
			break
		end
		local relicType,relicLink,o = strsplit("^",string,3)
		
		relicType = tonumber(relicType or "?")
		if not relicLink or not relicLink:find("item:") then
			relicLink = nil
		end
		
		db["relic"..i] = relicLink
		db["relicType"..i] = relicType
		
		string = o
	end
	
	return db
end

local UpdateArtifactToTalentsData

function Inspect_Artifact_ADDON_LOADED()
	for player,data in pairs(VExRT.InspectArtifact.players) do
		local db = {
			time = data[2],
		}
		moduleInspect.db.artifactDB[ player ] = db
		
		Inspect_ParseArtifactString(db, data[1])
		UpdateArtifactToTalentsData(player)
	end
	--LoadAddOn("Blizzard_ArtifactUI")
	
	--Rewrite default function, cuz GetTotalPurchasedRanks return nil after log on char
	--function ArtifactUI_CanViewArtifact()
	--	return C_ArtifactUI.IsAtForge() or (C_ArtifactUI.GetTotalPurchasedRanks() or 0) > 0 or C_ArtifactUI.GetNumObtainedArtifacts() > 1;
	--end
end

local UpdateArtifactInfoTimer
function Inspect_Artifact_PLAYER_EQUIPMENT_CHANGED(slot)
	if not (slot == 16 or slot == 17) then
		return
	end
	if UpdateArtifactInfoTimer then
		UpdateArtifactInfoTimer:Cancel()
	end
	UpdateArtifactInfoTimer = C_Timer.NewTimer(2,function()
		UpdateArtifactInfoTimer = nil
		UpdateArtifactData()
	end)
end


do
	local powerToSpellID = {}
	
	function UpdateArtifactToTalentsData(player)
		local name = ExRT.F.delUnitNameServer(player)
		for i=1,#module.db.artifactAllSpells do
			module.db.session_gGUIDs[ name ] = -module.db.artifactAllSpells[i]
		end
		if not moduleInspect.db.artifactDB[ player ] then
			return
		end
		for i=1,#moduleInspect.db.artifactDB[ player ] do
			if moduleInspect.db.artifactDB[ player ][i][2] > 0 then
				local powerID = moduleInspect.db.artifactDB[ player ][i][1]
				local spellID = powerToSpellID[powerID]
				if not spellID then
					spellID = C_ArtifactUI.GetPowerInfo(powerID)
					powerToSpellID[powerID] = spellID
				end	
				if spellID then
					module.db.session_gGUIDs[ name ] = spellID
				end
			end
		end
	end
	

	
	function GetArtifactTraitsKnown(playerName, spellID)
		local data
		for long_name,DB in pairs(moduleInspect.db.artifactDB) do
			if ExRT.F.delUnitNameServer(long_name) == playerName then
				if (not data) or (DB.time > data.time) then
					data = DB
				end
			end						
		end
		if not data then
			return 0
		end
		for i=1,#data do
			local powerID = data[i][1]
			local powerSpellID = powerToSpellID[powerID]
			if not powerSpellID then
				powerSpellID = C_ArtifactUI.GetPowerInfo(powerID)
				powerToSpellID[powerID] = powerSpellID
			end
			if powerSpellID == spellID then
				return data[i][2]
			end
		end
		return 0
	end
end

function moduleInspect:addonMessage(sender, prefix, prefix2, ...)
	if prefix == "inspect" then
		if prefix2 == "art" then
			local type,name = ...
			if type == "GET" then
				if ExRT.F.delUnitNameServer(name) == ExRT.SDB.charName then
					Inspect_SendArtifactData()
				end
			elseif type == "R" then
				local db = {}
				
				moduleInspect.db.artifactDB[ sender ] = db
				
				Inspect_ParseArtifactString(db, name)
				UpdateArtifactToTalentsData(sender)
				
				local currTime = time()
				
				db.time = currTime
				
				VExRT.InspectArtifact.players[ sender ] = {
					name,
					currTime,
				}
			elseif type == "AR" then
				local db = moduleInspect.db.artifactDB[ sender ]
				if not db then
					return
				end
				
				Inspect_ParseArtifactRelicString(db,name)
			
			elseif type == "NO" then
				moduleInspect.db.artifactNoResDB[ sender ] = true
			end
		end
	end
end
