require "scripts/style"
local pleft_x = 352.0
local pleft_y = 370.0
local pright_x = 671.0
local pright_y = 370.0

local pleft_w = 290
local pleft_h = 430
local pright_w = 290
local pright_h = 430

local curPage = 0

function SetCurrentPage(pageNum,showLeft,showRight)
	curPage = pageNum
	SetLabel("JournalPageL1",GetString("journal|"..curPage.."_left"))
	SetLabel("JournalPageR1",GetString("journal|"..curPage.."_right"))
	RleftGood = IsPageAccessible(curPage+1,0)
	RrightGood = IsPageAccessible(curPage+1,1)
	if(RleftGood or RrightGood) then
		SetWindowVisible("rightbutton",true)
	else
		SetWindowVisible("rightbutton",false)
	end
	LleftGood = IsPageAccessible(curPage-1,0)
	LrightGood = IsPageAccessible(curPage-1,1)
	if(LleftGood or LrightGood) then
		SetWindowVisible("leftbutton",true)
	else
		SetWindowVisible("leftbutton",false)
	end
end
LeftTextStyle=
{
	parent=DefaultStyle,
	font = {
		standardFont,
		34,
		BlackColor
	},
	x=pleft_x + 5 - pleft_w/2,
	y=pleft_y + 5 - pleft_h/2,
	w=pleft_w,
	h=pleft_h,
	align=kHAlignLeft+kVAlignTop,
};
RightTextStyle=
{
	parent=DefaultStyle,
	font = {
		standardFont,
		34,
		BlackColor
	},
	x=pright_x + 5 - pright_w/2,
	y=pright_y + 5 - pright_h/2,
	w=pright_w,
	h=pright_h,
	align=kHAlignLeft+kVAlignTop,
};
MakeDialog
{
	name="journal",
	JournalWindow
		{
			x=0,
			y=0,
			w=1024,
			h=768,
			rows=gRows,			

			pleftx=pleft_x,
			plefty=pleft_y,
			prightx=pright_x,
			prighty=pright_y,

			columns=gColumns,
			SetStyle(LeftTextStyle),
			Text{
				name="JournalPageL1",
				label="",
			},

			SetStyle(RightTextStyle),
			Text{
				name="JournalPageR1",
				label="",
			},

			SetStyle(ButtonStyle),
			Button{
				name="leftbutton",
				graphics={"ui/journal_menu/arrow_in.png","ui/journal_menu/arrow_out.png","ui/journal_menu/arrow_out.png"},
				x=kCenter-300,
				y=kCenter+200,
				sound="",
				--sound="audio/sfx/sfx_pickuppaper.ogg",
				command = function()
					if curPage > 1 then
						leftGood = IsPageAccessible(curPage-1,0)
						rightGood = IsPageAccessible(curPage-1,1)
						if(leftGood or rightGood) then
							SetCurrentPage(curPage-1,leftGood,rightGood)
						end
					end
				end,
			},
			Button{
				name="rightbutton",
				graphics={"ui/journal_menu/arrow_down.png","ui/journal_menu/arrow_up.png","ui/journal_menu/arrow_up.png"},
				x=kCenter+300,
				y=kCenter+200,
				sound="",
				command = function()
					if curPage < 13 then
						leftGood = IsPageAccessible(curPage+1,0)
						rightGood = IsPageAccessible(curPage+1,1)
						if(leftGood or rightGood) then
							SetCurrentPage(curPage+1,leftGood,rightGood)
						end
					end
				end,
			},
		},
}
