Device orientation

Hi there,
did you work on something to detect device orientation ? I mean, for example to detect realtime if the device is on landscape or portrait mode ?
I’m trying to find a method on the net, which could define the first orientation when opening the website, then detecting when it changes, so to modify rules for physics (transforming beta–>gamma and vice-versa). But I’m stucked…
You can see the project I’m working on at this post: Device orientation --> Change element position