﻿// get the user agent so we can determine the phone type.  We'll do special treatment for blackberries and iPhones.
var agent=navigator.userAgent.toLowerCase();
var bIsiPhone = (agent.indexOf('iphone')!=-1);

if (bIsiPhone) {
    // create this function which will see if the iPhone is in landscape or portrait mode and set the body tag accordingly
    var currentWidth = 320;
    
    var updateLayout = function() {
      if (window.innerWidth != currentWidth) {
        currentWidth = window.innerWidth;
        var orient = (currentWidth == 320) ? "profile" : "landscape";
        document.body.setAttribute("orient", orient);
        window.scrollTo(0, 1);
      }
      iPhoneOrientChange();
    };

    iPhone.DomLoad(updateLayout);
    setInterval(updateLayout, 500);
}

function iPhoneOrientChange() {
    var vp = document.getElementById("viewport")

    if (vp) {
        switch (window.orientation) {
            case 0:
                //document.getElementById("page_wrapper").setAttribute("class", "iPhonePortrait");
                break;
            case 90:
            case -90:
                //document.getElementById("page_wrapper").setAttribute("class", "iPhoneLandscape");
                break;
        }
    }
}

