%% The page shift of page #6 needs to be adjusted if the value is changed, no
%% clue why.
%% A4-flyer pagesize needs to be adjusted as well
\definemeasure
	[shortfold]
	[3mm]

\definepapersize
	[A4-flyer]
	[width=303mm,
	 height=216mm]

\definepapersize
	[flyer-page]
	[width=100mm,
	 height=210mm]

\definepapersize
  [flyer-page-small]
	[width=\dimexpr100mm-\measure{shortfold}\relax,
	 height=210mm]

\setuppapersize
	[flyer-page]
	[A4-flyer]

\setuparranging
	[TRYPTICHON]

%% The page shift of page #6 needs to be adjusted if shortfold is adjusted, no
%% clue why.
\definepageshift
	[flyer]
	[horizontal]
	[\zeropoint,
	 \measure{shortfold},
	 \measure{shortfold},
	 3\measured{shortfold},
	 \measure{shortfold},
	 \zeropoint]

\definepageshift
	[flyer]
	[vertical]
	[\measure{shortfold}]

\setuppageshift
	[paper]
	[flyer]

\definemeasure
	[small]
	[3mm]

\definemeasure
	[big]
	[\measure{small}*2]

\definelayout
	[first]
	[page]
	[page=flyer-page,
	 topspace=2\measured{big},
	 backspace=2\measured{small},
	 width=\dimexpr\paperwidth-4\measured{small}\relax,
	 height=\dimexpr\paperheight-4\measured{big}\relax]

\definelayout
	[second]
	[first]
	[topspace=4\measured{big},
	 backspace=2\measured{big},
	 width=\dimexpr\paperwidth-3\measured{big}\relax,
	 height=\dimexpr\paperheight-4\measured{big}-2\measured{big}\relax]

\definelayout
	[thirdandfourth]
	[second]
	[backspace=\measure{big},
	 width=\dimexpr\paperwidth-2\measured{big}\relax]

\definelayout
	[fifthandsixth]
	[first]
	[backspace=\measure{big},
	 width=\dimexpr\paperwidth-2\measured{big}\relax]

\definelayout [1] [first]
\definelayout [2] [second]
\definelayout [3] [thirdandfourth]
\definelayout [4] [thirdandfourth]
\definelayout [5] [fifthandsixth]
\definelayout [6] [fifthandsixth]

\defineoverlay
	[pagedecoration]
	[\useMPgraphic{pagedecoration}]

\setupbackgrounds
	[page]
	[background=pagedecoration,
	 backgroundcolor=lightblue]

\startuseMPgraphic{pagedecoration}
	distanceSmall := 3mm;
	distanceBig   := distanceSmall;
	bleed         := 3mm;

	if PageNumber==1:

		path pageOne;
		pageOne := (0, -bleed) -- (PaperWidth + bleed, -bleed) -- (PaperWidth + bleed, distanceBig)
			-- (2.5distanceBig, distanceBig){left} .. {up}(distanceSmall, 2.5distanceBig)
			-- (distanceSmall, PaperHeight +  bleed) -- (0, PaperHeight + bleed) -- cycle;
		fill pageOne withcolor "lightblue";
		setbounds currentpicture to OverlayBox;

	elseif PageNumber==2:

		path pageTwo;
		pageTwo := (-bleed, -bleed) -- (PaperWidth, -bleed)
			-- (PaperWidth, distanceBig)
			-- (2.5distanceBig, distanceBig){left} .. {up}(distanceBig, 2.5distanceBig)
			-- (distanceBig, PaperHeight + bleed) -- (-bleed, PaperHeight + bleed) -- cycle;
		fill pageTwo withcolor "lightblue";
		setbounds currentpicture to OverlayBox;

	elseif PageNumber==3:

		path pageThree;
		pageThree := (0, -bleed) -- (PaperWidth, -bleed)
			-- (PaperWidth, distanceBig)
			-- (0, distanceBig) -- cycle;
		fill pageThree withcolor "lightblue";
		setbounds currentpicture to OverlayBox;

	elseif PageNumber==4:

	elseif PageNumber==5:

		path pageFive;
		pageFive := (-bleed, -bleed) -- (PaperWidth, -bleed)
			-- (PaperWidth, distanceBig)
			-- (-bleed, distanceBig) -- cycle;
		fill pageFive withcolor "lightblue";
		setbounds currentpicture to OverlayBox;

	elseif PageNumber==6:

		path pageSix;
		pageSix := (distanceSmall, -bleed) -- (PaperWidth, -bleed)
			-- (PaperWidth, PaperHeight-distanceBig)
			-- (2.5distanceBig, PaperHeight-distanceBig){left}
			.. {down}(distanceSmall, PaperHeight-2.5distanceBig) -- cycle;
		fill pageSix withcolor "lightblue";
		setbounds currentpicture to OverlayBox;

	fi
\stopuseMPgraphic

\starttext
	\input knuth \page
	\input knuth \page
	\input knuth \page
	\setuppapersize [flyer-page-small] [A4-flyer]
	\input knuth \page
	\input knuth \page
	\setuppapersize [flyer-page] [A4-flyer]
	\input knuth
\stoptext
