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

local LoadPetsDB = CreateFrame("Frame");
LoadPetsDB:RegisterEvent("PET_JOURNAL_LIST_UPDATE");
LoadPetsDB:SetScript("OnEvent", function()
	core.LoadPets();
	petsDB = core.DBpets;
end)


--- LIBS FUNCTION ---
local function getNbMaxPet()
	local PetMax = 0;
	if (core.DBpets ~= nil) then
		for i = 1, core.libs.tablelength(core.DBpets) do
			local factionPlayer = UnitFactionGroup("player")
			if (factionPlayer == core.DBpets[i].faction or core.DBpets[i].faction == "Neutral") then
				PetMax = PetMax + 1;
			end
		end
	end
	return PetMax;
end
core.libs.getNbMaxPet = getNbMaxPet;

local function getNbPetDone()
	local PetDone = 0;
	if (core.DBpets ~= nil) then
		for i = 1, core.libs.tablelength(core.DBpets) do
			local factionPlayer = UnitFactionGroup("player")
			if (factionPlayer == core.DBpets[i].faction or core.DBpets[i].faction == "Neutral") then
				if (core.DBpets[i]["infoPet"][2] == true) then
					PetDone = PetDone + 1;
				end
			end
		end
	end
	return PetDone;
end
core.libs.getNbPetDone = getNbPetDone;

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 printNPCDroppedLoot(loot)
	local stret = "";
	for i = 1, core.libs.tablelength(loot) do
		if (loot[i].pourcentageDrop ~= 0) then
			stret = stret..loot[i].nameNPC.." ("..loot[i].pourcentageDrop.."%)";
		else
			stret = stret..loot[i].nameNPC;
		end
		if (i ~= core.libs.tablelength(loot)) then
			stret = stret.."|cffffffff, |r";
		end
	end
	return stret;
end

local function printNPCVendor(names)
	local stret = "";
	for i = 1, core.libs.tablelength(names) do
		stret = stret..names[i];
		if (i ~= core.libs.tablelength(names)) then
			stret = stret.."|cffffffff, |r";
		end
	end
	return stret;
end


local function printCompoCreate(create)
	local stret = "";
	for i = 1, core.libs.tablelength(create) do
		local compoName = "";
		local item = Item:CreateFromItemID(create[i].compoId)
		item:ContinueOnItemLoad(function()
			compoName = GetItemInfo(create[i].compoId);
		end)
		if (compoName == "") then
			stret = stret.."Loading";
		else
			stret = stret..compoName;
		end
		stret = stret.." ("..create[i].nbNeed..")";
		if (i ~= core.libs.tablelength(create)) then
			stret = stret.."|cffffffff, |r";
		end
	end
	return stret;
end

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

local function SetAllDoneNeed(PetId)
	for i = 1, core.libs.tablelength(core.DBpets[PetId].page) do
		for j = 1, core.libs.tablelength(core.DBpets[PetId].page[i].step) do		
			for k = 1, core.libs.tablelength(core.DBpets[PetId].page[i].step[j].task) do
				if (core.DBpets[PetId].page[i].step[j].task[k]["need"] ~= nil) then
					if (core.DBpets[PetId].page[i].step[j].task[k]["need"].path ~= nil) then
						core.DBpets[PetId].page[i].step[j].task[k]["need"].done = true;
						local pathSaved = {};
						for z = 1, #core.DBpets[PetId].page[i].step[j].task[k]["need"].path do
							pathSaved[z] = core.DBpets[PetId].page[i].step[j].task[k]["need"].path:sub(z, z)
						end
						DonePetTask[tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;
					end
				elseif (core.DBpets[PetId].page[i].step[j].task[k]["custom"] ~= nil) then
					if (core.DBpets[PetId].page[i].step[j].task[k]["custom"].path ~= nil) then
						core.DBpets[PetId].page[i].step[j].task[k]["custom"].done = true;
						local pathSaved = {};
						for z = 1, #core.DBpets[PetId].page[i].step[j].task[k]["custom"].path do
							pathSaved[z] = core.DBpets[PetId].page[i].step[j].task[k]["custom"].path:sub(z, z)
						end
						DonePetTask2[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
			for i = 1, #self.path["need"].path do
				pathSaved[i] = self.path["need"].path:sub(i, i)
			end
			if (core.DBpets[tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["need"].done == false) then
				core.DBpets[tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["need"].done = true;
				DonePetTask[tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;
			else
				core.DBpets[tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["need"].done = false;
				DonePetTask[tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = false;
			end
			OnLeave();
			core.UpdatePets();
		end
	elseif (self.path["custom"] ~= nil) then
		if (self.path["custom"].path ~= nil) then
			for i = 1, #self.path["custom"].path do
				pathSaved[i] = self.path["custom"].path:sub(i, i)
			end
			if (core.DBpets[tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["custom"].done == false) then
				core.DBpets[tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["custom"].done = true;
				DonePetTask[tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = true;
			else
				core.DBpets[tonumber(pathSaved[1])].page[tonumber(pathSaved[2])].step[tonumber(pathSaved[3])].task[tonumber(pathSaved[4])]["custom"].done = false;
				DonePetTask[tonumber(pathSaved[1])]["page"][tonumber(pathSaved[2])]["step"][tonumber(pathSaved[3])]["task"][tonumber(pathSaved[4])]["done"] = false;
			end
			OnLeave();
			core.UpdatePets();
		end
	end
end

--- GAME TOOLTIP ---
local OnEnterBtnPet = function(self, motion)
	GameTooltip:SetOwner(self, self.anchor, 0, 0);
	GameTooltip:AddLine(self.infoPetForTooltip["infoPet"][1], 1, 1, 1);
	if (self.infoPetForTooltip["infoPet"][2] == true) then
		GameTooltip:AddLine(core.L["MountCollected"], 0, 1, 0);
	else
		GameTooltip:AddLine(core.L["MountNotCollected"], 1, 0, 0);
	end
	GameTooltip:AddLine("\""..self.infoPetForTooltip["extraInfoPet"][1].."\"", 1, 0.82, 0, true);
	GameTooltip:AddLine(self.infoPetForTooltip["extraInfoPet"][2], 1, 1, 1);
	GameTooltip:AddLine(core.L["Expansion"].."|cffffffff"..self.infoPetForTooltip.expansion.."|r");
	GameTooltip:Show();
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 petTask = petsDB[tonumber(words[1])].page[tonumber(words[2])].step[tonumber(words[3])].task[tonumber(words[4])];

	if (petTask["hf"] ~= nil) then
		if (petTask["hf"][4] == true) then
			if (petTask["hf"][14] ~= "") then
				GameTooltip:AddLine(core.L["AcheveBy"].." "..petTask["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(petTask["hf"][8], 1, 1, 1);
	elseif (petTask["quest"] ~= nil) then
		if (petTask["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 (petTask["quest"].completed == true) then
			if (petTask["quest"].desc == core.L["DescQuest"]) then
				GameTooltip:AddLine(core.L["DescQuestComplete"], 1, 1, 1);
			else
				GameTooltip:AddLine(petTask["quest"].desc, 1, 1, 1, true);
			end
		else
			if (petTask["quest"].desc == core.L["DescQuest"]) then
				GameTooltip:AddLine(core.L["DescQuest"], 1, 1, 1);
			else
				GameTooltip:AddLine(petTask["quest"].desc, 1, 1, 1, true);
			end
		end
	elseif (petTask["custom"] ~= nil) then
		if (petTask["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
		GameTooltip:AddLine(tostring(petTask["custom"].desc), 1, 1, 1, true);
		if (petTask["custom"].path ~= nil) then
			GameTooltip:AddLine(" ");
			if (petTask["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 (petTask["need"] ~= nil) then
		if (petTask["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
		if (petTask["need"].path ~= nil) then
			GameTooltip:AddLine(core.L["Obtenir"]..tostring(petTask["need"].nbNeed).." "..petTask["need"].itemInfo[1]..".", 1, 1, 1);
		else
			GameTooltip:AddLine(core.L["Obtenir"]..petTask["need"].itemInfo[1]..".", 1, 1, 1);
		end
		GameTooltip:AddLine(" ");
		local count = GetItemCount(petTask["need"].itemId)
		if (petTask["need"].itemInfo[1] == nil) then
			petTask["need"].itemInfo[1] = "|cffff0000Loading...|r";
		end
		if (petTask["need"].path ~= nil) then
			if (count >= petTask["need"].nbNeed) then
				GameTooltip:AddLine(core.L["HaveItem"]..count.."/"..tostring(petTask["need"].nbNeed).." "..petTask["need"].itemInfo[1]..".", 0, 1, 0);		
			else
				GameTooltip:AddLine(core.L["HaveItem"]..count.."/"..tostring(petTask["need"].nbNeed).." "..petTask["need"].itemInfo[1]..".", 1, 1, 1);
			end
		end
		if (petTask["need"]["loot"] ~= nil) then
			GameTooltip:AddLine("|cffffffff"..core.L["DroppedBy"].."|r"..printNPCDroppedLoot(petTask["need"]["loot"]).."|cffffffff.|r", 1, 0.82, 0, true);
		elseif (petTask["need"]["vendor"] ~= nil) then
			GameTooltip:AddLine("|cffffffff"..core.L["SoldBy"].."|r"..printNPCVendor(petTask["need"]["vendor"]).."|cffffffff.|r");
		elseif (petTask["need"]["create"] ~= nil) then
			GameTooltip:AddLine("|cffffffff"..core.L["CreatedBy"].."|r"..printCompoCreate(petTask["need"]["create"]).."|cffffffff.|r", 1, 0.82, 0, true);
		elseif (petTask["need"]["quest"] ~= nil) then
			GameTooltip:AddLine("|cffffffffTerminer la quête |r"..petTask["need"]["quest"].title.."|cffffffff.|r", 1, 0.82, 0, true);
		end
		if (petTask["need"].path ~= nil) then
			GameTooltip:AddLine(" ");
			if (petTask["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 (petTask["faction"] ~= nil and petTask["MA"] == nil) then
		GameTooltip:AddLine(core.libs.changeReputToText(petTask["faction"]), 1, 1, 1);
	end
	if (petTask["hf"] ~= nil and GetAchievementNumCriteria(petTask["hf"][1]) ~= 0) then
		GameTooltip:AddLine(core.libs.printCriteriaHF(petTask["hf"][1]));
	end
	GameTooltip:Show();
end

local lootOnEnterTaskIconItem = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_LEFT", 0, 0);
	if (self.itemLink ~= nil) then
		GameTooltip:SetHyperlink(self.itemLink)
	else
		GameTooltip:AddLine("|cffff0000Loading Error|r");
	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 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 OnEnterBtnOnMap = function(self, motion)
	GameTooltip:SetOwner(self, "ANCHOR_TOP");
	GameTooltip:AddLine(self.infoMap.nameNPC);
	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 function CreatePetsTab()
	local bgPets = CreateFrame("Frame", "bgPetsFrame", core.Tab.t3.content, nil);
	bgPets:SetSize(800,450);
	bgPets:SetPoint("CENTER", core.Tab.t3.content, "CENTER");
	
	core.nilPetsBg = CreateFrame("Frame", "nilPetsBgFrame", core.Tab.t3.content, nil);
	core.nilPetsBg:SetSize(800,450);
	core.nilPetsBg:SetPoint("CENTER", core.Tab.t3.content, "CENTER");
	core.nilPetsBg:SetFrameLevel(6);
	core.nilPetsBg:SetPropagateKeyboardInput(true)
	core.nilPetsBg:SetBackdrop({bgFile = "Interface/TALENTFRAME/spec-paper-bg",
							edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
							tile = false, edgeSize = 16, 
							insets = { left = 0, right = -241, top = 0, bottom = -71 }});
	core.nilPetsBg.Text = core.nilPetsBg:CreateFontString(nil, "OVERLAY");
	core.nilPetsBg.Text:SetFontObject("GameFontNormalLarge");
	core.nilPetsBg.Text:SetPoint("CENTER");
	core.nilPetsBg.Text:SetSize(core.nilPetsBg:GetWidth()-60, 0);
	core.nilPetsBg.Text:SetText(core.L["TextFilterPets"]);
	core.nilPetsBg:Hide();

	ListPets = CreateFrame("Frame", "ListPetsFrame", bgPets, nil);
	ListPets:SetSize(245,450);
	ListPets:SetPoint("LEFT", bgPets, "LEFT", 1, 0);
	ListPets: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 }});
	ListPets.title_fond = CreateFrame("Frame", "UIListPetsTitleFrame", ListPets, nil);
	ListPets.title_fond:SetSize(ListPets:GetWidth()+6, 65);
	ListPets.title_fond:SetPoint("TOP", ListPets, "TOP", 0, 4);
	ListPets.title_fond:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/title_fond",
												tile = false,
												insets = { left = 0, right = 0, top = 0, bottom = 0 }
												});
	ListPets.title_fond.text = ListPets.title_fond:CreateFontString("UIListPetsTitleTextFrame", "OVERLAY", ListPets.title_fond);
	ListPets.title_fond.text:SetSize(ListPets.title_fond:GetWidth(), 0);
	if (getNbPetDone() == 0) then
		ListPets.title_fond.text:SetFontObject("GameFontRedLarge");
	elseif (getNbPetDone() == getNbMaxPet()) then
		ListPets.title_fond.text:SetFontObject("GameFontGreenLarge");
	else
		ListPets.title_fond.text:SetFontObject("GameFontHighlightLarge");
	end
	ListPets.title_fond.text:SetText(core.L["Pets"].." "..getNbPetDone().."/"..getNbMaxPet());
	ListPets.title_fond.text:SetPoint("CENTER", ListPets.title_fond, "CENTER", 0, 0);
	
	ListPets.ScrollFrame = CreateFrame("ScrollFrame", nil, ListPets, "UIPanelScrollFrameTemplate");
	ListPets.ScrollFrame:SetPoint("TOPLEFT", ListPets, "TOPLEFT", 0, -50);
	ListPets.ScrollFrame:SetPoint("BOTTOMRIGHT", ListPets, "BOTTOMRIGHT", 0, 4);
	ListPets.ScrollFrame:SetClipsChildren(true);
	ListPets.ScrollFrame.ScrollBar:ClearAllPoints();
	ListPets.ScrollFrame.ScrollBar:SetPoint("TOPRIGHT", ListPets.ScrollFrame, "TOPRIGHT", -4, -20);
	ListPets.ScrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", ListPets.ScrollFrame, "BOTTOMRIGHT", -4, 19);
	local child = CreateFrame("Frame", nil, ListPets.ScrollFrame);
	child:SetSize(220, 396);

	ListPets.ScrollFrame:SetScrollChild(child);
	ListPets.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);
	
	local PagePet = CreateFrame("Frame", "PagePetFrame", bgPets, nil);
	PagePet:SetSize(555,450);
	PagePet: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 }});
	PagePet:SetPoint("BOTTOMRIGHT", bgPets, "BOTTOMRIGHT", -2, 0);
	PagePet.ScrollFrame = CreateFrame("ScrollFrame", nil, PagePet, "UIPanelScrollFrameTemplate");
	PagePet.ScrollFrame:SetPoint("TOPLEFT", PagePet, "TOPLEFT", 0, 0);
	PagePet.ScrollFrame:SetPoint("BOTTOMRIGHT", PagePet, "BOTTOMRIGHT", 0, 0);
	PagePet.ScrollFrame:SetClipsChildren(true);
	local childPagePet = CreateFrame("Frame", nil, PagePet.ScrollFrame);
	childPagePet:SetSize(555, 450);
	PagePet.ScrollFrame:SetScrollChild(childPagePet);
	PagePet.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);
	
	PagePet.ScrollFrame.text = PagePet.ScrollFrame:CreateFontString(nil, "OVERLAY", PagePet.ScrollFrame);
	PagePet.ScrollFrame.text:SetFontObject("GameFontHighlightLarge");
	PagePet.ScrollFrame.text:SetText(core.L["SelectPetText"]);
	PagePet.ScrollFrame.text:SetPoint("CENTER", PagePet.ScrollFrame, "CENTER");
	
	local function TabDiff_Unselected_all()
		for i=1, core.libs.tablelength(petsDB) do
			_G["PetBtn"..i]:SetNormalTexture("Interface/AddOns/WoWChallenger/images/mounts/button_mount");
			_G["PetBtn"..i]:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/mounts/button_highlight_mount");
		end
	end
		
	local function TabPet_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 = PagePet.ScrollFrame:GetScrollChild();
		if (scrollChild) then
			scrollChild:Hide();
		end
		PagePet.ScrollFrame:SetScrollChild(self:GetParent().content);
		self:GetParent().content:Show();
	end
	
	local function CreateButtonPets(PetInfo, frameParent, PagePet)
		local PetFrame = CreateFrame("Frame", "PetFrame"..PetInfo.id, frameParent);
		PetFrame:SetSize(frameParent:GetWidth(), 45);
		if (PetInfo.id == 1) then
			PetFrame:SetPoint("TOP", frameParent, "TOP", 8, -5);
		else
			PetFrame:SetPoint("BOTTOM", _G["PetFrame"..(PetInfo.id - 1)], "BOTTOM", 0, -50);
		end
		
		PetFrame.button = CreateFrame("Button", "PetBtn"..PetInfo.id, PetFrame);
		PetFrame.button:SetSize(175, 45);
		PetFrame.button:SetPoint("RIGHT", PetFrame, "RIGHT", -5, 0);
		PetFrame.button:SetNormalTexture("Interface/AddOns/WoWChallenger/images/mounts/button_mount");
		PetFrame.button:SetHighlightTexture("Interface/AddOns/WoWChallenger/images/mounts/button_highlight_mount");
		PetFrame.button:SetScript("OnClick", TabPet_OnClick);
		PetFrame.text = PetFrame.button:CreateFontString("PetBtn"..PetInfo.id.."Text", "OVERLAY", PetFrame.button);
		PetFrame.text:SetSize(PetFrame.button:GetWidth()-20, 0);
		if (PetInfo["infoPet"][2] == true) then
			PetFrame.text:SetFontObject("GameFontGreen");
			SetAllDoneNeed(PetInfo.id);
		else
			PetFrame.text:SetFontObject("GameFontNormal");
		end
		PetFrame.text:SetText(PetInfo["infoPet"][1]);
		PetFrame.text:SetJustifyH("LEFT");
		PetFrame.text:SetPoint("LEFT", PetFrame.button, "LEFT", 10, 0);
		
		PetFrame.icon = CreateFrame("Frame", nil, PetFrame);
		PetFrame.icon:SetSize(45, 45);
		PetFrame.icon:SetPoint("LEFT", PetFrame, "LEFT", -5, 0);
		PetFrame.icon:SetBackdrop({bgFile = PetInfo.icon});
		PetFrame.icon.infoPetForTooltip = PetInfo;
		PetFrame.icon.anchor = "ANCHOR_LEFT";
		PetFrame.icon:SetScript("OnEnter", OnEnterBtnPet);
		PetFrame.icon:SetScript("OnLeave", OnLeave);	

		PetFrame.content = CreateFrame("Frame", "PetFrame"..PetInfo.id.."Content", PagePet);
		PetFrame.content:SetSize(555,450);
		PetFrame.content:Hide();
		PetFrame.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 }});
		PetFrame.content.title = PetFrame.content:CreateFontString("PetFrame"..PetInfo.id.."ContentTitle", "OVERLAY", PetFrame.content);
		if GetLocale() == "ruRU" then
			PetFrame.content.title:SetFont("Interface\\AddOns\\WoWChallenger\\fonts\\FRIZQT__CYR.TTF", 20, "OUTLINE");
		else
			PetFrame.content.title:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE");
		end
		PetFrame.content.title:SetText(PetInfo["infoPet"][1]);
		PetFrame.content.title:SetPoint("TOP", PetFrame.content, "TOP", 0, -15);
		
		PetFrame.content.bar_page = CreateFrame("Frame", nil, PetFrame.content);
		PetFrame.content.bar_page:SetSize(548, 55);
		PetFrame.content.bar_page:SetPoint("TOP", PetFrame.content, "TOP", -10, -60);
		PetFrame.content.bar_page:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/fond_progress_page"});
		local factionPlayer = UnitFactionGroup("player")
		if (factionPlayer ~= PetInfo.faction and PetInfo.faction ~= "Neutral") then
			PetFrame:Hide();
			PetFrame:SetPoint("BOTTOM", _G["PetFrame"..(PetInfo.id - 1)], "BOTTOM", 0, 0);
		end
		
		function PagePet_OnClick_Lock()
			return;
		end
		
		function PagePet_OnClick(self)
			_G["PetFrame"..self.petId.."ContentPageGoalContent"]:Hide();
			for i = 1, core.libs.tablelength(core.DBpets[self.petId].page) do
				_G["PetFrame"..self.petId.."ContentPage"..i.."Content"]:Hide();
				if (i == 1 or core.libs.ifDoneAllPrevPage(core.DBpets[self.petId], i) == true) then
					if (core.libs.ifDonePage(core.DBpets[self.petId].page[i]) == true) then
						_G["PetFrame"..self.petId.."ContentPage"..i]:SetNormalTexture(core.DBpets[self.petId].page[i].icon.."_done");
						_G["PetFrame"..self.petId.."ContentPage"..i]:SetHighlightTexture(core.DBpets[self.petId].page[i].icon.."_done");
						_G["PetFrame"..self.petId.."ContentPage"..i].saveIcon = core.DBpets[self.petId].page[i].icon.."_done";
						_G["PetFrame"..self.petId.."ContentPage"..i].selected = false;
					else
						_G["PetFrame"..self.petId.."ContentPage"..i]:SetNormalTexture(core.DBpets[self.petId].page[i].icon);
						_G["PetFrame"..self.petId.."ContentPage"..i]:SetHighlightTexture(core.DBpets[self.petId].page[i].icon);
						_G["PetFrame"..self.petId.."ContentPage"..i].saveIcon = core.DBpets[self.petId].page[i].icon;
						_G["PetFrame"..self.petId.."ContentPage"..i].selected = false;
					end
				else
					_G["PetFrame"..self.petId.."ContentPage"..i]:SetNormalTexture(core.DBpets[self.petId].page[i].icon.."_lock");
					_G["PetFrame"..self.petId.."ContentPage"..i]:SetHighlightTexture(core.DBpets[self.petId].page[i].icon.."_lock");
				end
			end
			if (core.DBpets[self.petId]["infoPet"][2] == true) then
				_G["PetFrame"..self.petId.."ContentPageGoal"]:SetNormalTexture(core.DBpets[self.petId].icon.."_goal_done");
				_G["PetFrame"..self.petId.."ContentPageGoal"]:SetHighlightTexture(core.DBpets[self.petId].icon.."_goal_done");
				_G["PetFrame"..self.petId.."ContentPageGoal"].selected = false;
			else
				_G["PetFrame"..self.petId.."ContentPageGoal"]:SetNormalTexture(core.DBpets[self.petId].icon.."_goal");
				_G["PetFrame"..self.petId.."ContentPageGoal"]:SetHighlightTexture(core.DBpets[self.petId].icon.."_goal");
				_G["PetFrame"..self.petId.."ContentPageGoal"].selected = false;
			end
			PlaySound("681", "sfx");
			self:SetNormalTexture(self.saveIcon.."_selected");
			self:SetHighlightTexture(self.saveIcon.."_selected");
			self.selected = true;
			self.content:Show();
		end
		
		local function CreatePageGoalPet(frameParent)
			local frameParentName = frameParent:GetName();
			frameParent.goal_page = CreateFrame("Button", frameParentName.."PageGoal", frameParent);
			frameParent.goal_page.selected = false;
			frameParent.goal_page.petId = PetInfo.id;
			frameParent.goal_page:SetSize(58, 58);
			frameParent.goal_page:SetFrameLevel(7);
			frameParent.goal_page:SetPoint("RIGHT", frameParent.bar_page, "RIGHT", -5, -2);
			if (PetInfo["infoPet"][2] == true) then
				frameParent.goal_page:SetNormalTexture(PetInfo.icon.."_goal_done");
				frameParent.goal_page:SetHighlightTexture(PetInfo.icon.."_goal_done");
				frameParent.goal_page.saveIcon = PetInfo.icon.."_goal_done";
			else
				frameParent.goal_page:SetNormalTexture(PetInfo.icon.."_goal");
				frameParent.goal_page:SetHighlightTexture(PetInfo.icon.."_goal");
				frameParent.goal_page.saveIcon = PetInfo.icon.."_goal";
			end
			frameParent.goal_page.infoPetForTooltip = PetInfo;
			frameParent.goal_page.anchor = "ANCHOR_RIGHT";
			frameParent.goal_page:SetScript("OnEnter", OnEnterBtnPet);
			frameParent.goal_page:SetScript("OnLeave", OnLeave);
			frameParent.goal_page:SetScript("OnClick", PagePet_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);
			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 (PetInfo.Model ~= nil) then
				frameParent.goal_page.content.imgEdge.picture = CreateFrame("PlayerModel", nil, frameParent.goal_page.content)
				frameParent.goal_page.content.imgEdge.picture:SetSize(525,330);
				frameParent.goal_page.content.imgEdge.picture:SetPoint("TOPLEFT");
				frameParent.goal_page.content.imgEdge.picture:SetCamDistanceScale(PetInfo.Model.camDist);
				frameParent.goal_page.content.imgEdge.picture:SetRotation(PetInfo.Model.rotation);
				frameParent.goal_page.content.imgEdge.picture:SetDisplayInfo(PetInfo.Model.id);
				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.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)
					PagePet_OnClick(_G["PetFrame"..PetInfo.id.."ContentPage1"]);
				end);
			end
		end
		
		local function PageImgNext_OnClick(self)
			if (PetInfo.page[self:GetParent().pageId].imgT[self:GetParent().imgId].id + 1 <= core.libs.tablelength(PetInfo.page[self:GetParent().pageId].imgT)) then
				for i = 1, core.libs.tablelength(PetInfo.page[self:GetParent().pageId].imgT) do
					_G["PetFrame"..PetInfo.id.."ContentPage"..self:GetParent().pageId.."ContentImg"..i]:Hide();
				end
				_G["PetFrame"..PetInfo.id.."ContentPage"..self:GetParent().pageId.."ContentImg"..(self:GetParent().imgId + 1)]:Show();
				PlaySound("21966", "sfx");
			end
		end
		
		local function PageImgPrev_OnClick(self)
			if (PetInfo.page[self:GetParent().pageId].imgT[self:GetParent().imgId].id - 1 >= 1) then
				for i = 1, core.libs.tablelength(PetInfo.page[self:GetParent().pageId].imgT) do
					_G["PetFrame"..PetInfo.id.."ContentPage"..self:GetParent().pageId.."ContentImg"..i]:Hide();
				end
				_G["PetFrame"..PetInfo.id.."ContentPage"..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", nil, WorldMapFrame)
					self.pin:SetWidth(45)
					self.pin:SetHeight(45)
					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.infoMap = self.infoMap;
					self.pin.i = i;
					self.pin:SetScript("OnLeave", OnLeave);
					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);
			end
			OnLeave();
		end
		
		local function CreatePagePet(frameParent, PetPage, PagePrevDone)
			local frameParentName = frameParent:GetName();
			frameParent.page = CreateFrame("Button", frameParentName.."Page"..PetPage.id, frameParent);
			frameParent.page:SetSize(36, 36);
			frameParent.page:SetFrameLevel(7);
			frameParent.page.selected = false;
			frameParent.page.petId = PetInfo.id;
			if (core.libs.ifDonePage(PetPage) == true) then
				frameParent.page:SetNormalTexture(PetPage.icon.."_done");
				frameParent.page:SetHighlightTexture(PetPage.icon.."_done");
				frameParent.page.saveIcon = PetPage.icon.."_done";
			else
				frameParent.page:SetNormalTexture(PetPage.icon);
				frameParent.page:SetHighlightTexture(PetPage.icon);
				frameParent.page.saveIcon = PetPage.icon;
			end
			local OnEnterPagePet = function(self, motion)
				GameTooltip:SetOwner(self, "ANCHOR_TOP", 0, 3);
				GameTooltip:AddLine(core.L["Chapter"]..PetPage.id);
				GameTooltip:Show();
			end
			if (PagePrevDone == true) then
				frameParent.page:SetScript("OnClick", PagePet_OnClick);
			else
				frameParent.page:SetNormalTexture(PetPage.icon.."_lock");
				frameParent.page:SetHighlightTexture(PetPage.icon.."_lock");
				frameParent.page:SetScript("OnClick", PagePet_OnClick_Lock);
			end
			frameParent.page:SetScript("OnEnter", OnEnterPagePet);
			frameParent.page:SetScript("OnLeave", OnLeave);
			
			frameParent.page.arrrow = CreateFrame("Frame", nil, PetFrame.content);
			frameParent.page.arrrow:SetSize(16, 32);
			frameParent.page.arrrow:SetFrameLevel(7);
			frameParent.page.arrrow:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/mounts/arrowRight"});
			frameParent.page:SetPoint("TOPLEFT", frameParent.bar_page, "TOPLEFT", core.libs.centerListObjectXByWidth((PetPage.id*2)-1, core.libs.tablelength(PetInfo.page)*2, 470, 36)+30, -10);
			frameParent.page.arrrow:SetPoint("TOPLEFT", frameParent.bar_page, "TOPLEFT", core.libs.centerListObjectXByWidth((PetPage.id*2), core.libs.tablelength(PetInfo.page)*2, 470, 36)+35, -13);

			frameParent.page.content = CreateFrame("Frame", frameParentName.."Page"..PetPage.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);
			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(PetPage.imgT) do
				frameParent.page.content.imgEdge.picture = CreateFrame("Frame", frameParentName.."Page"..PetPage.id.."ContentImg"..i, frameParent.page.content.imgEdge);
				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 = PetPage.imgT[i].path});
				frameParent.page.content.imgEdge.picture:SetFrameLevel(6);
				frameParent.page.content.imgEdge.picture.pageId = PetPage.id;
				frameParent.page.content.imgEdge.picture.imgId = i;
				if (PetPage.imgT[i].title ~= nil) then
					frameParent.page.content.imgEdge.picture.title = frameParent.page.content.imgEdge.picture:CreateFontString(frameParentName.."Page"..PetPage.id.."ContentImg"..i.."Title"..i, "OVERLAY");
					frameParent.page.content.imgEdge.picture.title:SetFontObject("GameFontNormalLarge");
					frameParent.page.content.imgEdge.picture.title:SetText(PetPage.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 (PetPage.imgT[i].onMap ~= nil) then
					frameParent.page.content.imgEdge.picture.showOnMap = CreateFrame("Button", frameParentName.."Page"..PetPage.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 = PetPage.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
				frameParent.page.content.imgEdge.picture.buttonL = CreateFrame("Button", frameParentName.."Page"..PetPage.id.."ContentImg"..i.."BtnL", frameParent.page.content.imgEdge.picture);
				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"..PetPage.id.."ContentImg"..i.."BtnR", frameParent.page.content.imgEdge.picture);
				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-SpellbookIcon-NextPage-Up");
				frameParent.page.content.imgEdge.picture.buttonR:SetScript("OnClick", PageImgNext_OnClick);
				if (i == core.libs.tablelength(PetPage.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-SpellbookIcon-NextPage-Up");
				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-SpellbookIcon-PrevPage-Up");
				end
				frameParent.page.content.imgEdge.picture.text = frameParent.page.content.imgEdge.picture:CreateFontString(frameParentName.."Page"..PetPage.id.."ContentImg"..i.."Text", "OVERLAY");
				frameParent.page.content.imgEdge.picture.text:SetFontObject("GameFontHighlight");
				frameParent.page.content.imgEdge.picture.text:SetText(i.."/"..core.libs.tablelength(PetPage.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"..PetPage.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);
			
			local function CreateStepPet(PetStep, frameParent, nbStep, StepPrevDone)
				local frameParentName = frameParent:GetName();
				frameParent.title = CreateFrame("Frame", frameParentName..PetStep.id, frameParent);
				frameParent.title:SetSize(256, 32);
				frameParent.title:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/step_title_bg"});
				frameParent.title.text = frameParent.title:CreateFontString(frameParentName..PetStep.id.."TitleText", "OVERLAY");
				frameParent.title.text:SetFontObject("GameFontWhite");
				frameParent.title.text:SetText(core.L["Etape"].." "..PetStep.id.."/"..nbStep..core.L["2points"]);
				frameParent.title.text:SetPoint("LEFT", frameParent.title, "LEFT", 10, 0);
				
				frameParent.taskBg = CreateFrame("Frame", frameParentName..PetStep.id.."Content", frameParent.title);
				frameParent.title.iconHelp = CreateFrame("Frame", frameParentName..PetStep.id.."iconHelp", frameParent);
				frameParent.title.iconHelp:SetPoint("RIGHT", frameParent.title, "RIGHT", -5, 0);
				frameParent.title.iconHelp:SetFrameLevel(15);
				frameParent.title.iconHelp:SetSize(20, 20);
				if (PetStep.help ~= nil) then
					frameParent.title.iconHelp.helpForTooltip = PetStep.help;
				elseif (PetStep.helpI ~= nil) then
					frameParent.title.iconHelp.helpForTooltipImp = PetStep.helpI;
				end
				if (StepPrevDone == true) then
					if (core.libs.ifDoneStep(PetStep) == true) then
						frameParent.title.text:SetText(core.L["Etape"].." "..PetStep.id.."/"..nbStep..core.L["2points"]..core.L["Acheve"]);
					end
					frameParent.taskBg:SetSize(252, core.libs.heightBgTask(PetStep.task)+10);
					frameParent.taskBg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/step_task_bg"});
					frameParent.taskBg:SetPoint("TOP", frameParent.title, "BOTTOM", 0, 5);
					if (PetStep.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 (PetStep.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 (PetStep.id == 1) then
					frameParent.title:SetPoint("TOP", frameParent, "TOP", -8, -10);
				else
					frameParent.title:SetPoint("BOTTOM", _G[frameParentName..(PetStep.id - 1).."Content"], "BOTTOM", 0, -40);
				end
				
				local function CreateTaskPet(PetTask, frameParent, StepPrevDone)
					local frameParentName = frameParent:GetName();
					frameParent.obj = CreateFrame("Button", frameParentName.."Task"..PetTask.id, frameParent);
					if (PetTask.id == 1) then
							frameParent.obj:SetPoint("TOPLEFT", frameParent, "TOPLEFT", 0, -5);
						else
							frameParent.obj:SetPoint("LEFT", _G[frameParentName.."Task"..(PetTask.id - 1)], "LEFT", 0, -40);
					end
					frameParent.obj.text = frameParent.obj:CreateFontString(frameParentName.."Task"..PetTask.id.."Text", "OVERLAY", frameParent.obj);
					frameParent.obj.checkImg = CreateFrame("Frame", frameParentName.."Task"..PetTask.id.."CheckImg", frameParent.obj);
					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.itemImg = CreateFrame("Frame", frameParentName.."Task"..PetTask.id.."ItemImg", frameParent.obj);
					frameParent.obj.itemImg:SetSize(22, 22);
					frameParent.obj.itemImg:SetPoint("LEFT", frameParent.obj, "LEFT", 25, 0);
					if (PetTask["need"] ~= nil) then
						local _, itemLink = GetItemInfo(PetTask["need"].itemId)
						frameParent.obj.itemImg.itemLink = itemLink;
					end
					if (StepPrevDone == true) then
					frameParent.obj:SetSize(frameParent:GetWidth(), 40);
						if (PetTask["hf"] ~= nil) then
							if (PetTask["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(PetTask["hf"][2]);
						elseif (PetTask["quest"] ~= nil) then
							if (PetTask["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 (PetTask["quest"].title == nil) then
								frameParent.obj.text:SetText("|c007D7D7d"..core.L["QuestNotDis"].."|r");
							else
								frameParent.obj.text:SetText(PetTask["quest"].title);
							end
						elseif (PetTask["custom"] ~= nil) then
							frameParent.obj.path = PetTask;
							if (PetTask["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(PetTask["custom"].title);
							frameParent.obj:SetScript("OnClick", OnClickTaskNeed)
						elseif (PetTask["need"] ~= nil) then
							frameParent.obj.path = PetTask;
							if (PetTask["need"].done == true) then
								frameParent.obj.checkImg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/greenCheckButton"});
								frameParent.obj.itemImg:SetBackdrop({bgFile = PetTask["need"].itemIcon});
								frameParent.obj.itemImg.taskForTooltip = PetTask;
								frameParent.obj.itemImg:SetScript("OnEnter", lootOnEnterTaskIconItem);
								frameParent.obj.itemImg:SetScript("OnLeave", OnLeave);
								local _, itemLink = GetItemInfo(PetTask["need"].itemId)
								frameParent.obj.itemImg.itemLink = itemLink;
								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(PetTask["need"].nbNeed)..core.L["Required"]);
								local item = Item:CreateFromItemID(PetTask["need"].itemId)
								item:ContinueOnItemLoad(function()
									PetTask["need"].itemInfo[1] = GetItemInfo(PetTask["need"].itemId);
								end)
							else							
								frameParent.obj.itemImg:SetBackdrop({bgFile = PetTask["need"].itemIcon});
								frameParent.obj.itemImg.taskForTooltip = PetTask;
								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(PetTask["need"].nbNeed)..core.L["Required"]);
								local item = Item:CreateFromItemID(PetTask["need"].itemId)
								item:ContinueOnItemLoad(function()
									PetTask["need"].itemInfo[1] = GetItemInfo(PetTask["need"].itemId);
								end)
							end
							frameParent.obj:SetScript("OnClick", OnClickTaskNeed);
						end
						frameParent.obj:SetScript("OnEnter", lootOnEnterTask);
						frameParent.obj:SetScript("OnLeave", OnLeave);
					else
						if (PetTask.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
				
				if (PetStep.task ~= nil) then
					for i = 1, core.libs.tablelength(PetStep.task) do
						CreateTaskPet(PetStep.task[i], frameParent.taskBg, StepPrevDone);
					end
				end
			end
			
			if (PetPage.step ~= nil) then
				for i = 1, core.libs.tablelength(PetPage.step) do
					if (i == 1 or core.libs.ifDoneAllPrevStep(PetPage, PetPage.step[i].id) == true) then
						CreateStepPet(PetPage.step[i], frameParent.page.content.ScrollFrame.child, core.libs.tablelength(PetPage.step), true);
					else
						CreateStepPet(PetPage.step[i], frameParent.page.content.ScrollFrame.child, core.libs.tablelength(PetPage.step), false);
					end
				end
			end
		end
		CreatePageGoalPet(PetFrame.content);
		for i = 1, core.libs.tablelength(PetInfo.page) do
			if (i == 1 or core.libs.ifDoneAllPrevPage(PetInfo, i) == true) then
				CreatePagePet(PetFrame.content, PetInfo.page[i], true);
			else
				CreatePagePet(PetFrame.content, PetInfo.page[i], false);
			end
		end
		PagePet_OnClick(_G["PetFrame"..PetInfo.id.."ContentPageGoal"]);
	end
	for i = 1, (core.libs.tablelength(petsDB)) do
		CreateButtonPets(petsDB[i], child, PagePet);
	end
	
end
core.PetsTab = CreatePetsTab;

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