﻿function populate()
{
    var w = "310px";
    var h = "470px";
    var contentType = "";
    switch (window.orientation)
    {
        case 0:
            w = "320px";
            h = "356px";
            contentType = 'portrait';
            getLanding(false, 'divPortrait');
            break;

        case -90:
            w = "480px";
            h = "208px";
            contentType = 'landscape_right';
            getClients(false, 'divLandscapeRight');
            break;

        case 90:
            w = "480px";
            h = "208px";
            contentType = 'landscape_left';
            //getTeam(false, 'divLandscapeLeft');
            getFeed(false, 'divLandscapeLeft');
            break;

        case 180:
            w = "320px";
            h = "356px";
            contentType = 'flipped';
            alert('This view is not enabled by iPhone.');
            break;
    }
    var pg = document.getElementById('page_wrapper');
    pg.setAttribute('class', contentType);
    pg.setAttribute('style', 'width:' + w + '; height:' + h + ';');
    
    switch (pg.getAttribute('class'))
    {
        case 'portrait':
            getElem(false, 'divPortrait').setAttribute('style', 'background: url("http://14four.com/img/iPhoneWeb/main.png") top center no-repeat; width:' + w + '; height:' + h + ';');            
            break;
    }   
}

$(document).ready(function()
{
    window.addEventListener('orientationchange', populate, true);
    populate(); //initial call
});

//landing PORTRAIT
function getLanding(ss, id)
{
    var landing = getElem(false, 'divPortrait');

    landing.innerHTML = '<a href="tel:1-509-448-4070"><div id="call"><div id="call_txt">CALL</div></div></a>'
        + '<a href="mailto:jeff@14four.com"><div id="email"><div id="email_txt">EMAIL</div></div></a>'
        + '<a href="http://maps.google.com/maps?q=157 S. Howard St. Spokane, WA 99201" target="_blank"><div id="map"><div id="map_txt">MAP</div></div></a>';
    
}
//work RIGHT LANDSCAPE
function getClients(ss, id)
{
    Work.GetClients
    (
        function(r)
        {
            onGetClientsCompleted(r, id, ss);
        }
    );
}
function onGetClientsCompleted(r, id, ss)
{
    if (typeof r == 'object')
    {
        getElem(false, 'page_wrapper').style.width = r.width + 'px';
        getElem(ss, id).innerHTML = r.data;
    }
}


//team LEFT LANDSCAPE
function getFeed(ss, id)
{
    SocialNetwork.GetFeed
    (
        function(r)
        {
            onGetFeedCompleted(r, id, ss);
        }
    );
}
function onGetFeedCompleted(r, id, ss)
{
    if(typeof r == 'object')
    {
        getElem(false, 'page_wrapper').style.width = r.width + 'px';
        getElem(ss, id).innerHTML = r.data;
    }
}
/*function getTeam(ss, id)
{
    Team.GetTeam
    (
        function(r)
        {
            onGetTeamCompleted(r, id, ss);
        }
    );
}
function onGetTeamCompleted(r, id, ss)
{
    if (typeof r == 'object')
    {
        getElem(false, 'page_wrapper').style.width = r.width + 'px';
        getElem(ss, id).innerHTML = r.data;
    }
}*/