<div class="curtain" style="width:100%; height:100%; z-index:9999;">
    <div class="splash">
        <img src="assets/header/logo.png"/>
        <p>Connecting...</p>
    </div>
</div>
<div class="dialog-overlay op70" style="display:none; width:100%; height:100%; z-index:99;"></div>

<%= render "header" %>
<%= render "home" %>
<%= render "footer" %>
<%= render "searchResults" %>
<%= render "faders" %>
<%= render "vu_meters" %>
<%= render "ftue" %>
<%= render "terms" %>
<%= render "sidebar" %>
<%= render "createSession" %>
<%= render "findSession" %>
<%= render "session" %>
<%= render "profile" %>
<%= render "feed" %>
<%= render "bands" %>
<%= render "musicians" %>
<%= render "testBridge" %>
<%= render "account" %>
<%= render "account_identity" %>
<%= render "account_profile" %>
<%= render "account_profile_avatar" %>
<%= render "account_audio_profile" %>
<%= render "invitationDialog" %>
<%= render "notify" %>
<%= render "client_update" %>
<%= render "banner" %>
<%= render "clients/banners/disconnected" %>
<%= render "overlay_small" %>

<script type="text/javascript">
    $(function() {

        JK = JK || {};

        <% if Rails.env == "development" %>
            // if in development mode, we assume you are running websocket-gateway
            // on the same host as you hit your server.  
            JK.websocket_gateway_uri = "ws://" + location.hostname + ":6767/websocket";
        <% else %>
            // but in any other mode, just trust the config coming through gon
            JK.websocket_gateway_uri = gon.websocket_gateway_uri
        <% end %>
        if (console) { console.debug("websocket_gateway_uri:" + JK.websocket_gateway_uri); }

        // If no jamClient (when not running in native client)
        // create a fake one.
        if (!(window.jamClient)) {
            window.jamClient = new JK.FakeJamClient();
        }
        // If no trackVolumeObject (when not running in native client)
        // create a fake one.
        if (!(window.trackVolumeObject)) {
            window.trackVolumeObject = {
                bIsMediaFile: false,
                broadcast: false,
                clientID: "",
                instrumentID: "",
                master: false,
                monitor: false,
                mute: false,
                name: "",
                objectName: "",
                record: false,
                volL: 0,
                volR: 0,
                wigetID: ""
            };
        }

        <% if current_user %>
            JK.currentUserId = '<%= current_user.id %>';
        <% else %>
            JK.currentUserId = null;
        <% end %>


        // Some things can't be initialized until we're connected. Put them here.
        function _initAfterConnect() {

            var header = new JK.Header(JK.app);
            JK.Header = header;
            header.initialize();

            var sidebar = new JK.Sidebar(JK.app);
            sidebar.initialize();

            var homeScreen = new JK.HomeScreen(JK.app);
            homeScreen.initialize();

            var profileScreen = new JK.ProfileScreen(JK.app);
            profileScreen.initialize();

            var accountScreen = new JK.AccountScreen(JK.app);
            accountScreen.initialize();

            var accountIdentityScreen = new JK.AccountIdentityScreen(JK.app);
            accountIdentityScreen.initialize();

            var accountProfileScreen = new JK.AccountProfileScreen(JK.app);
            accountProfileScreen.initialize();

            var accountProfileAvatarScreen = new JK.AccountProfileAvatarScreen(JK.app);
            accountProfileAvatarScreen.initialize();

            var accountAudioProfile = new JK.AccountAudioProfile(JK.app);
            accountAudioProfile.initialize();

            var searchResultScreen = new JK.SearchResultScreen(JK.app);
            searchResultScreen.initialize();

            // This is a helper class with a singleton. No need to instantiate.
            JK.GenreSelectorHelper.initialize();
            JK.Banner.initialize();

            var createSessionScreen = new JK.CreateSessionScreen(JK.app);
            createSessionScreen.initialize();

            var findSessionScreen = new JK.FindSessionScreen(JK.app);
            var sessionLatency = null;
            if ("jamClient" in window) {
                sessionLatency = new JK.SessionLatency(window.jamClient);
            }
            findSessionScreen.initialize(sessionLatency);

            var sessionScreen = new JK.SessionScreen(JK.app);
            sessionScreen.initialize();
            var sessionSettingsDialog = new JK.SessionSettingsDialog(JK.app, sessionScreen);
            sessionSettingsDialog.initialize();

            var ftueWizard = new JK.FtueWizard(JK.app);
            ftueWizard.initialize();

            /*  Commenting Out while reworking
            var ftueAudioTestingScreen = new JK.FtueAudioTestingScreen(JK.app);
            ftueAudioTestingScreen.initialize();
            */

            var testBridgeScreen = new JK.TestBridgeScreen(JK.app);
            testBridgeScreen.initialize();

            JK.app.initialRouting();
            JK.hideCurtain(300);
        }

        // Let's get things rolling...
        if (JK.currentUserId) {

            JK.app = JK.JamKazam();

            // do a client update early check upon initialization
            var clientUpdate = new JK.ClientUpdate(JK.app)
            clientUpdate.initialize().check()

            JK.app.initialize();
            JK.JamServer.connect(); // singleton here defined in JamServer.js
            // this ensures that there is always a CurrentSessionModel, even if it's for a non-active session
            JK.CurrentSessionModel = new JK.SessionModel(JK.app, JK.JamServer, window.jamClient);

            // Run a check to see if we're logged in yet. Only after that should
            // we initialize the other screens.
            // TODO: There should be a timeout, and a "could not connect" message.
            function testConnected() {
                if (JK.clientId) {
                    _initAfterConnect();
                } else {
                    window.setTimeout(testConnected, 100);
                }
            }
            testConnected();

        }

    })
</script>

<!-- version info: <%= version %> -->


