Detect if iPhone is rotating as it's rotating?
<p>I have the following code which will update the background image of my page when you rotate it a certain way:</p>

<pre><code>window.onorientationchange = function() {
    var orientation = window.orientation;
    switch (orientation) {
    case 0:
        $(".bg-img").css("background-image", "url(" + portrait + ")");
        break;
    case 90:
        $(".bg-img").css("background-image", "url(" + landscape + ")");
        break;
    case -90:
        $(".bg-img").css("background-image", "url(" + landscape + ")");
        break;
    };
};​
</code></pre>

<p>This works, but when the page is rotated, it takes a few seconds to load the new image, and causes the page to look odd.</p>

<p>Is there anyway to detect that the orientation is changing, instead of changed? Something like <code>willAnimateFirstHalfOfRotationToInterfaceOrientation</code>?</p>
