local _, core = ...;
local g_idTab = 0;
local HBD_Pins = LibStub("HereBeDragons-Pins-2.0");


--- GAME TOOLTIP ---
local OnEnterRefreshUICollectionDone = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT", 0, 0);
	GameTooltip:AddLine(core.L["Progression actualisée"], 0, 1, 0);
	GameTooltip:Show();
end
local OnEnterRefreshUICollection = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT", 0, 0);
	GameTooltip:AddLine(core.L["Actualiser votre progression"], 1, 1, 1);
	GameTooltip:Show();
end

local OnEnterBtnCollection = function(self, motion)
	GameTooltip:SetOwner(self, self.anchor, 0, 0);
	GameTooltip:AddLine(self.infoCollectionForTooltip["info"][1], 1, 1, 1);
	if (self.infoCollectionForTooltip["info"][2] == true) then
		GameTooltip:AddDoubleLine("|cff00ff00"..core.L["MountCollected"].."|r", core.L["Difficult"][self.infoCollectionForTooltip.difficult]);
	else
		GameTooltip:AddDoubleLine("|cffff0000"..core.L["MountNotCollected"].."|r", core.L["Difficult"][self.infoCollectionForTooltip.difficult]);
	end
	if (self.infoCollectionForTooltip["info"][3] ~= nil) then
		GameTooltip:AddLine("\""..self.infoCollectionForTooltip["info"][3].."\"", 1, 0.82, 0, true);
	end
	if (self.infoCollectionForTooltip["info"][4] ~= nil) then
		GameTooltip:AddLine(self.infoCollectionForTooltip["info"][4], 1, 1, 1);
	end
	local classStr = "";
	if (self.infoCollectionForTooltip.class ~= nil) then
		for i = 1, #self.infoCollectionForTooltip.class do
			if (i == 1) then
				classStr = classStr..core.L["ClassesList"][self.infoCollectionForTooltip.class[i]];
			else
				classStr = classStr.."|cffffffff,|r "..core.L["ClassesList"][self.infoCollectionForTooltip.class[i]];	
			end
		end
	end
	if (classStr ~= "") then
		GameTooltip:AddLine(core.L["Classes"]..core.L["2points"]..classStr, 1, 0.82, 0, true);
	end
	GameTooltip:AddLine(core.L["Expansion"].."|cffffffff"..self.infoCollectionForTooltip.expansion.."|r");
	GameTooltip:Show();
end

local OnEnterPageCollection = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_TOP", 0, 3);
	GameTooltip:AddLine(core.L["Chapter"]..self.collectionPageId);
	GameTooltip:Show();
end

local OnEnterBtnOnMap = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_TOP");
	if (self.infoMap.littlePin ~= nil) then
		GameTooltip:AddLine(self.infoMap.nameNPC.." "..self.i);
	else
		GameTooltip:AddLine(self.infoMap.nameNPC);
	end
	GameTooltip:AddLine("|cffffffff"..self.infoMap.nameZone.."|r ("..tostring(self.infoMap.pins[self.i].x*100)..", "..tostring(self.infoMap.pins[self.i].y*100)..")");
	GameTooltip:Show();
end

local OnEnterBtnShowMap = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_TOP");
	if (self.activate == true) then
		GameTooltip:AddLine(core.L["Cacher sur la carte"]);
	else
		GameTooltip:AddLine(core.L["Afficher sur la carte"]);
	end
	GameTooltip:AddLine(self.infoMap.nameNPC.."|cffffffff, "..self.infoMap.nameZone.."|r");
	GameTooltip:Show();
end

local lootOnEnterTaskIconItem = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_LEFT", 0, 0);
	if (self.itemLink ~= nil) then
		local _, itemLink = GetItemInfo(self.itemLink);
		if (itemLink ~= nil) then
			GameTooltip:SetHyperlink(itemLink)
		else
			GameTooltip:AddLine("|cffff0000Loading Error|r");
		end
	else
		GameTooltip:AddLine("Loading...");
	end
	GameTooltip:Show();
end

local lootOnEnterIconHelpImp = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_LEFT", 0, 0);
	GameTooltip:AddLine("|c00FF7F00"..core.L["HelpImportant"].."|r");
	GameTooltip:AddLine(self.helpForTooltipImp, 1, 1, 1, true);
	GameTooltip:Show();
end

local lootOnEnterIconHelp = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_LEFT", 0, 0);
	GameTooltip:AddLine(core.L["Aide"]);
	GameTooltip:AddLine(self.helpForTooltip, 1, 1, 1, true);
	GameTooltip:Show();
end

local lootOnEnterIconLock = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_LEFT", 0, 0);
	GameTooltip:AddLine(core.L["Lock"], 0.5, 0.5, 0.5);
	GameTooltip:Show();
end

local OnLeave = function(self, motion)
	GameTooltip:Hide()
end

local lootOnEnterTask = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_TOP", 0, 5);
		words = {}
    for w in string.gmatch(self.taskForTooltip, "%d+") do
		table.insert(words, w)
    end                                   
	local collectionTask = core.DB_Collections[tonumber(words[1])][core.DB_DisplayCollections[tonumber(words[1])][tonumber(words[2])]].page[tonumber(words[3])].step[tonumber(words[4])].task[tonumber(words[5])];

	if (collectionTask["hf"] ~= nil) then
		if (collectionTask["hf"][4] == true) then
			if (collectionTask["hf"][14] ~= "") then
				GameTooltip:AddLine(core.L["AcheveBy"].." "..collectionTask["hf"][14], 0, 1, 0);
			else
				GameTooltip:AddLine(core.L["Acheve"], 0, 1, 0);
			end
		else
			GameTooltip:AddLine(core.L["NoAcheve"], 0.5, 0.5, 0.5);
		end
		GameTooltip:AddLine(collectionTask["hf"][8], 1, 1, 1);
	elseif (collectionTask["quest"] ~= nil) then
		if (collectionTask["quest"].completed == true) then
			GameTooltip:AddLine(core.L["Acheve"], 0, 1, 0);
		else
			GameTooltip:AddLine(core.L["NoAcheve"], 0.5, 0.5, 0.5);
		end
		if (collectionTask["quest"].completed == true) then
			if (collectionTask["quest"].desc == core.L["DescQuest"]) then
				GameTooltip:AddLine(core.L["DescQuestComplete"], 1, 1, 1);
			else
				GameTooltip:AddLine(collectionTask["quest"].desc, 1, 1, 1, true);
			end
		else
			if (collectionTask["quest"].desc == core.L["DescQuest"]) then
				GameTooltip:AddLine(core.L["DescQuest"], 1, 1, 1);
			else
				GameTooltip:AddLine(collectionTask["quest"].desc, 1, 1, 1, true);
			end
		end
	elseif (collectionTask["custom"] ~= nil) then
		if (collectionTask["custom"].done == true) then
			GameTooltip:AddLine(core.L["Acheve"], 0, 1, 0);
		else
			GameTooltip:AddLine(core.L["NoAcheve"], 0.5, 0.5, 0.5);
		end
		
		if (tostring(collectionTask["custom"].desc) == "Custom1") then
			GameTooltip:AddLine(C_QuestLog.IsQuestFlaggedCompleted(44311) == true and core.L["Le bouclier est là ! Trouvez le !"] or core.L["Le bouclier n'est pas là, revenez demain."], 1, 1, 1, true);
		else
			GameTooltip:AddLine(tostring(collectionTask["custom"].desc), 1, 1, 1, true);
		end
		
		if (collectionTask["custom"].path ~= nil) then
			GameTooltip:AddLine(" ");
			if (collectionTask["custom"].done == true) then
				GameTooltip:AddLine(core.L["PutNotComplete"], 0.6, 0.6, 0.6);
			else
				GameTooltip:AddLine(core.L["PutComplete"], 0, 0.8, 0);
			end
		end
	elseif (collectionTask["need"] ~= nil) then
		if (collectionTask["need"].done == true) then
			GameTooltip:AddLine(core.L["Acheve"], 0, 1, 0);
		else
			GameTooltip:AddLine(core.L["NoAcheve"], 0.5, 0.5, 0.5);
		end
		local nameItem = core.libs.nameItemInColor(collectionTask["need"].itemInfo, 1);
		if (collectionTask["need"].path ~= nil) then
			GameTooltip:AddLine(core.L["Obtenir"]..tostring(collectionTask["need"].nbNeed).." "..nameItem..".", 1, 1, 1);
		else
			GameTooltip:AddLine(core.L["Obtenir"]..nameItem..".", 1, 1, 1);
		end
		GameTooltip:AddLine(" ");
		local count = GetItemCount(collectionTask["need"].itemId)
		if (collectionTask["need"].itemInfo[1] == nil) then
			collectionTask["need"].itemInfo[1] = "|cffff0000Loading...|r";
		end
		if (collectionTask["need"].path ~= nil) then
			if (count >= collectionTask["need"].nbNeed) then
				GameTooltip:AddLine(core.L["HaveItem"]..count.."/"..tostring(collectionTask["need"].nbNeed).." "..core.libs.nameItemInColor(collectionTask["need"].itemInfo, 2), 0, 1, 0);		
			else
				GameTooltip:AddLine(core.L["HaveItem"]..count.."/"..tostring(collectionTask["need"].nbNeed).." "..core.libs.nameItemInColor(collectionTask["need"].itemInfo, 2), 1, 1, 1);
			end
		end
		if (collectionTask["need"]["loot"] ~= nil) then
			GameTooltip:AddLine("|cffffffff"..core.L["DroppedBy"].."|r"..core.libs.printNPCDroppedLoot(collectionTask["need"]["loot"]).."|cffffffff.|r", 1, 0.82, 0, true);
		elseif (collectionTask["need"]["vendor"] ~= nil) then
			GameTooltip:AddLine("|cffffffff"..core.L["SoldBy"].."|r"..core.libs.printNPCVendor(collectionTask["need"]["vendor"]).."|cffffffff.|r");
		elseif (collectionTask["need"]["create"] ~= nil) then
			if (collectionTask["need"].profession ~= nil) then
				GameTooltip:AddLine(core.L["CreatedBy"].."|cFFF5CC00["..collectionTask["need"].profession.."]|r - "..core.libs.printCompoCreate(collectionTask["need"]["create"])..".", 1, 1, 1, true);
			else
				GameTooltip:AddLine(core.L["CreatedBy"]..core.libs.printCompoCreate(collectionTask["need"]["create"])..".", 1, 1, 1, true);
			end		elseif (collectionTask["need"]["hf"] ~= nil) then
			if (collectionTask["need"]["hf"][2] ~= nil) then
				GameTooltip:AddLine("|cffffffff"..core.L["FinishHF"].."|r"..collectionTask["need"]["hf"][2].."|cffffffff.|r", 1, 0.82, 0, true);
			else
				GameTooltip:AddLine("|cffffffff"..core.L["FinishHF"].."|rLoading...|cffffffff.|r", 1, 0.82, 0, true);
			end
		elseif (collectionTask["need"]["quest"] ~= nil) then
			if (collectionTask["need"]["quest"].title ~= nil) then
				GameTooltip:AddLine("|cffffffff"..core.L["FinishQuest"].."|r"..collectionTask["need"]["quest"].title.."|cffffffff.|r", 1, 0.82, 0, true);
			else
				GameTooltip:AddLine("|cffffffff"..core.L["FinishQuest"].."|rLoading...|cffffffff.|r", 1, 0.82, 0, true);
			end
		end
		if (collectionTask["need"].path ~= nil) then
			GameTooltip:AddLine(" ");
			if (collectionTask["need"].done == true) then
				GameTooltip:AddLine(core.L["PutNotComplete"], 0.6, 0.6, 0.6);
			else
				GameTooltip:AddLine(core.L["PutComplete"], 0, 0.8, 0);
			end
		end
	end
	if (collectionTask["faction"] ~= nil and collectionTask["MA"] == nil) then
		GameTooltip:AddLine(core.libs.changeReputToText(collectionTask["faction"]), 1, 1, 1);
	end
	if (collectionTask["hf"] ~= nil and GetAchievementNumCriteria(collectionTask["hf"][1]) ~= 0) then
		GameTooltip:AddLine(core.libs.printCriteriaHF(collectionTask["hf"][1]));
	end
	GameTooltip:Show();
end
----- END GAME TOOLTIP -----


local function SetAllDoneNeed(collectionId, idTab)
	for i = 1, core.libs.tablelength(core.DB_Collections[idTab][collectionId].page) do
		for j = 1, core.libs.tablelength(core.DB_Collections[idTab][collectionId].page[i].step) do		
			for k = 1, core.libs.tablelength(core.DB_Collections[idTab][collectionId].page[i].step[j].task) do
				if (core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["need"] ~= nil) then
					if (core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["need"].path ~= nil and core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["need"].notAffected == nil) then
						core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["need"].done = true;
						local pathSaved = {};
						local itmp = 1;
						for word in string.gmatch(core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["need"].path, '([^,]+)') do
							pathSaved[itmp] = word;
							itmp = itmp + 1;
						end
						DoneCollectionTaskRogue[idTab][tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;
					end
				elseif (core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["custom"] ~= nil) then
					if (core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["custom"].path ~= nil and core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["custom"].notAffected == nil) then
						core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["custom"].done = true;
						local pathSaved = {};
						local itmp = 1;
						for word in string.gmatch(core.DB_Collections[idTab][collectionId].page[i].step[j].task[k]["custom"].path, '([^,]+)') do
							pathSaved[itmp] = word;
							itmp = itmp + 1;
						end
						DoneCollectionTaskRogue[idTab][tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;
					end
				end
			end
		end
	end
end

local function OnClickTaskNeed(self)
	local pathSaved = {};
	if (self.path["need"] ~= nil) then
		if (self.path["need"].path ~= nil) then
			local itmp = 1;
			for word in string.gmatch(self.path["need"].path, '([^,]+)') do
				pathSaved[itmp] = word;
				itmp = itmp + 1;
			end
			if (core.DB_Collections[self.idTab][tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["need"].done == false) then
				core.DB_Collections[self.idTab][tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["need"].done = true;
				DoneCollectionTaskRogue[self.idTab][tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;	
			else
				core.DB_Collections[self.idTab][tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["need"].done = false;
				DoneCollectionTaskRogue[self.idTab][tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = false;
			end
			core.UpdateCollectionsSpecific(self.idTab, tonumber(pathSaved[1]));
			lootOnEnterTask(self);
		end
	elseif (self.path["custom"] ~= nil) then
		if (self.path["custom"].path ~= nil) then
			local itmp = 1;
			for word in string.gmatch(self.path["custom"].path, '([^,]+)') do
				pathSaved[itmp] = word;
				itmp = itmp + 1;
			end
			if (core.DB_Collections[self.idTab][tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["custom"].done == false) then
				core.DB_Collections[self.idTab][tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["custom"].done = true;
				DoneCollectionTaskRogue[self.idTab][tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;
			else
				core.DB_Collections[self.idTab][tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["custom"].done = false;
				DoneCollectionTaskRogue[self.idTab][tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = false;
			end
			core.UpdateCollectionsSpecific(self.idTab, tonumber(pathSaved[1]));
			lootOnEnterTask(self);
		end
	end
end

function PageCollection_OnClick_Lock()
	return;
end

local function ScrollFrame_OnMouseWheel(self, delta)
	local newValue = self:GetVerticalScroll() - (delta * 100);
	if (newValue < 0) then
		newValue = 0;
	elseif (newValue > self:GetVerticalScrollRange()) then
		newValue = self:GetVerticalScrollRange();
	end
	self:SetVerticalScroll(newValue);
end

local function getNbMaxCollection(idTab)
	local CollectionMax = 0;
	local idb = core.DB_DisplayCollections[idTab];
	local dbToCheck = core.DB_Collections[idTab];
	for i = 1, core.libs.tablelength(idb) do
		if (idb[i] ~= nil and dbToCheck[idb[i]] ~= nil) then
			local factionPlayer = UnitFactionGroup("player")
			if (core.libs.checkFactionandClass(dbToCheck[idb[i]].faction, dbToCheck[idb[i]].class) == true) then
				CollectionMax = CollectionMax + 1;
			end
		end
	end
	return CollectionMax;
end
core.libs.getNbMaxCollection = getNbMaxCollection;

local function getNbCollectionDone(idTab)
	local CollectionDone = 0;
	local idb = core.DB_DisplayCollections[idTab];
	local dbToCheck = core.DB_Collections[idTab];
	for i = 1, core.libs.tablelength(idb) do
		if (idb[i] ~= nil and dbToCheck[idb[i]] ~= nil) then
			local factionPlayer = UnitFactionGroup("player")
			if (core.libs.checkFactionandClass(dbToCheck[idb[i]].faction, dbToCheck[idb[i]].class) == true) then
				if (dbToCheck[idb[i]]["info"][2] == true) then
					CollectionDone = CollectionDone + 1;
				end
			end
		end
	end
	return CollectionDone;
end
core.libs.getNbCollectionDone = getNbCollectionDone;

function btnRefreshCollection_OnClick(self)
	PlaySound("83", "sfx");
	core.UpdateCollections(self.idTab);
	OnEnterRefreshUICollectionDone(self);
end

local function CreatePageGoalCollection(frameParent, collectionInfoGoal, idTab, iDisplayColl)
	local frameParentName = frameParent:GetName();
	frameParent.goal_page = CreateFrame("Button", frameParentName.."PageGoal", frameParent);
	frameParent.goal_page.selected = false;
	frameParent.goal_page.tabId = g_idTab;
	frameParent.goal_page.collectionId = collectionInfoGoal.id;
	frameParent.goal_page.modelType = collectionInfoGoal.Model;
	frameParent.goal_page.parentName = frameParentName;
	frameParent.goal_page:SetSize(58, 58);
	frameParent.goal_page:SetFrameLevel(7);
	frameParent.goal_page:SetPoint("RIGHT", frameParent.bar_page, "RIGHT", -5, -2);
	if (collectionInfoGoal["info"][2] == true) then
		frameParent.goal_page:SetNormalTexture(collectionInfoGoal.icon.."_goal_done");
		frameParent.goal_page:SetHighlightTexture(collectionInfoGoal.icon.."_goal_done");
		frameParent.goal_page.saveIcon = collectionInfoGoal.icon.."_goal_done";
	else
		frameParent.goal_page:SetNormalTexture(collectionInfoGoal.icon.."_goal");
		frameParent.goal_page:SetHighlightTexture(collectionInfoGoal.icon.."_goal");
		frameParent.goal_page.saveIcon = collectionInfoGoal.icon.."_goal";
	end
	frameParent.goal_page.infoCollectionForTooltip = collectionInfoGoal;
	frameParent.goal_page.anchor = "ANCHOR_RIGHT";
	frameParent.goal_page:SetScript("OnEnter", OnEnterBtnCollection);
	frameParent.goal_page:SetScript("OnLeave", OnLeave);
	frameParent.goal_page:SetScript("OnClick", PageCollection_OnClick);
	
	frameParent.goal_page.content = CreateFrame("Frame", frameParentName.."PageGoalContent", frameParent);
	frameParent.goal_page.content:SetSize(544, 333);
	frameParent.goal_page.content:SetPoint("BOTTOM", frameParent, "BOTTOM", 0, 3);
	frameParent.goal_page.content:Hide();
	
	frameParent.goal_page.content.imgEdge = CreateFrame("Frame", nil, frameParent.goal_page.content, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.goal_page.content.imgEdge:SetSize(545, 340);
	frameParent.goal_page.content.imgEdge:SetPoint("BOTTOM", frameParent.goal_page.content, "BOTTOM", -6, 0);
	frameParent.goal_page.content.imgEdge:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/edge_character_pct"});
	frameParent.goal_page.content.imgEdge:SetFrameLevel(7);
	
	if (collectionInfoGoal.Model ~= nil) then
		frameParent.goal_page.content.imgEdge.picture = CreateFrame("DressUpModel", frameParentName.."PageGoalModel", frameParent.goal_page.content, BackdropTemplateMixin and "BackdropTemplate")
		frameParent.goal_page.content.imgEdge.picture:SetKeepModelOnHide(true);
		frameParent.goal_page.content.imgEdge.picture:SetSize(525,330);
		frameParent.goal_page.content.imgEdge.picture:SetPoint("TOPLEFT");
		frameParent.goal_page.content.imgEdge.picture:SetCamDistanceScale(collectionInfoGoal.Model.camDist);
		frameParent.goal_page.content.imgEdge.picture:SetRotation(collectionInfoGoal.Model.rotation);
		if (collectionInfoGoal.Model.id ~= "player") then
			frameParent.goal_page.content.imgEdge.picture:SetDisplayInfo(collectionInfoGoal.Model.id);
		end
		frameParent.goal_page.content.imgEdge.picture:SetBackdrop({ bgFile = "Interface/AddOns/WoWChallenger/images/mounts/bg_mounts",
				  tile = false,
				  insets = { left = 0, right = 0, top = 0, bottom = 0 }})
		frameParent.goal_page.content.imgEdge.picture:SetFrameLevel(6);
		frameParent.goal_page.content.imgEdge.picture.cursorX = 0;
		frameParent.goal_page.content.imgEdge.picture:SetScript("OnMouseDown", core.libs.ModelOnMouseDown)
		frameParent.goal_page.content.imgEdge.picture:SetScript("OnMouseUp", core.libs.ModelOnMouseUp)
		
		frameParent.goal_page.content.imgEdge.picture.btnPlus = CreateFrame("Button", nil, frameParent.goal_page.content.imgEdge.picture, "UIPanelButtonTemplate");
		frameParent.goal_page.content.imgEdge.picture.btnPlus:SetSize(120, 25);
		frameParent.goal_page.content.imgEdge.picture.btnPlus:SetText(core.L["Next"]);
		frameParent.goal_page.content.imgEdge.picture.btnPlus:SetPoint("BOTTOM", frameParent.goal_page.content.imgEdge.picture, "BOTTOM", 0, 20);
		frameParent.goal_page.content.imgEdge.picture.btnPlus:SetScript("OnClick", function(self)
			PageCollection_OnClick(_G["Collection"..idTab.."Frame"..iDisplayColl.."ContentPage1"]);
		end);
	end
end

local function onWaitSetTransmogOnModel(frame, sourceID)
	frame:TryOn(sourceID);
end

local function setTransmogOnModel(frame, itemsId, modID)
	frame:SetUnit("player");
	for iTransmo = 1, #itemsId do
		local _, sourceID = 0;
		if (modID ~= nil) then
			_, sourceID = C_TransmogCollection.GetItemInfo(itemsId[iTransmo], modID[iTransmo]);
		else
			_, sourceID = C_TransmogCollection.GetItemInfo(itemsId[iTransmo]);
		end
		core.cpgn.WC_wait(0.75, onWaitSetTransmogOnModel, frame, sourceID);
	end
end

function PageCollection_OnClick(self)
	_G[self.parentName.."PageGoalContent"]:Hide();
	for i = 1, core.libs.tablelength(core.DB_Collections[self.tabId][self.collectionId].page) do
		_G[self.parentName.."Page"..i.."Content"]:Hide();
		if (i == 1 or core.libs.ifDoneAllPrevPage(core.DB_Collections[self.tabId][self.collectionId], i) == true) then
			if (core.libs.ifDonePage(core.DB_Collections[self.tabId][self.collectionId].page[i]) == true) then
				_G[self.parentName.."Page"..i]:SetNormalTexture(core.DB_Collections[self.tabId][self.collectionId].page[i].icon.."_done");
				_G[self.parentName.."Page"..i]:SetHighlightTexture(core.DB_Collections[self.tabId][self.collectionId].page[i].icon.."_done");
				_G[self.parentName.."Page"..i].saveIcon = core.DB_Collections[self.tabId][self.collectionId].page[i].icon.."_done";
				_G[self.parentName.."Page"..i].selected = false;
			else
				_G[self.parentName.."Page"..i]:SetNormalTexture(core.DB_Collections[self.tabId][self.collectionId].page[i].icon);
				_G[self.parentName.."Page"..i]:SetHighlightTexture(core.DB_Collections[self.tabId][self.collectionId].page[i].icon);
				_G[self.parentName.."Page"..i].saveIcon = core.DB_Collections[self.tabId][self.collectionId].page[i].icon;
				_G[self.parentName.."Page"..i].selected = false;
			end
		else
			_G[self.parentName.."Page"..i]:SetNormalTexture(core.DB_Collections[self.tabId][self.collectionId].page[i].icon.."_lock");
			_G[self.parentName.."Page"..i]:SetHighlightTexture(core.DB_Collections[self.tabId][self.collectionId].page[i].icon.."_lock");
		end
	end
	if (core.DB_Collections[self.tabId][self.collectionId]["info"][2] == true) then
		_G[self.parentName.."PageGoal"]:SetNormalTexture(core.DB_Collections[self.tabId][self.collectionId].icon.."_goal_done");
		_G[self.parentName.."PageGoal"]:SetHighlightTexture(core.DB_Collections[self.tabId][self.collectionId].icon.."_goal_done");
		_G[self.parentName.."PageGoal"].selected = false;
	else
		_G[self.parentName.."PageGoal"]:SetNormalTexture(core.DB_Collections[self.tabId][self.collectionId].icon.."_goal");
		_G[self.parentName.."PageGoal"]:SetHighlightTexture(core.DB_Collections[self.tabId][self.collectionId].icon.."_goal");
		_G[self.parentName.."PageGoal"].selected = false;
	end
	_G[self.parentName.."PageGoalModel"]:SetFacing(core.DB_Collections[self.tabId][self.collectionId].Model.rotation);
	if (self.modelType ~= nil and self.modelType.id == "player") then
		setTransmogOnModel(_G[self.parentName.."PageGoalModel"], self.modelType.items, self.modelType.modID);
	end
	PlaySound("681", "sfx");
	self:SetNormalTexture(self.saveIcon.."_selected");
	self:SetHighlightTexture(self.saveIcon.."_selected");
	self.selected = true;
	self.content:Show();
end

local function PageImgNext_OnClick(self)
	if (self.collectionInfo.page[self:GetParent().pageId].imgT[self:GetParent().imgId].id + 1 <= core.libs.tablelength(self.collectionInfo.page[self:GetParent().pageId].imgT)) then
		for i = 1, core.libs.tablelength(self.collectionInfo.page[self:GetParent().pageId].imgT) do
			_G[self.parentName.."Page"..self:GetParent().pageId.."ContentImg"..i]:Hide();
		end
		_G[self.parentName.."Page"..self:GetParent().pageId.."ContentImg"..(self:GetParent().imgId + 1)]:Show();
		PlaySound("21966", "sfx");
	end
end

local function PageImgPrev_OnClick(self)
	if (self.collectionInfo.page[self:GetParent().pageId].imgT[self:GetParent().imgId].id - 1 >= 1) then
		for i = 1, core.libs.tablelength(self.collectionInfo.page[self:GetParent().pageId].imgT) do
			_G[self.parentName.."Page"..self:GetParent().pageId.."ContentImg"..i]:Hide();
		end
		_G[self.parentName.."Page"..self:GetParent().pageId.."ContentImg"..(self:GetParent().imgId - 1)]:Show();
		PlaySound("21966", "sfx");
	end
end

local function ShowMap_OnClick(self)
	if (self.activate == false) then
		self.activate = true;
		self:SetNormalTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_on");
		self:SetPushedTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_on");
		self:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_on");
		for i = 1, core.libs.tablelength(self.infoMap.pins) do
			self.pin = CreateFrame("Button", "WoWChallengerPin", WorldMapFrame)
			self.pin.infoMap = self.infoMap;
			if (self.infoMap.littlePin ~= nil) then
				self.pin:SetWidth(20)
				self.pin:SetHeight(20)
			else
				self.pin:SetWidth(45)
				self.pin:SetHeight(45)
			end
			self.pin:EnableMouse(true)
			self.pin:SetFrameLevel(WorldMapFrame:GetFrameLevel() + 2);
			self.pin:SetNormalTexture(self.infoMap.icon);
			self.pin:SetPushedTexture(self.infoMap.icon);
			self.pin:SetHighlightTexture(self.infoMap.icon);
			self.pin:SetScript("OnEnter", OnEnterBtnOnMap);
			self.pin.i = i;
			self.pin:SetScript("OnLeave", OnLeave);
			--HBD_Pins:AddMinimapIconMap(self, self.pin, self.infoMap.pins[i].zone, self.infoMap.pins[i].x, self.infoMap.pins[i].y, false, true)
			HBD_Pins:AddWorldMapIconMap(self, self.pin, self.infoMap.pins[i].zone, self.infoMap.pins[i].x, self.infoMap.pins[i].y, HBD_PINS_WORLDMAP_SHOW_WORLD);
		end
	else
		self.activate = false;
		self:SetNormalTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_off");
		self:SetPushedTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_off");
		self:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_off");
		HBD_Pins:RemoveAllWorldMapIcons(self);
		HBD_Pins:RemoveAllMinimapIcons(self);
	end
	OnEnterBtnShowMap(self);
end


local function CreateTaskCollection(CollectionTask, frameParent, StepPrevDone, collectionDone)
	local frameParentName = frameParent:GetName();
	frameParent.obj = CreateFrame("Button", frameParentName.."Task"..CollectionTask.id, frameParent);
	if (CollectionTask.id == 1) then
			frameParent.obj:SetPoint("TOPLEFT", frameParent, "TOPLEFT", 0, -5);
		else
			frameParent.obj:SetPoint("LEFT", _G[frameParentName.."Task"..(CollectionTask.id - 1)], "LEFT", 0, -40);
	end
	frameParent.obj.text = frameParent.obj:CreateFontString(frameParentName.."Task"..CollectionTask.id.."Text", "OVERLAY", frameParent.obj);
	frameParent.obj.checkImg = CreateFrame("Frame", frameParentName.."Task"..CollectionTask.id.."CheckImg", frameParent.obj, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.obj.checkImg:SetSize(32, 32);
	frameParent.obj.checkImg:SetPoint("LEFT", frameParent.obj, "LEFT", -3, 0);
	frameParent.obj.text:SetJustifyH("LEFT");
	frameParent.obj.text:SetSize(frameParent:GetWidth()-15, 0);
	frameParent.obj.text:SetPoint("LEFT", frameParent.obj, "LEFT", 25, 0);
	frameParent.obj.taskForTooltip = frameParent.obj:GetName();
	frameParent.obj.idTab = g_idTab;
	frameParent.obj.itemImg = CreateFrame("Frame", frameParentName.."Task"..CollectionTask.id.."ItemImg", frameParent.obj, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.obj.itemImg:SetSize(22, 22);
	frameParent.obj.itemImg:SetPoint("LEFT", frameParent.obj, "LEFT", 25, 0);
	if (CollectionTask["need"] ~= nil) then
		local _, itemLink = GetItemInfo(CollectionTask["need"].itemId)
		frameParent.obj.itemImg.itemLink = itemLink;
	end
	
	if (StepPrevDone == true) then
		frameParent.obj:SetSize(frameParent:GetWidth(), 40);
		if (CollectionTask["hf"] ~= nil) then
			if (CollectionTask["hf"][4] == true) then
				frameParent.obj.checkImg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
				frameParent.obj.text:SetFontObject("GameFontGreenLarge");
			else
				frameParent.obj.text:SetFontObject("GameFontHighlightLarge");
			end
			frameParent.obj.text:SetText(CollectionTask["hf"][2]);
		elseif (CollectionTask["quest"] ~= nil) then
			if (CollectionTask["quest"].completed == true) then
				frameParent.obj.checkImg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
				frameParent.obj.text:SetFontObject("GameFontGreenLarge");
			else
				frameParent.obj.text:SetFontObject("GameFontHighlightLarge");
			end
			if (CollectionTask["quest"].title == nil) then
				frameParent.obj.text:SetText("|c007D7D7d"..core.L["QuestNotDis"].."|r");
			else
				frameParent.obj.text:SetText(CollectionTask["quest"].title);
			end
		elseif (CollectionTask["custom"] ~= nil) then
			frameParent.obj.path = CollectionTask;
			if (CollectionTask["custom"].done == true) then
				frameParent.obj.checkImg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
				frameParent.obj.text:SetFontObject("GameFontGreenLarge");
			else
				frameParent.obj.text:SetFontObject("GameFontHighlightLarge");
			end
			frameParent.obj.text:SetText(CollectionTask["custom"].title);
			if (collectionDone == true) then
				frameParent.obj:SetScript("OnClick", nil)
			else
				frameParent.obj:SetScript("OnClick", OnClickTaskNeed)
			end
		elseif (CollectionTask["need"] ~= nil) then
			frameParent.obj.path = CollectionTask;
			if (CollectionTask["need"].done == true) then
				frameParent.obj.checkImg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
				frameParent.obj.itemImg:SetBackdrop({bgFile = CollectionTask["need"].itemIcon});
				frameParent.obj.itemImg.taskForTooltip = CollectionTask;
				frameParent.obj.itemImg.itemLink = CollectionTask["need"].itemId;
				frameParent.obj.itemImg:SetScript("OnEnter", lootOnEnterTaskIconItem);
				frameParent.obj.itemImg:SetScript("OnLeave", OnLeave);
				frameParent.obj.text:SetSize(frameParent:GetWidth()-20, 0);
				frameParent.obj.text:SetPoint("LEFT", frameParent.obj.itemImg, "LEFT", 25, 0);
				frameParent.obj.text:SetFontObject("GameFontGreenLarge");
				frameParent.obj.text:SetText("x"..tostring(CollectionTask["need"].nbNeed)..core.L["Required"]);
				local item = Item:CreateFromItemID(CollectionTask["need"].itemId)
				item:ContinueOnItemLoad(function()
					CollectionTask["need"].itemInfo[1] = GetItemInfo(CollectionTask["need"].itemId);
				end)
			else							
				frameParent.obj.itemImg:SetBackdrop({bgFile = CollectionTask["need"].itemIcon});
				frameParent.obj.itemImg.taskForTooltip = CollectionTask;
				frameParent.obj.itemImg:SetScript("OnEnter", lootOnEnterTaskIconItem);
				frameParent.obj.itemImg:SetScript("OnLeave", OnLeave);
				frameParent.obj.text:SetSize(frameParent:GetWidth()-20, 0);
				frameParent.obj.text:SetPoint("LEFT", frameParent.obj.itemImg, "LEFT", 25, 0);
				frameParent.obj.text:SetFontObject("GameFontHighlightLarge");							
				frameParent.obj.text:SetText("x"..tostring(CollectionTask["need"].nbNeed)..core.L["Required"]);
				local item = Item:CreateFromItemID(CollectionTask["need"].itemId)
				item:ContinueOnItemLoad(function()
					CollectionTask["need"].itemInfo[1] = GetItemInfo(CollectionTask["need"].itemId);
				end)
			end
			if (collectionDone == true) then
				frameParent.obj:SetScript("OnClick", nil)
			else
				frameParent.obj:SetScript("OnClick", OnClickTaskNeed);
			end
		end
		frameParent.obj:SetScript("OnEnter", lootOnEnterTask);
		frameParent.obj:SetScript("OnLeave", OnLeave);
	else
		if (CollectionTask.id == 1) then
			_G[frameParentName.."Task1Text"]:SetFontObject("GameFontHighlight");
			_G[frameParentName.."Task1Text"]:SetText(core.L["EtapeLock"]);
			_G[frameParentName.."Task1Text"]:SetJustifyH("LEFT");
			_G[frameParentName.."Task1Text"]:SetSize(frameParent:GetWidth(), 0);
			_G[frameParentName.."Task1Text"]:SetPoint("LEFT", frameParent, "LEFT", 25, 0);
		end
	end
end


local function CreateStepCollection(CollectionStep, frameParent, nbStep, StepPrevDone, collectionDone)
	local frameParentName = frameParent:GetName();
	frameParent.title = CreateFrame("Frame", frameParentName..CollectionStep.id, frameParent, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.title:SetSize(256, 32);
	frameParent.title:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/step_title_bg"});
	frameParent.title.text = frameParent.title:CreateFontString(frameParentName..CollectionStep.id.."TitleText", "OVERLAY");
	frameParent.title.text:SetFontObject("GameFontWhite");
	frameParent.title.text:SetText(core.L["Etape"].." "..CollectionStep.id.."/"..nbStep..core.L["2points"]);
	frameParent.title.text:SetPoint("LEFT", frameParent.title, "LEFT", 10, 0);
	
	frameParent.taskBg = CreateFrame("Frame", frameParentName..CollectionStep.id.."Content", frameParent.title, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.title.iconHelp = CreateFrame("Frame", frameParentName..CollectionStep.id.."iconHelp", frameParent, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.title.iconHelp:SetPoint("RIGHT", frameParent.title, "RIGHT", -5, 0);
	frameParent.title.iconHelp:SetFrameLevel(15);
	frameParent.title.iconHelp:SetSize(20, 20);
	if (CollectionStep.help ~= nil) then
		frameParent.title.iconHelp.helpForTooltip = CollectionStep.help;
	elseif (CollectionStep.helpI ~= nil) then
		frameParent.title.iconHelp.helpForTooltipImp = CollectionStep.helpI;
	end
	
	if (StepPrevDone == true) then
		if (core.libs.ifDoneStep(CollectionStep) == true) then
			frameParent.title.text:SetText(core.L["Etape"].." "..CollectionStep.id.."/"..nbStep..core.L["2points"]..core.L["Acheve"]);
		end
		frameParent.taskBg:SetSize(252, core.libs.heightBgTask(CollectionStep.task)+10);
		frameParent.taskBg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/step_task_bg"});
		frameParent.taskBg:SetPoint("TOP", frameParent.title, "BOTTOM", 0, 5);
		if (CollectionStep.help ~= nil) then
			frameParent.title.iconHelp:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/helpIconStep"});
			frameParent.title.iconHelp:SetScript("OnEnter", lootOnEnterIconHelp);
			frameParent.title.iconHelp:SetScript("OnLeave", OnLeave);
		elseif (CollectionStep.helpI ~= nil) then
			frameParent.title.iconHelp:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/helpIconStep2"});
			frameParent.title.iconHelp:SetScript("OnEnter", lootOnEnterIconHelpImp);
			frameParent.title.iconHelp:SetScript("OnLeave", OnLeave);
		end
	else
		frameParent.taskBg:SetSize(252, 50);
		frameParent.taskBg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/step_task_bg"});
		frameParent.taskBg:SetPoint("TOP", frameParent.title, "BOTTOM", 0, 5);
		frameParent.title.iconHelp:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/lockIconStep"});
		frameParent.title.iconHelp:SetScript("OnEnter", lootOnEnterIconLock);
		frameParent.title.iconHelp:SetScript("OnLeave", OnLeave);
	end

	if (CollectionStep.id == 1) then
		frameParent.title:SetPoint("TOP", frameParent, "TOP", -8, -10);
	else
		frameParent.title:SetPoint("BOTTOM", _G[frameParentName..(CollectionStep.id - 1).."Content"], "BOTTOM", 0, -40);
	end
	
	if (CollectionStep.task ~= nil) then
		for i = 1, core.libs.tablelength(CollectionStep.task) do
			CreateTaskCollection(CollectionStep.task[i], frameParent.taskBg, StepPrevDone, collectionDone);
		end
	end
end


local function CreatePageCollection(frameParent, CollectionInfoPage, PagePrevDone, CollectionInfo)
	local frameParentName = frameParent:GetName();
	frameParent.page = CreateFrame("Button", frameParentName.."Page"..CollectionInfoPage.id, frameParent);
	frameParent.page:SetSize(36, 36);
	frameParent.page:SetFrameLevel(7);
	frameParent.page.selected = false;
	frameParent.page.tabId = g_idTab;
	frameParent.page.parentName = frameParentName;
	frameParent.page.collectionId = CollectionInfo.id;
	frameParent.page.collectionPageId = CollectionInfoPage.id;
	if (core.libs.ifDonePage(CollectionInfoPage) == true) then
		frameParent.page:SetNormalTexture(CollectionInfoPage.icon.."_done");
		frameParent.page:SetHighlightTexture(CollectionInfoPage.icon.."_done");
		frameParent.page.saveIcon = CollectionInfoPage.icon.."_done";
	else
		frameParent.page:SetNormalTexture(CollectionInfoPage.icon);
		frameParent.page:SetHighlightTexture(CollectionInfoPage.icon);
		frameParent.page.saveIcon = CollectionInfoPage.icon;
	end
	if (PagePrevDone == true) then
		frameParent.page:SetScript("OnClick", PageCollection_OnClick);
	else
		frameParent.page:SetNormalTexture(CollectionInfoPage.icon.."_lock");
		frameParent.page:SetHighlightTexture(CollectionInfoPage.icon.."_lock");
		frameParent.page:SetScript("OnClick", PageCollection_OnClick_Lock);
	end
	frameParent.page:SetScript("OnEnter", OnEnterPageCollection);
	frameParent.page:SetScript("OnLeave", OnLeave);
	
	frameParent.page.arrow = CreateFrame("Frame", nil, frameParent, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.page.arrow:SetSize(16, 32);
	frameParent.page.arrow:SetFrameLevel(7);
	frameParent.page.arrow:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/arrowRight"});
	frameParent.page:SetPoint("TOPLEFT", frameParent.bar_page, "TOPLEFT", core.libs.centerListObjectXByWidth((CollectionInfoPage.id*2)-1, core.libs.tablelength(CollectionInfo.page)*2, 470, 36)+30, -10);
	frameParent.page.arrow:SetPoint("TOPLEFT", frameParent.bar_page, "TOPLEFT", core.libs.centerListObjectXByWidth((CollectionInfoPage.id*2), core.libs.tablelength(CollectionInfo.page)*2, 470, 36)+35, -13);

	frameParent.page.content = CreateFrame("Frame", frameParentName.."Page"..CollectionInfoPage.id.."Content", frameParent);
	frameParent.page.content:SetSize(545, 333);
	frameParent.page.content:SetPoint("BOTTOM", frameParent, "BOTTOM", 0, 3);
	frameParent.page.content:Hide();
	
	frameParent.page.content.imgEdge = CreateFrame("Frame", nil, frameParent.page.content, BackdropTemplateMixin and "BackdropTemplate");
	frameParent.page.content.imgEdge:SetSize(235, 338);
	frameParent.page.content.imgEdge:SetPoint("BOTTOMLEFT", frameParent.page.content, "BOTTOMLEFT", -2, 0);
	frameParent.page.content.imgEdge:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/edge_character_pct"});
	frameParent.page.content.imgEdge:SetFrameLevel(7);
	
	
	for i = 1, core.libs.tablelength(CollectionInfoPage.imgT) do
		frameParent.page.content.imgEdge.picture = CreateFrame("Frame", frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i, frameParent.page.content.imgEdge, BackdropTemplateMixin and "BackdropTemplate");
		frameParent.page.content.imgEdge.picture:SetSize(227, 332);
		frameParent.page.content.imgEdge.picture:SetPoint("CENTER", frameParent.page.content.imgEdge, "CENTER", -2, -1);
		frameParent.page.content.imgEdge.picture:SetBackdrop({bgFile = CollectionInfoPage.imgT[i].path});
		frameParent.page.content.imgEdge.picture:SetFrameLevel(6);
		frameParent.page.content.imgEdge.picture.pageId = CollectionInfoPage.id;
		frameParent.page.content.imgEdge.picture.tabId = g_idTab;
		frameParent.page.content.imgEdge.picture.collectionInfo = CollectionInfoPage;
		frameParent.page.content.imgEdge.picture.imgId = i;
		if (CollectionInfoPage.imgT[i].title ~= nil) then
			frameParent.page.content.imgEdge.picture.title = frameParent.page.content.imgEdge.picture:CreateFontString(frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i.."Title"..i, "OVERLAY");
			frameParent.page.content.imgEdge.picture.title:SetFontObject("GameFontNormalLarge");
			frameParent.page.content.imgEdge.picture.title:SetText(CollectionInfoPage.imgT[i].title);
			frameParent.page.content.imgEdge.picture.title:SetPoint("BOTTOM", frameParent.page.content.imgEdge.picture, "BOTTOM", 0, 45);
			frameParent.page.content.imgEdge.picture.title:SetSize(frameParent.page.content.imgEdge.picture:GetWidth(), 0);
		end
		if (CollectionInfoPage.imgT[i].onMap ~= nil) then
			frameParent.page.content.imgEdge.picture.showOnMap = CreateFrame("Button", frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i.."BtnShowMap"..i, frameParent.page.content.imgEdge.picture);
			frameParent.page.content.imgEdge.picture.showOnMap:SetSize(25, 25);
			frameParent.page.content.imgEdge.picture.showOnMap:SetPoint("TOPRIGHT", frameParent.page.content.imgEdge.picture, "TOPRIGHT", -5, -5);
			frameParent.page.content.imgEdge.picture.showOnMap:SetNormalTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_off");
			frameParent.page.content.imgEdge.picture.showOnMap:SetPushedTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_off");
			frameParent.page.content.imgEdge.picture.showOnMap:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/challenges/btn_showMap_off");
			frameParent.page.content.imgEdge.picture.showOnMap:SetFrameLevel(7);
			frameParent.page.content.imgEdge.picture.showOnMap.infoMap = CollectionInfoPage.imgT[i].onMap;
			frameParent.page.content.imgEdge.picture.showOnMap.activate = false;
			frameParent.page.content.imgEdge.picture.showOnMap:SetScript("OnEnter", OnEnterBtnShowMap);
			frameParent.page.content.imgEdge.picture.showOnMap:SetScript("OnLeave", OnLeave);
			frameParent.page.content.imgEdge.picture.showOnMap:SetScript("OnClick", ShowMap_OnClick);
		end
		if (CollectionInfoPage.imgT[i].stepAssigned ~= nil) then
			frameParent.page.content.imgEdge.picture.stepAssignedText = frameParent.page.content.imgEdge.picture:CreateFontString(frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i.."StepAssigned"..i, "OVERLAY");
			frameParent.page.content.imgEdge.picture.stepAssignedText:SetFontObject("GameFontWhite");
			frameParent.page.content.imgEdge.picture.stepAssignedText:SetText(core.L["Etape"].." "..tostring(CollectionInfoPage.imgT[i].stepAssigned));
			frameParent.page.content.imgEdge.picture.stepAssignedText:SetPoint("TOPLEFT", frameParent.page.content.imgEdge.picture, "TOPLEFT", 10, -10);
		end
		frameParent.page.content.imgEdge.picture.buttonL = CreateFrame("Button", frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i.."BtnL", frameParent.page.content.imgEdge.picture);
		frameParent.page.content.imgEdge.picture.buttonL.collectionInfo = CollectionInfo;
		frameParent.page.content.imgEdge.picture.buttonL.parentName = frameParentName;
		frameParent.page.content.imgEdge.picture.buttonL:SetSize(32, 32);
		frameParent.page.content.imgEdge.picture.buttonL:SetPoint("BOTTOM", frameParent.page.content.imgEdge.picture, "BOTTOM", -40, 10);
		frameParent.page.content.imgEdge.picture.buttonL:SetNormalTexture("Interface/Buttons/UI-SpellbookIcon-PrevPage-Disabled");
		frameParent.page.content.imgEdge.picture.buttonL:SetScript("OnClick", PageImgPrev_OnClick);
		
		frameParent.page.content.imgEdge.picture.buttonR = CreateFrame("Button", frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i.."BtnR", frameParent.page.content.imgEdge.picture);
		frameParent.page.content.imgEdge.picture.buttonR.collectionInfo = CollectionInfo;
		frameParent.page.content.imgEdge.picture.buttonR.parentName = frameParentName;
		frameParent.page.content.imgEdge.picture.buttonR:SetSize(32, 32);
		frameParent.page.content.imgEdge.picture.buttonR:SetPoint("BOTTOM", frameParent.page.content.imgEdge.picture, "BOTTOM", 40, 10);
		frameParent.page.content.imgEdge.picture.buttonR:SetNormalTexture("Interface/Buttons/UI-SpellbookIcon-NextPage-Up");
		frameParent.page.content.imgEdge.picture.buttonR:SetPushedTexture("Interface/Buttons/UI-SpellbookIcon-NextPage-Down");
		frameParent.page.content.imgEdge.picture.buttonR:SetHighlightTexture("Interface/Buttons/UI-Common-MouseHilight");
		frameParent.page.content.imgEdge.picture.buttonR:SetScript("OnClick", PageImgNext_OnClick);
		if (i == core.libs.tablelength(CollectionInfoPage.imgT)) then
			frameParent.page.content.imgEdge.picture.buttonR:SetNormalTexture("Interface/Buttons/UI-SpellbookIcon-NextPage-Disabled");
			frameParent.page.content.imgEdge.picture.buttonR:SetPushedTexture("Interface/Buttons/UI-SpellbookIcon-NextPage-Disabled");
			frameParent.page.content.imgEdge.picture.buttonR:SetHighlightTexture("");
		else
			frameParent.page.content.imgEdge.picture.buttonR:SetNormalTexture("Interface/Buttons/UI-SpellbookIcon-NextPage-Up");
			frameParent.page.content.imgEdge.picture.buttonR:SetPushedTexture("Interface/Buttons/UI-SpellbookIcon-NextPage-Down");
			frameParent.page.content.imgEdge.picture.buttonR:SetHighlightTexture("Interface/Buttons/UI-Common-MouseHilight");
		end
		if (i == 1) then
			frameParent.page.content.imgEdge.picture.buttonL:SetNormalTexture("Interface/Buttons/UI-SpellbookIcon-PrevPage-Disabled");
			frameParent.page.content.imgEdge.picture.buttonL:SetPushedTexture("Interface/Buttons/UI-SpellbookIcon-PrevPage-Disabled");
			frameParent.page.content.imgEdge.picture.buttonL:SetHighlightTexture("");
		else
			frameParent.page.content.imgEdge.picture.buttonL:SetNormalTexture("Interface/Buttons/UI-SpellbookIcon-PrevPage-Up");
			frameParent.page.content.imgEdge.picture.buttonL:SetPushedTexture("Interface/Buttons/UI-SpellbookIcon-PrevPage-Down");
			frameParent.page.content.imgEdge.picture.buttonL:SetHighlightTexture("Interface/Buttons/UI-Common-MouseHilight");
		end
		frameParent.page.content.imgEdge.picture.text = frameParent.page.content.imgEdge.picture:CreateFontString(frameParentName.."Page"..CollectionInfoPage.id.."ContentImg"..i.."Text", "OVERLAY");
		frameParent.page.content.imgEdge.picture.text:SetFontObject("GameFontHighlight");
		frameParent.page.content.imgEdge.picture.text:SetText(i.."/"..core.libs.tablelength(CollectionInfoPage.imgT));
		frameParent.page.content.imgEdge.picture.text:SetPoint("BOTTOM", frameParent.page.content.imgEdge.picture, "BOTTOM", 0, 20);
		if (i == 1) then
			frameParent.page.content.imgEdge.picture:Show();
		else
			frameParent.page.content.imgEdge.picture:Hide();
		end
	end
	
	frameParent.page.content.ScrollFrame = CreateFrame("ScrollFrame",  nil, frameParent.page.content, "UIPanelScrollFrameTemplate");
	frameParent.page.content.ScrollFrame:SetSize(315, 335);
	frameParent.page.content.ScrollFrame:SetPoint("BOTTOMRIGHT", frameParent.page.content, "BOTTOMRIGHT");
	frameParent.page.content.ScrollFrame:SetClipsChildren(true);
	frameParent.page.content.ScrollFrame.ScrollBar:ClearAllPoints();
	frameParent.page.content.ScrollFrame.ScrollBar:SetPoint("TOPRIGHT", frameParent.page.content.ScrollFrame, "TOPRIGHT", -1, -18);
	frameParent.page.content.ScrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", frameParent.page.content.ScrollFrame, "BOTTOMRIGHT", -1, 18);
	frameParent.page.content.ScrollFrame.child = CreateFrame("Frame", frameParentName.."Page"..CollectionInfoPage.id.."ContentStep", frameParent.page.content.ScrollFrame);
	frameParent.page.content.ScrollFrame.child:SetSize(315, 335);
	frameParent.page.content.ScrollFrame:SetScrollChild(frameParent.page.content.ScrollFrame.child);
	frameParent.page.content.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);
	
	if (CollectionInfoPage.step ~= nil) then
		for i = 1, core.libs.tablelength(CollectionInfoPage.step) do
			if (i == 1 or core.libs.ifDoneAllPrevStep(CollectionInfoPage, CollectionInfoPage.step[i].id) == true) then
				CreateStepCollection(CollectionInfoPage.step[i], frameParent.page.content.ScrollFrame.child, core.libs.tablelength(CollectionInfoPage.step), true, CollectionInfo["info"][2]);
			else
				CreateStepCollection(CollectionInfoPage.step[i], frameParent.page.content.ScrollFrame.child, core.libs.tablelength(CollectionInfoPage.step), false, CollectionInfo["info"][2]);
			end
		end
	end
end

local function createTabTemplate(idTab, frameParent)
	g_idTab = idTab;
	local bgTab = CreateFrame("Frame", "bgTab"..idTab.."Frame", frameParent);
	bgTab:SetSize(800,450);
	bgTab:SetPoint("CENTER", frameParent, "CENTER")
	
	ListTab = CreateFrame("Frame", "ListTab"..idTab.."Frame", bgTab, BackdropTemplateMixin and "BackdropTemplate");
	ListTab:SetSize(245,450);
	ListTab:SetPoint("LEFT", bgTab, "LEFT", 1, 0);
	ListTab:SetBackdrop({bgFile = "Interface/FrameGeneral/UI-Background-Marble",
						edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
						tile = false, edgeSize = 16, 
						insets = { left = 0, right = 3, top = 0, bottom = 0 }});
	ListTab.title_fond = CreateFrame("Frame", "UIListTab"..idTab.."TitleFrame", ListTab, BackdropTemplateMixin and "BackdropTemplate");
	ListTab.title_fond:SetSize(ListTab:GetWidth()+6, 65);
	ListTab.title_fond:SetPoint("TOP", ListTab, "TOP", 0, 4);
	ListTab.title_fond:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/title_fond",
									tile = false,
									insets = { left = 0, right = 0, top = 0, bottom = 0 }
									});
	ListTab.title_fond.text = ListTab.title_fond:CreateFontString("UIListCollection"..idTab.."TitleTextFrame", "OVERLAY", ListTab.title_fond);
	ListTab.title_fond.text:SetSize(ListTab.title_fond:GetWidth(), 0);
	ListTab.title_fond.text:SetFontObject("GameFontHighlightLarge");
	
	
	local nbDone = getNbCollectionDone(idTab);
	local nbMax = getNbMaxCollection(idTab);
	if (nbDone == 0) then
		ListTab.title_fond.text:SetText(core.L["CollectionName"][idTab].." |cffff0000"..nbDone.."/"..nbMax.."|r");
	elseif (nbDone == nbMax) then
		ListTab.title_fond.text:SetText(core.L["CollectionName"][idTab].." |cff1eff00"..nbDone.."/"..nbMax.."|r");
	else
		ListTab.title_fond.text:SetText(core.L["CollectionName"][idTab].." "..nbDone.."/"..nbMax);
	end
	ListTab.title_fond.text:SetPoint("CENTER", ListTab.title_fond, "CENTER", 0, 0);
	
	ListTab.ScrollFrame = CreateFrame("ScrollFrame", nil, ListTab, "UIPanelScrollFrameTemplate");
	ListTab.ScrollFrame:SetPoint("TOPLEFT", ListTab, "TOPLEFT", 0, -50);
	ListTab.ScrollFrame:SetPoint("BOTTOMRIGHT", ListTab, "BOTTOMRIGHT", 0, 0);
	ListTab.ScrollFrame:SetClipsChildren(true);
	ListTab.ScrollFrame.ScrollBar:ClearAllPoints();
	ListTab.ScrollFrame.ScrollBar:SetPoint("TOPRIGHT", ListTab.ScrollFrame, "TOPRIGHT", -4, -20);
	ListTab.ScrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", ListTab.ScrollFrame, "BOTTOMRIGHT", -4, 19);
	local child = CreateFrame("Frame", nil, ListTab.ScrollFrame);
	child:SetSize(220, 396);
	ListTab.ScrollFrame:SetScrollChild(child);
	ListTab.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);

	local PageTab = CreateFrame("Frame", "PageTab"..idTab.."Frame", bgTab, BackdropTemplateMixin and "BackdropTemplate");
	PageTab:SetSize(555,450);
	PageTab:SetBackdrop({bgFile = "Interface/TALENTFRAME/spec-paper-bg",
							edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
							tile = false, edgeSize = 16, 
							insets = { left = 0, right = -170, top = 0, bottom = -71 }});
	PageTab:SetPoint("BOTTOMRIGHT", bgTab, "BOTTOMRIGHT", -2, 0);
	PageTab.ScrollFrame = CreateFrame("ScrollFrame", nil, PageTab, "UIPanelScrollFrameTemplate");
	PageTab.ScrollFrame:SetPoint("TOPLEFT", PageTab, "TOPLEFT", 0, 0);
	PageTab.ScrollFrame:SetPoint("BOTTOMRIGHT", PageTab, "BOTTOMRIGHT", 0, 0);
	PageTab.ScrollFrame:SetClipsChildren(true);
	local childPageTab = CreateFrame("Frame", nil, PageTab.ScrollFrame);
	childPageTab:SetSize(555, 450);
	PageTab.ScrollFrame:SetScrollChild(childPageTab);
	PageTab.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);
	
	PageTab.ScrollFrame.text = PageTab.ScrollFrame:CreateFontString(nil, "OVERLAY", PageTab.ScrollFrame);
	PageTab.ScrollFrame.text:SetFontObject("GameFontHighlightLarge");
	PageTab.ScrollFrame.text:SetText(core.L["SelectCollectionsText"][idTab]);
	PageTab.ScrollFrame.text:SetPoint("CENTER", PageTab.ScrollFrame, "CENTER");
	
	local function TabDiff_Unselected_all()
		for i = 1, core.libs.tablelength(core.DB_DisplayCollections[idTab]) do
			_G["Collection"..idTab.."Btn"..i]:SetNormalTexture("Interface/AddOns/WoWChallenger/images/mounts/button_mount");
			_G["Collection"..idTab.."Btn"..i]:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/mounts/button_highlight_mount");
			_G["Collection"..idTab.."Frame"..i.."ContentPageGoalModel"]:SetFacing(core.DB_Collections[idTab][core.DB_DisplayCollections[idTab][i]].Model.rotation);
		end
	end
			
	local function CollectionBtn_OnClick(self)
		PlaySound("83", "sfx");
		TabDiff_Unselected_all();
		self:SetNormalTexture("Interface/AddOns/WoWChallenger/images/mounts/button_clicked_mount");
		self:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/mounts/button_highlight_mount");
		self:GetParent().content:Show();
		local scrollChild = PageTab.ScrollFrame:GetScrollChild();
		if (scrollChild) then
			scrollChild:Hide();
		end
		PageTab.ScrollFrame:SetScrollChild(self:GetParent().content);
		self:GetParent().content:Show();
	end
	
	local function CreateButtonCollection(CollectionInfo, frameParent, iDisplayColl)
		local CollectionFrame = CreateFrame("Frame", "Collection"..idTab.."Frame"..iDisplayColl, frameParent);
		CollectionFrame:SetSize(frameParent:GetWidth(), 45);
		if (iDisplayColl == 1) then
			CollectionFrame:SetPoint("TOP", frameParent, "TOP", 8, -5);
		else
			CollectionFrame:SetPoint("BOTTOM", _G["Collection"..idTab.."Frame"..(iDisplayColl - 1)], "BOTTOM", 0, -47);
		end
		CollectionFrame.button = CreateFrame("Button", "Collection"..idTab.."Btn"..iDisplayColl, CollectionFrame);
		CollectionFrame.button:SetSize(175, 45);
		CollectionFrame.button:SetPoint("RIGHT", CollectionFrame, "RIGHT", -5, 0);
		CollectionFrame.button:SetNormalTexture("Interface/AddOns/WoWChallenger/images/mounts/button_mount");
		CollectionFrame.button:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/mounts/button_highlight_mount");
		CollectionFrame.button:SetScript("OnClick", CollectionBtn_OnClick);
		
		CollectionFrame.button.bg_faction = CreateFrame("Frame", nil, CollectionFrame.button, BackdropTemplateMixin and "BackdropTemplate");
		CollectionFrame.button.bg_faction:SetSize(57, 57);
		CollectionFrame.button.bg_faction:SetPoint("RIGHT", CollectionFrame.button, "RIGHT", 5, 0);
		if (CollectionInfo.flag ~= nil and CollectionInfo.faction == "Horde") then
			CollectionFrame.button.bg_faction:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/button_bg_horde"});
		elseif (CollectionInfo.flag ~= nil and CollectionInfo.faction == "Alliance") then
			CollectionFrame.button.bg_faction:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/button_bg_alliance"});			
		end
		
		CollectionFrame.text = CollectionFrame.button:CreateFontString("Collection"..idTab.."Btn"..iDisplayColl.."Text", "OVERLAY", CollectionFrame.button);
		CollectionFrame.text:SetSize(CollectionFrame.button:GetWidth()-20, 0);
		if (CollectionInfo["info"][2] == true) then
			CollectionFrame.text:SetFontObject("GameFontGreen");
			SetAllDoneNeed(CollectionInfo.id, idTab);
		else
			CollectionFrame.text:SetFontObject("GameFontNormal");
		end
		CollectionFrame.text:SetText(CollectionInfo["info"][1]);
		CollectionFrame.text:SetJustifyH("LEFT");
		CollectionFrame.text:SetPoint("LEFT", CollectionFrame.button, "LEFT", 10, 0);
		
		CollectionFrame.icon = CreateFrame("Frame", nil, CollectionFrame, BackdropTemplateMixin and "BackdropTemplate");
		CollectionFrame.icon:SetSize(45, 45);
		CollectionFrame.icon:SetPoint("LEFT", CollectionFrame, "LEFT", -5, 0);
		CollectionFrame.icon:SetBackdrop({bgFile = CollectionInfo.icon});
		CollectionFrame.icon.infoCollectionForTooltip = CollectionInfo;
		CollectionFrame.icon.anchor = "ANCHOR_LEFT";
		CollectionFrame.icon:SetScript("OnEnter", OnEnterBtnCollection);
		CollectionFrame.icon:SetScript("OnLeave", OnLeave);
		
		CollectionFrame.content = CreateFrame("Frame", "Collection"..idTab.."Frame"..iDisplayColl.."Content", PageTab, BackdropTemplateMixin and "BackdropTemplate");
		CollectionFrame.content:SetSize(555,450);
		CollectionFrame.content:Hide();
		CollectionFrame.content:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/bg_step_challenge",
								edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
								tile = false, edgeSize = 16, 
								insets = { left = 3, right = 0, top = 0, bottom = 0 }});
		CollectionFrame.content.title = CollectionFrame.content:CreateFontString("Collection"..idTab.."Frame"..iDisplayColl.."ContentTitle", "OVERLAY", CollectionFrame.content);
		if GetLocale() == "ruRU" then
			CollectionFrame.content.title:SetFont("Interface\\AddOns\\WoWChallenger\\fonts\\FRIZQT__CYR.TTF", 20, "OUTLINE");
		else
			CollectionFrame.content.title:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE");
		end
		CollectionFrame.content.title:SetText(CollectionInfo["info"][1]);
		CollectionFrame.content.title:SetPoint("TOP", CollectionFrame.content, "TOP", 0, -15);
		
		CollectionFrame.content.btnRefresh = CreateFrame("Button", "Collection"..idTab.."Frame"..iDisplayColl.."ContentBtnRefresh", CollectionFrame.content);
		CollectionFrame.content.btnRefresh:SetSize(30, 30);
		CollectionFrame.content.btnRefresh:SetPoint("TOPRIGHT", CollectionFrame.content, "TOPRIGHT", -25, -12);
		CollectionFrame.content.btnRefresh:SetNormalTexture("Interface/AddOns/WoWChallenger/images/mounts/button_refresh_ui");
		CollectionFrame.content.btnRefresh:SetPushedTexture("Interface/AddOns/WoWChallenger/images/mounts/button_refresh_ui_down");
		CollectionFrame.content.btnRefresh:SetHighlightTexture("Interface/Buttons/UI-Common-MouseHilight");
		CollectionFrame.content.btnRefresh.idTab = idTab;
		CollectionFrame.content.btnRefresh:SetScript("OnEnter", OnEnterRefreshUICollection);
		CollectionFrame.content.btnRefresh:SetScript("OnLeave", OnLeave);
		CollectionFrame.content.btnRefresh:SetScript("OnClick", btnRefreshCollection_OnClick);
		
		CollectionFrame.content.bar_page = CreateFrame("Frame", nil, CollectionFrame.content, BackdropTemplateMixin and "BackdropTemplate");
		CollectionFrame.content.bar_page:SetSize(548, 55);
		CollectionFrame.content.bar_page:SetPoint("TOP", CollectionFrame.content, "TOP", -10, -60);
		CollectionFrame.content.bar_page:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/fond_progress_page"});
		
		if (core.libs.checkFactionandClass(CollectionInfo.faction, CollectionInfo.class) == false) then
			CollectionFrame:Hide();
			if (iDisplayColl == 1) then
				CollectionFrame:SetPoint("TOP", frameParent, "TOP", 8, 42);
			else
				CollectionFrame:SetPoint("BOTTOM", _G["Collection"..idTab.."Frame"..(iDisplayColl - 1)], "BOTTOM", 0, 0);	
			end
		end
		
		CreatePageGoalCollection(CollectionFrame.content, CollectionInfo, idTab, iDisplayColl);
		for i = 1, core.libs.tablelength(CollectionInfo.page) do
			if (i == 1 or core.libs.ifDoneAllPrevPage(CollectionInfo, i) == true) then
				CreatePageCollection(CollectionFrame.content, CollectionInfo.page[i], true, CollectionInfo);
			else
				CreatePageCollection(CollectionFrame.content, CollectionInfo.page[i], false, CollectionInfo);
			end
		end
		PageCollection_OnClick(_G["Collection"..idTab.."Frame"..iDisplayColl.."ContentPageGoal"]);
	end
	
	for i = 1, #core.DB_DisplayCollections[idTab] do
		CreateButtonCollection(core.DB_Collections[idTab][core.DB_DisplayCollections[idTab][i]], child, i);
	end
end
core.libs.createTabTemplate = createTabTemplate;

----- UPDATE_COLLECTIONS -----
local function UpdateCollections(idTab)
	loaded = LoadAddOn("WoWChallenger");
	if (loaded == nil) then
		print("Error to refresh addon");
	else
		core.loadDB_Collections(idTab);
		local idb = core.DB_DisplayCollections[idTab];
		for i = 1, core.libs.tablelength(idb) do
			local dbToCheck = core.DB_Collections[idTab];
			_G["Collection"..idTab.."Frame"..i].icon.infoCollectionForTooltip = dbToCheck[idb[i]];
			_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"].infoCollectionForTooltip = dbToCheck[idb[i]];
			local nbDone = getNbCollectionDone(idTab);
			local nbMax = getNbMaxCollection(idTab);
			if (nbDone == 0) then
				_G["UIListCollection"..idTab.."TitleTextFrame"]:SetText(core.L["CollectionName"][idTab].." |cffff0000"..nbDone.."/"..nbMax.."|r");
			elseif (nbDone == nbMax) then
				_G["UIListCollection"..idTab.."TitleTextFrame"]:SetText(core.L["CollectionName"][idTab].." |cff1eff00"..nbDone.."/"..nbMax.."|r");
			else
				_G["UIListCollection"..idTab.."TitleTextFrame"]:SetText(core.L["CollectionName"][idTab].." "..nbDone.."/"..nbMax);
			end
			_G["Collection"..idTab.."Btn"..i.."Text"]:SetFontObject("GameFontNormal");
			_G["Collection"..idTab.."Btn"..i.."Text"]:SetText(dbToCheck[idb[i]]["info"][1]);
			_G["Collection"..idTab.."Frame"..i.."ContentTitle"]:SetText(dbToCheck[idb[i]]["info"][1]);
			if (dbToCheck[idb[i]]["info"][2] == true) then
				_G["Collection"..idTab.."Btn"..i.."Text"]:SetFontObject("GameFontGreen");
				SetAllDoneNeed(dbToCheck[idb[i]].id, idTab);
				if (_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"].selected == true) then
					_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"]:SetNormalTexture(dbToCheck[idb[i]].icon.."_goal_done_selected");
					_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"]:SetHighlightTexture(dbToCheck[idb[i]].icon.."_goal_done_selected");
				else
					_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"]:SetNormalTexture(dbToCheck[idb[i]].icon.."_goal_done");
					_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"]:SetHighlightTexture(dbToCheck[idb[i]].icon.."_goal_done");	
				end
				_G["Collection"..idTab.."Frame"..i.."ContentPageGoal"].saveIcon = dbToCheck[idb[i]].icon.."_goal_done";
			end
			for i2 = 1, core.libs.tablelength(dbToCheck[idb[i]].page) do
				if (i2 == 1 or core.libs.ifDoneAllPrevPage(dbToCheck[idb[i]], i2) == true) then
					_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetScript("OnClick", PageCollection_OnClick);
					if (core.libs.ifDonePage(dbToCheck[idb[i]].page[i2]) == true) then
						if (_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2].selected == true) then
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetNormalTexture(dbToCheck[idb[i]].page[i2].icon.."_done_selected");
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetHighlightTexture(dbToCheck[idb[i]].page[i2].icon.."_done_selected");								
						else
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetNormalTexture(dbToCheck[idb[i]].page[i2].icon.."_done");
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetHighlightTexture(dbToCheck[idb[i]].page[i2].icon.."_done");
						end
					else
						if (_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2].selected == true) then
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetNormalTexture(dbToCheck[idb[i]].page[i2].icon.."_selected");
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetHighlightTexture(dbToCheck[idb[i]].page[i2].icon.."_selected");								
						else
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetNormalTexture(dbToCheck[idb[i]].page[i2].icon);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetHighlightTexture(dbToCheck[idb[i]].page[i2].icon);
						end
					end
				else
					_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetNormalTexture(dbToCheck[idb[i]].page[i2].icon.."_lock");
					_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetHighlightTexture(dbToCheck[idb[i]].page[i2].icon.."_lock");
					_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2]:SetScript("OnClick", PageCollection_OnClick_Lock);
				end
				for i3 = 1, core.libs.tablelength(dbToCheck[idb[i]].page[i2].step) do
					if (i3 == 1 or core.libs.ifDoneAllPrevStep(dbToCheck[idb[i]].page[i2], dbToCheck[idb[i]].page[i2].step[i3].id) == true) then
						if (core.libs.ifDoneStep(dbToCheck[idb[i]].page[i2].step[i3]) == true) then
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetText(core.L["Etape"].." "..dbToCheck[idb[i]].page[i2].step[i3].id.."/"..core.libs.tablelength(dbToCheck[idb[i]].page[i2].step)..core.L["2points"]..core.L["Acheve"]);
						else
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetText(core.L["Etape"].." "..dbToCheck[idb[i]].page[i2].step[i3].id.."/"..core.libs.tablelength(dbToCheck[idb[i]].page[i2].step)..core.L["2points"]);
						end
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."Content"]:SetSize(252, core.libs.heightBgTask(dbToCheck[idb[i]].page[i2].step[i3].task)+10);
						if (dbToCheck[idb[i]].page[i2].step[i3].help ~= nil) then
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/helpIconStep"});
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetSize(20, 20);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", lootOnEnterIconHelp);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -5, 0);
						elseif (dbToCheck[idb[i]].page[i2].step[i3].helpI ~= nil) then
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/helpIconStep2"});
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetSize(20, 20);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", lootOnEnterIconHelpImp);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -5, 0);
						else
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = ""});
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", OnLeave);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -10000, 0);
						end
						for i4 = 1, core.libs.tablelength(dbToCheck[idb[i]].page[i2].step[i3].task) do
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetSize(_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3]:GetWidth(), 40);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetSize(_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."Content"]:GetWidth()-15, 0);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetPoint("LEFT", "Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4, "LEFT", 25, 0);
							if (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["hf"] ~= nil) then
								if (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["hf"][4] == true) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText(dbToCheck[idb[i]].page[i2].step[i3].task[i4]["hf"][2]);
							elseif (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["quest"] ~= nil) then
								if (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["quest"].completed == true) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								if (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["quest"].title == nil) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText("|c007D7D7d"..core.L["QuestNotDis"].."|r");
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText(dbToCheck[idb[i]].page[i2].step[i3].task[i4]["quest"].title);
								end
							elseif (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["custom"] ~= nil) then
								if (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["custom"].done == true) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = ""});
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText(dbToCheck[idb[i]].page[i2].step[i3].task[i4]["custom"].title);
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4].path = dbToCheck[idb[i]].page[i2].step[i3].task[i4];
								if (dbToCheck[idb[i]]["info"][2] == true) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", nil);
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", OnClickTaskNeed);
								end
							elseif (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["need"] ~= nil) then
								if (dbToCheck[idb[i]].page[i2].step[i3].task[i4]["need"].done == true) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = ""});
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetPoint("LEFT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4], "LEFT", 25, 0);
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetBackdrop({bgFile = dbToCheck[idb[i]].page[i2].step[i3].task[i4]["need"].itemIcon});
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetPoint("LEFT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"], "LEFT", 25, 0);
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4].path = dbToCheck[idb[i]].page[i2].step[i3].task[i4];
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetSize(_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:GetWidth()-20, 0);
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText("x"..tostring(dbToCheck[idb[i]].page[i2].step[i3].task[i4]["need"].nbNeed)..core.L["Required"]);
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetScript("OnEnter", lootOnEnterTaskIconItem);
								_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetScript("OnLeave", OnLeave);
								if (dbToCheck[idb[i]]["info"][2] == true) then
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", nil);
								else
									_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", OnClickTaskNeed);
								end
							end
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnEnter", lootOnEnterTask);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:Show();
						end
					else
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetText(core.L["Etape"].." "..dbToCheck[idb[i]].page[i2].step[i3].id.."/"..core.libs.tablelength(dbToCheck[idb[i]].page[i2].step)..core.L["2points"]);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetPoint("LEFT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3], "LEFT", 10, 0);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1Text"]:SetFontObject("GameFontHighlight");
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1Text"]:SetText(core.L["EtapeLock"]);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1Text"]:SetPoint("LEFT", "Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1", "LEFT", 25, 0);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetSize(_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3]:GetWidth(), 40);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetScript("OnEnter", OnLeave);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetScript("OnLeave", OnLeave);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1CheckImg"]:SetBackdrop({bgFile = ""});
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1ItemImg"]:SetBackdrop({bgFile = ""});
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1ItemImg"]:SetScript("OnEnter", OnLeave);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -5, 0);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/lockIconStep"});
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", lootOnEnterIconLock);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."Content"]:SetSize(252, 50);
						_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetScript("OnClick", PageCollection_OnClick_Lock);
						for z = 2, core.libs.tablelength(dbToCheck[idb[i]].page[i2].step[i3].task) do
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..z]:Hide();
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..z.."ItemImg"]:SetBackdrop({bgFile = ""});
							_G["Collection"..idTab.."Frame"..i.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..z]:SetScript("OnClick", PageCollection_OnClick_Lock);
						end
					end
				end
			end
		end
	end
end
core.UpdateCollections = UpdateCollections;

local function UpdateCollectionsSpecific(idTab, icollection)
	loaded = LoadAddOn("WoWChallenger");
	if (loaded == nil) then
		print("Error to refresh addon");
	else
		core.loadDB_Collections(idTab);
		
		local idb = 0;
		for i = 1, #core.DB_DisplayCollections[idTab] do
			if (core.DB_DisplayCollections[idTab][i] == icollection) then
				idb = i;
				break;
			end
		end
		if (idb ~= 0) then
			local dbToCheck = core.DB_Collections[idTab][icollection];
			_G["Collection"..idTab.."Frame"..idb].icon.infoCollectionForTooltip = dbToCheck;
			_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"].infoCollectionForTooltip = dbToCheck;
			
			_G["Collection"..idTab.."Btn"..idb.."Text"]:SetText(dbToCheck["info"][1]);
			_G["Collection"..idTab.."Frame"..idb.."ContentTitle"]:SetText(dbToCheck["info"][1]);
			if (dbToCheck["info"][2] == true) then
				_G["Collection"..idTab.."Btn"..idb.."Text"]:SetFontObject("GameFontGreen");
				SetAllDoneNeed(dbToCheck.id, idTab);
				if (_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"].selected == true) then
					_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"]:SetNormalTexture(dbToCheck.icon.."_goal_done_selected");
					_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"]:SetHighlightTexture(dbToCheck.icon.."_goal_done_selected");
				else
					_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"]:SetNormalTexture(dbToCheck.icon.."_goal_done");
					_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"]:SetHighlightTexture(dbToCheck.icon.."_goal_done");	
				end
				_G["Collection"..idTab.."Frame"..idb.."ContentPageGoal"].saveIcon = dbToCheck.icon.."_goal_done";
			end
			for i2 = 1, core.libs.tablelength(dbToCheck.page) do
				if (i2 == 1 or core.libs.ifDoneAllPrevPage(dbToCheck, i2) == true) then
					_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetScript("OnClick", PageCollection_OnClick);
					if (core.libs.ifDonePage(dbToCheck.page[i2]) == true) then
						if (_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2].selected == true) then
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetNormalTexture(dbToCheck.page[i2].icon.."_done_selected");
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetHighlightTexture(dbToCheck.page[i2].icon.."_done_selected");								
						else
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetNormalTexture(dbToCheck.page[i2].icon.."_done");
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetHighlightTexture(dbToCheck.page[i2].icon.."_done");
						end
					else
						if (_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2].selected == true) then
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetNormalTexture(dbToCheck.page[i2].icon.."_selected");
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetHighlightTexture(dbToCheck.page[i2].icon.."_selected");								
						else
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetNormalTexture(dbToCheck.page[i2].icon);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetHighlightTexture(dbToCheck.page[i2].icon);
						end
					end
				else
					_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetNormalTexture(dbToCheck.page[i2].icon.."_lock");
					_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetHighlightTexture(dbToCheck.page[i2].icon.."_lock");
					_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2]:SetScript("OnClick", PageCollection_OnClick_Lock);
				end
				for i3 = 1, core.libs.tablelength(dbToCheck.page[i2].step) do
					if (i3 == 1 or core.libs.ifDoneAllPrevStep(dbToCheck.page[i2], dbToCheck.page[i2].step[i3].id) == true) then
						if (core.libs.ifDoneStep(dbToCheck.page[i2].step[i3]) == true) then
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetText(core.L["Etape"].." "..dbToCheck.page[i2].step[i3].id.."/"..core.libs.tablelength(dbToCheck.page[i2].step)..core.L["2points"]..core.L["Acheve"]);
						else
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetText(core.L["Etape"].." "..dbToCheck.page[i2].step[i3].id.."/"..core.libs.tablelength(dbToCheck.page[i2].step)..core.L["2points"]);
						end
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."Content"]:SetSize(252, core.libs.heightBgTask(dbToCheck.page[i2].step[i3].task)+10);
						if (dbToCheck.page[i2].step[i3].help ~= nil) then
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/helpIconStep"});
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetSize(20, 20);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", lootOnEnterIconHelp);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -5, 0);
						elseif (dbToCheck.page[i2].step[i3].helpI ~= nil) then
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/helpIconStep2"});
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetSize(20, 20);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", lootOnEnterIconHelpImp);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -5, 0);
						else
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = ""});
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", OnLeave);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -10000, 0);
						end
						for i4 = 1, core.libs.tablelength(dbToCheck.page[i2].step[i3].task) do
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetSize(_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3]:GetWidth(), 40);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetSize(_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."Content"]:GetWidth()-15, 0);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetPoint("LEFT", "Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4, "LEFT", 25, 0);
							if (dbToCheck.page[i2].step[i3].task[i4]["hf"] ~= nil) then
								if (dbToCheck.page[i2].step[i3].task[i4]["hf"][4] == true) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText(dbToCheck.page[i2].step[i3].task[i4]["hf"][2]);
							elseif (dbToCheck.page[i2].step[i3].task[i4]["quest"] ~= nil) then
								if (dbToCheck.page[i2].step[i3].task[i4]["quest"].completed == true) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								if (dbToCheck.page[i2].step[i3].task[i4]["quest"].title == nil) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText("|c007D7D7d"..core.L["QuestNotDis"].."|r");
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText(dbToCheck.page[i2].step[i3].task[i4]["quest"].title);
								end
							elseif (dbToCheck.page[i2].step[i3].task[i4]["custom"] ~= nil) then
								if (dbToCheck.page[i2].step[i3].task[i4]["custom"].done == true) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = ""});
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText(dbToCheck.page[i2].step[i3].task[i4]["custom"].title);
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4].path = dbToCheck.page[i2].step[i3].task[i4];
								if (dbToCheck["info"][2] == true) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", nil);
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", OnClickTaskNeed);
								end
							elseif (dbToCheck.page[i2].step[i3].task[i4]["need"] ~= nil) then
								if (dbToCheck.page[i2].step[i3].task[i4]["need"].done == true) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontGreenLarge");
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."CheckImg"]:SetBackdrop({bgFile = ""});
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetFontObject("GameFontHighlightLarge");
								end
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetPoint("LEFT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4], "LEFT", 25, 0);
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetBackdrop({bgFile = dbToCheck.page[i2].step[i3].task[i4]["need"].itemIcon});
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetPoint("LEFT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"], "LEFT", 25, 0);
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4].path = dbToCheck.page[i2].step[i3].task[i4];
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetSize(_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:GetWidth()-20, 0);
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."Text"]:SetText("x"..tostring(dbToCheck.page[i2].step[i3].task[i4]["need"].nbNeed)..core.L["Required"]);
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetScript("OnEnter", lootOnEnterTaskIconItem);
								_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4.."ItemImg"]:SetScript("OnLeave", OnLeave);
								if (dbToCheck["info"][2] == true) then
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", nil);
								else
									_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnClick", OnClickTaskNeed);
								end
							end
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnEnter", lootOnEnterTask);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:SetScript("OnLeave", OnLeave);
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..i4]:Show();
						end
					else
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetText(core.L["Etape"].." "..dbToCheck.page[i2].step[i3].id.."/"..core.libs.tablelength(dbToCheck.page[i2].step)..core.L["2points"]);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."TitleText"]:SetPoint("LEFT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3], "LEFT", 10, 0);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1Text"]:SetFontObject("GameFontHighlight");
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1Text"]:SetText(core.L["EtapeLock"]);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1Text"]:SetPoint("LEFT", "Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1", "LEFT", 25, 0);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetSize(_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3]:GetWidth(), 40);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetScript("OnEnter", OnLeave);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetScript("OnLeave", OnLeave);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1CheckImg"]:SetBackdrop({bgFile = ""});
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1ItemImg"]:SetBackdrop({bgFile = ""});
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1ItemImg"]:SetScript("OnEnter", OnLeave);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetPoint("RIGHT", _G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3], "RIGHT", -5, 0);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/lockIconStep"});
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnEnter", lootOnEnterIconLock);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."iconHelp"]:SetScript("OnLeave", OnLeave);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."Content"]:SetSize(252, 50);
						_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask1"]:SetScript("OnClick", PageCollection_OnClick_Lock);
						for z = 2, core.libs.tablelength(dbToCheck.page[i2].step[i3].task) do
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..z]:Hide();
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..z.."ItemImg"]:SetBackdrop({bgFile = ""});
							_G["Collection"..idTab.."Frame"..idb.."ContentPage"..i2.."ContentStep"..i3.."ContentTask"..z]:SetScript("OnClick", PageCollection_OnClick_Lock);
						end
					end
				end
			end
		end
	end
end
core.UpdateCollectionsSpecific = UpdateCollectionsSpecific;

