/**
 * Script that gets run or included only for mobile devices
 */
if (/mobile/i.test(navigator.userAgent)) {

    var hideToolbarIfNeeded = function() {
        // Only scroll if the user hasn't already scrolled by now
        if(!pageYOffset) {
            window.scrollTo(0, 1);
        }
    }

    // Detect and handle screen orientation changes
    var updateOrientation = function() {
        hideToolbarIfNeeded();
    }
    window.onorientationchange = updateOrientation;

    jQuery(document).ready(function(){
        // If this isn't an internal page link with a #, try scrolling the
        // toolbar out of view so the webpage takes up all the screen space
        if(!location.hash) {
            // Give the browser time to figure out the full height of the page,
            // or else it will undo our scrolling
            setTimeout(function () {
                hideToolbarIfNeeded();
            }, 1000);
            setTimeout(function () {
                hideToolbarIfNeeded();
            }, 3000);
        }
    });
}
