﻿window.onload = function initialLoad() {
    updateOrientation();
}
function updateOrientation() {
    var contentType = "show_";
    switch (window.orientation) {
        case 0:
            contentType += "normal";
            document.getElementById("content_normal").style.display = 'block';
            break;

        case -90:
            contentType += "right";
            document.getElementById("content_normal").style.display = 'none';
            break;

        case 90:
            contentType += "left";
            document.getElementById("content_normal").style.display = 'none';
            break;

        case 180:
            contentType += "flipped";
            break;
        default:
            contentType += "normal";
            break;
    }

    
    document.getElementById("page_wrapper").setAttribute("class", contentType);
}

window.addEventListener("load", function() { setTimeout(loaded, 100) }, false);

//This javascipt waits until the page has loaded and then scrolls to the named element. In this case, page_wrapper. This hides the location bar straight away rather than having to scroll it manually off the screen. Handy if you want to make a page that fits the iPhone exactly. 
function loaded() {
    document.getElementById("page_wrapper").style.visibility = "visible";
    window.scrollTo(0, 1); // pan to the bottom, hides the location bar
}


function createCookie(name, value, days, domain, path) {
    var expires = '';
    if (days) {
        var d = new Date();
        d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = '; expires=' + d.toGMTString();
    }
    domain = domain ? '; domain=' + domain : '';
    path = '; path=' + (path ? path : '/');
    document.cookie = name + '=' + value + expires + path + domain;
}

function readCookie(name) {
    var n = name + '=';
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
        var c = cookies[i].replace(/^\s+/, '');
        if (c.indexOf(n) == 0) {
            return c.substring(n.length);
        }
    }
    return null;
}

function deleteCookie(name, domain, path) {
    setCookie(name, '', -1, domain, path);
}

