On your test page, it's possible that you're running into the problem described in the 'Using percentage heights' note here.
(You are changing the gallery's parent container's height using JavaScript immediately before loading the gallery and the gallery has been assigned a galleryHeight of 100%.)
I notice that your gallery container comes before the embedding code on your web page.
Try moving your gallery container to after the embedding code on your web page.
My own tests suggest that this might make a difference (but, again, only for a galleryHeight of 100% - other percentages and fixed pixel values should not be affected).
I have notified the developers that, depending on the conditions, a galleryHeight of 100% can sometimes result in an unexpected height. (I have reported both anomalies: (1) a galleryHeight of 100% in a parent container of fixed height without other content on the page and (2) a galleryHeight of 100% in a parent container of fixed height with other content on the page and the gallery container before the embedding code.)
I realise that your test page was designed to show an issue (thank you for providing it) but if it was a problem that you could not overcome, then a solution might be to set your galleryHeight to be your own custom 'galleryHeight' JavaScript variable (which you already use to set the height for your 'header' <div>).
galleryHeight: galleryHeight,
Alternatively, you can always set a gallery's dimensions after the gallery has loaded (for example when the browser window is resized) using the Juicebox-Pro API setGallerySize(width: int, height: int), method. Please note that this method accepts fixed pixel values only (not percentages).