another alternative to determine orientation, based on comparison of the width/height:
var mql = window.matchMedia("(min-aspect-ratio: 4/3)");
if (mql.matches) {
orientation = 'landscape';
}
You use it on "resize" event:
window.addEventListener("resize", function() { ... });