local _, core = ...;

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 AnnoucementFunction()
	AnnoucementShow3 = false;
	PopUp = CreateFrame("Frame", "WoWChallengesAnnoucementFrame", UIParent);
	PopUp:EnableMouse(true)
	PopUp:SetSize(650,475);
	PopUp:SetPoint("CENTER", UIParent, "CENTER");
	PopUp:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/annoucement/bg"});
	PopUp:SetFrameLevel(8);
	PopUp.titlebg = CreateFrame("Frame", nil, PopUp);
	PopUp.titlebg:SetSize(256,64);
	PopUp.titlebg:SetPoint("TOP", PopUp, "TOP", 0, 0);
	PopUp.titlebg:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/annoucement/bg_title"});
	PopUp.titlebg.text = PopUp.titlebg:CreateFontString(nil, "OVERLAY");
	if GetLocale() == "ruRU" then
		PopUp.titlebg.text:SetFont("Interface\\AddOns\\WoWChallenger\\fonts\\FRIZQT__CYR.TTF", 16, "OUTLINE");
	else
		PopUp.titlebg.text:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE");
	end
	PopUp.titlebg.text:SetText("WoW Challenger");
	PopUp.titlebg.text:SetPoint("CENTER", PopUp.titlebg, "CENTER", 0, -5);
	
	PopUp.content = CreateFrame("Frame", nil, PopUp);
	PopUp.content:SetSize(500,350);
	PopUp.content:SetPoint("CENTER", PopUp, "CENTER", 0, 0);
	PopUp.content:SetFrameLevel(11);
	PopUp.content:SetBackdrop({bgFile = "",
								edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
								tile = false, edgeSize = 16, 
								insets = { left = 0, right = 0, top = 0, bottom = 0 }});
	
	PopUp.content.imgEdge = CreateFrame("Frame", nil, PopUp.content);
	PopUp.content.imgEdge:SetSize(200, 348);
	PopUp.content.imgEdge:SetPoint("LEFT", PopUp.content, "LEFT", 3, 1);
	PopUp.content.imgEdge:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/edge_character_pct"});
	PopUp.content.imgEdge:SetFrameLevel(19);
	PopUp.content.imgEdge.picture = CreateFrame("Frame", nil, PopUp.content.imgEdge);
	PopUp.content.imgEdge.picture:SetSize(198, 343);
	PopUp.content.imgEdge.picture:SetPoint("CENTER", PopUp.content.imgEdge, "CENTER", -2, -1);
	PopUp.content.imgEdge.picture:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/annoucement/v1_6"});
	PopUp.content.imgEdge.picture:SetFrameLevel(9);
	
	PopUp.content.zoneText = CreateFrame("Frame", nil, PopUp.content);
	PopUp.content.zoneText:SetSize(298, 345);
	PopUp.content.zoneText:SetPoint("BOTTOMRIGHT", PopUp.content, "BOTTOMRIGHT", -4, 2);
	PopUp.content.zoneText:SetBackdrop({bgFile = "Interface/AddOns/WoWChallenger/images/challenges/bg_step_challenge"});
	PopUp.content.zoneText:SetFrameLevel(9);
	
	PopUp.content.zoneText.Bigtitle = PopUp.content.zoneText:CreateFontString(nil, "OVERLAY");
	if GetLocale() == "ruRU" then
		PopUp.content.zoneText.Bigtitle:SetFont("Interface\\AddOns\\WoWChallenger\\fonts\\FRIZQT__CYR.TTF", 20, "OUTLINE");
	else
		PopUp.content.zoneText.Bigtitle:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE");
	end
	PopUp.content.zoneText.Bigtitle:SetText(core.L["TitleAnnoucement"]);
	PopUp.content.zoneText.Bigtitle:SetPoint("TOP", PopUp.content.zoneText, "TOP", 0, -10);
	
	PopUp.content.zoneText.ScrollFrame = CreateFrame("ScrollFrame",  nil, PopUp.content.zoneText, "UIPanelScrollFrameTemplate");
	PopUp.content.zoneText.ScrollFrame:SetPoint("TOPLEFT", PopUp.content.zoneText, "TOPLEFT", 0, -34);
	PopUp.content.zoneText.ScrollFrame:SetPoint("BOTTOMRIGHT", PopUp.content.zoneText, "BOTTOMRIGHT");
	PopUp.content.zoneText.ScrollFrame:SetClipsChildren(true);
	PopUp.content.zoneText.ScrollFrame.child = CreateFrame("Frame", nil, PopUp.content.zoneText.ScrollFrame);
	PopUp.content.zoneText.ScrollFrame.child:SetSize(280, 245);
	PopUp.content.zoneText.ScrollFrame:SetScrollChild(PopUp.content.zoneText.ScrollFrame.child);
	PopUp.content.zoneText.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);
	
	PopUp.content.zoneText.desc = PopUp.content.zoneText.ScrollFrame.child:CreateFontString(nil, "OVERLAY");
	PopUp.content.zoneText.desc:SetFontObject("QuestFontNormalSmall");
	PopUp.content.zoneText.desc:SetText(core.L["TextAnnoucement"]);
	PopUp.content.zoneText.desc:SetJustifyH("LEFT");
	PopUp.content.zoneText.desc:SetPoint("TOPLEFT", PopUp.content.zoneText.ScrollFrame.child, "TOPLEFT", 10, -10);
	PopUp.content.zoneText.desc:SetSize(270, 0);
	
	PopUp.Closebtn = CreateFrame("Button", "btnCloseFrame", PopUp, "UIPanelButtonTemplate");
	PopUp.Closebtn:SetSize(75, 25);
	PopUp.Closebtn:SetText(core.L["Next"]);
	PopUp.Closebtn:SetPoint("BOTTOM", PopUp, "BOTTOM", 0, 30);
	PopUp.Closebtn:SetScript("OnClick", function(self)
		PlaySound("21967", "sfx");
		self:GetParent():Hide();
		core.Config.Toggle();
	end);
end
core.AnnoucementFunction = AnnoucementFunction;