require( "scripts/style.lua" );

function NextPage()
	SetHelpPage(GetHelpPage()+1);
	SetLabel("page_number", GetCurrentHelpPageString());
	configButtons();
	ShowHelpPage();
end

function PreviousPage()
	SetHelpPage(GetHelpPage()-1);
	SetLabel("page_number", GetCurrentHelpPageString());
	configButtons();
	ShowHelpPage();
end

MakeDialog
{
	--name=name, -- Remember, this is like saying table['name']=name, so it works.
    FaderWindow
	{
		wait=0,
		duration=100,
		fit = true,
		startalpha = 0,
		finalalpha = 0.99,
		skip = false,
		Bitmap
		{
			image = "backgrounds/shade",
			alpha = 1,
		},
		HelpWindow
		{
			Bitmap
			{
				name = "help_bg",
				image="gui/main/helppage",
				x=kCenter,
				y=kCenter,
				
				Text
				{
					x=0,y=400,w=kMax, h=40,
					flags = kVAlignCenter + kHAlignCenter,
					font = {"fonts/amano.mvec", 40, BlackColor},
					name = "page_number",
					--label = "#"..GetCurrentHelpPageString(),
				},
				
				Window
				{
					name = "help_content",
					x=20,y=0,w=250, h=400,
				},
				
				ShadowedButton
				{
					command = function()
								NextPage();
							  end,
					close = false,
					face = "buttons/scrollright",
					displacement = 1,
					flags = 5,
					name = "next",
					x = 250,
					y = 400,
					scale = 1.5,
				},
				
				ShadowedButton
				{
					command = function()
								PreviousPage();
							  end,
					close = false,
					face = "buttons/scrollleft",
					displacement = 1,
					flags = 5,
					name = "back",
					x = 10,
					y = 400,
					scale = 1.5,
				},
				
				SetStyle(ButtonStdCancelStyle),
				--ShadowedButton
				Button
				{
					clickSound = "audio/sfx/buttons/default_click.ogg",
					--face = "buttons/stdcancel",
					--shadow = "buttons/stddone_shadow",
					--displacement = 2,
					close = true,
					--command = function()
					--			CloseHelpWindow();
					--		  end,
					flags = 5,
					name = "close",
					x = 210,
					y = 0,
				},
			},
		},
	},
} -- MakeDialog

function configButtons()
	local totalPages = GetTotalHelpPages();
	local currentPage = GetHelpPage();
	if(totalPages>1) then
		if(currentPage == 0) then
			EnableWindow("next", true);
			EnableWindow("back", false);
		elseif(currentPage == totalPages-1) then
			EnableWindow("next", false);
			EnableWindow("back", true);
		else
			EnableWindow("next", true);
			EnableWindow("back", true);
		end
	else
		EnableWindow("next", false);
		EnableWindow("back", false);
	end
end

configButtons();
SetLabel("page_number", GetCurrentHelpPageString());