-------------------------------------------
--					Init						--
-------------------------------------------
require( "scripts/style" );
local kNumberOfPages = 1;
local kCurrentPage = 1;
local kBtnPlayX = 0;
local kBtnPlayY = 0;

-- Check from Metastructure (for coord fixes)
if (gFromMetastructure == 1)
then
	kBtnPlayX = 406;
	kBtnPlayY = 668;
else
	kBtnPlayX = kCenter;
	kBtnPlayY = kMax -100;
end



-- Getting number of pages
if (gCurrentVenue == 1)-- or gCurrentVenue == 2)
then
	--kNumberOfPages = 2;
end

-------------------------------------------
--					Functions					--
-------------------------------------------
function createPages(numPages)
	
	t = { SetStyle(ButtonStyle), BeginGroup()	};
	if (not gCurrentVenue)
	then
		gCurrentVenue = 1;
	end

	
	if (numPages == 2)
	then
			table.insert(t,
				Bitmap
					{
						name = "dialogcomicintro"..gCurrentVenue.."p2",
						image = "backgrounds/dialogs/comics/dialogcomicintro"..gCurrentVenue.."p2",
					}
			);
	end
	
	table.insert(t,
		Bitmap
			{
				name = "dialogcomicintro"..gCurrentVenue.."p1",
				image = "backgrounds/dialogs/comics/dialogcomicintro"..gCurrentVenue.."p1",
			}
	);



	return Group(t);
end

function createSoundAux()
	if (gFromMetastructure == 1)
	then
		return createSoundNext(975,0);
	else
	   return createSound();
	end
end

-------------------------------------------
--					Main Dialog				--
-------------------------------------------
MakeDialog
{
	name = "comicintro",
	
	createPages(kNumberOfPages),

	SetStyle(ButtonStyle),
	Button
	{
		name = "skip",
		x = kCenter,
		y = kMax -100,
		DefaultButtonLabel("skip"),
		type = kPush,
		command =
			function()
				doTransition("goGame");
			end,
	},

	Button
	{
		name = "play",
		x = kBtnPlayX,
		y = kBtnPlayY,
		DefaultButtonLabel("play"),
		type = kPush,
		command =
			function()
				doTransition("goGame");
			end,
	},

	Button
	{
		name = "next",
		x = kCenter + 350,
		y = kMax - 100,
		DefaultButtonLabel("next"),
		type = kPush,
		command=
			function()
				SetWindowVisible("dialogcomicintro"..gCurrentVenue.."p"..kCurrentPage,false);
				kCurrentPage = kCurrentPage+1;
				SetWindowVisible("dialogcomicintro"..gCurrentVenue.."p"..kCurrentPage,true);
				SetWindowVisible("back",true);
				if (kCurrentPage == 2)
				then
					SetWindowVisible("next",false);
					SetWindowVisible("skip",false);
					SetWindowVisible("play",true);
				end
			end,
	},

	Button
	{
		name = "back",
		x = kCenter - 350,
		y = kMax -100,
		DefaultButtonLabel("back"),
		type = kPush,
		command=
			function()
				SetWindowVisible("dialogcomicintro"..gCurrentVenue.."p"..kCurrentPage,false);
				kCurrentPage = kCurrentPage-1;
				SetWindowVisible("dialogcomicintro"..gCurrentVenue.."p"..kCurrentPage,true);
				SetWindowVisible("next",true);
				if (kCurrentPage == 1)
				then
					SetWindowVisible("back",false);	
					SetWindowVisible("skip",true);
					SetWindowVisible("play",false);
				end
			end,
	},
	-- Sound	
	createSoundAux(),
}

-------------------------------------------
--					Finalize					--
-------------------------------------------
SetWindowVisible("back",false);
SetWindowVisible("play",false);
SetWindowVisible("play",false);

if (kNumberOfPages == 1)
then
	SetWindowVisible("next",false);
	SetWindowVisible("skip",false);
	SetWindowVisible("play",true);
end
