I've been making adaptive app-layouts almost the same way..
The best way is to stay consistent..
instead of using windowwidth and windowheight, keep using the viewportleft, right, top and bottom..
Windowwidth - 40 would become: viewportright(0)-viewportleft(0)-40
windowheight - 40 : viewportbottom(0)-viewporttop(0) -40
the horizontal center of your layout : viewportleft(0)+0.5*(viewportright(0)-viewportleft(0))
Etcetera..
I put most of these values in variables and update them on any change in the windowsize, having different ways of showing things for landscape and portrait and depending on the amount of pixels availabe..
One thing that could be happening on mobile is the app is called fullscreen so when the "on start of layout" event is executed the windowsize is different than a few ticks later when the browser adress bar "re-appears" (This is just a guess/possibility, but can be easily caught by also using the browser-objects "on resized" event to call the set layout function)