<div class="curtain <%= @minimal_curtain ? 'minimal' : ''%>" 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 "paginator" %>
<%= render "searchResults" %>
<%= render "faders" %>
<%= render "vu_meters" %>
<!--%= render "ftue" % No longer used--> 
<%= render "jamServer" %>
<%= render "iconInstrumentSelect" %>
<%= render "muteSelect" %>
<%= render "manageVsts" %>
<%= render "lessonSessionActions" %>
<%= render "jamblasterOptions" %>
<%= render "vstEffects" %>
<%= render "metronome_playback_mode" %>
<%= render "clients/wizard/buttons" %>
<%= render "clients/wizard/gear/gear_wizard" %>
<%= render "clients/wizard/loopback/loopback_wizard" %>
<%= render "terms" %>
<%= render "rateSession" %>
<%= render "alert" %>
<%= render "confirm" %>
<%= render "sidebar" %>
<%= render "scheduledSession" %>
<%= render "findSession" %>
<%= render "findSession2" %>
<%= render "session2" %>
<%= render "profile" %>
<%= render "bandProfile" %>
<%= render "band_setup" %>
<%= render "band_setup_photo" %>
<%= render "clients/jamclass/jamblaster" %>
<%= render "clients/teachers/setup/introduction" %>
<%= render "clients/teachers/setup/basics" %>
<%= render "clients/teachers/setup/experience" %>
<%= render "clients/teachers/setup/pricing" %>
<%= render "clients/teachers/profile/profile" %>
<%= render "clients/teachers/search/search_options" %>
<%= render "clients/teachers/search/search_results" %>
<%= render "clients/jamclass/book_lesson" %>
<%= render "clients/jamclass/lesson_payment" %>
<%= render "clients/jamclass/lesson_session" %>
<%= render "clients/jamclass/lesson_booking" %>
<%= render "clients/jamclass/test_drive_selection" %>
<%= render "clients/jamclass/jamclass_student" %>
<%= render "users/feed_music_session_ajax" %>
<%= render "users/feed_recording_ajax" %>
<%= render "jamtrack_search" %>
<%= render "jamtrack_filter" %>
<%= render "jamtrack_landing" %>
<%= render "paypal_confirmation" %>
<%= render "shopping_cart" %>
<%= render "checkout_signin" %>
<%= render "checkout_payment" %>
<%= render "checkout_order" %>
<%= render "checkout_complete" %>
<%= render "redeem_signup" %>
<%= render "redeem_complete" %>
<%= render "feed" %>
<%= render "bands" %>
<%= render "musicians" %>
<%= render "testBridge" %>
<%= render "account" %>
<%= render "account_identity" %>
<%= render "affiliate_report" %>
<%= render "account_profile" %>
<%= render "account_profile_experience" %>
<%= render "account_profile_interests" %>
<%= render "account_profile_samples" %>
<%= render "account_profile_avatar" %>
<%= render "account_audio_profile" %>
<%= render "account_video_profile" %>
<%= render "account_sessions" %>
<%= render "account_jamtracks" %>
<%= render "account_affiliate_partner" %>
<%= render "account_session_detail" %>
<%= render "account_session_properties" %>
<%= render "account_payment_history" %>
<%= render "account_school" %>
<%= render "account_retailer" %>
<%= render "account_onboarder" %>
<%= render "account_subscription" %>
<%= render "inviteMusicians" %>
<%= render "hoverBand" %>
<%= render "hoverFan" %>
<%= render "hoverMusician" %>
<%= render "hoverRecording" %>
<%= render "hoverSession" %>
<%= render "notify" %>
<%= render "client_update" %>
<%= render "overlay_small" %>
<%= render "listenBroadcast" %>
<%= render "sync_viewer_templates" %>
<%= render "download_jamtrack_templates" %>
<%= render "jam_track_preview" %>
<%= render "help" %>
<%= render 'dialogs/dialogs' %>
<div id="fb-root"></div>


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

        JK = JK || {};

        JK.root_url = gon.root_url

        // 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: ""
            };
        }

        var api = JK.Rest()

        <% if current_user %>
            JK.currentUserId = '<%= current_user.id %>';
            JK.currentUserAvatarUrl = JK.resolveAvatarUrl('<%= current_user.photo_url %>');
            JK.currentUserName = '<%= current_user.name %>';
            JK.currentUserMusician = '<%= current_user.musician %>';
            JK.currentUserAdmin = <%= current_user.admin %>;
            JK.currentUserFreeJamTrack = <%= current_user.show_free_jamtrack? %>
        <% else %>
            JK.currentUserId = null;
            JK.currentUserAvatarUrl = null;
            JK.currentUserName = null;
            JK.currentUserMusician = null;
            JK.currentUserAdmin = false;
            JK.currentUserFreeJamTrack = <%= anonymous_user.nil? ?  false : anonymous_user.show_free_jamtrack? %>
      <% end %>


        // Some things can't be initialized until we're connected. Put them here.
        function _initAfterConnect(connected) {
            if (this.didInitAfterConnect) return;
            this.didInitAfterConnect = true

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

            JK.getGenreList().done(function(genres) {
              JK.genres = genres;
            });
            var recordingManager = new JK.RecordingManager(JK.app);

            var acceptFriendRequestDialog = new JK.AcceptFriendRequestDialog(JK.app);

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

            var sidebar = new JK.Sidebar(JK.app);
            acceptFriendRequestDialog.initialize(sidebar);
            sidebar.initialize(JK.InvitationDialogInstance, JK.TextMessageDialogInstance);

            var editRecordingDialog = new JK.EditRecordingDialog(JK.app);
            editRecordingDialog.initialize();

            var deleteVideoDialog = new JK.DeleteVideoConfirmDialog(JK.app);
            deleteVideoDialog.initialize();

            var recordingFinishedDialog = new JK.RecordingFinishedDialog(JK.app);
            recordingFinishedDialog.initialize();
            JK.recordingFinishedDialog = recordingFinishedDialog

            var localRecordingsDialog = new JK.LocalRecordingsDialog(JK.app);
            localRecordingsDialog.initialize();

            var openJamTrackDialog = new JK.OpenJamTrackDialog(JK.app);
            JK.OpenJamTrackDialogInstance = openJamTrackDialog;
            openJamTrackDialog.initialize();

            var openBackingTrackDialog = new JK.OpenBackingTrackDialog(JK.app);
            openBackingTrackDialog.initialize();

            var configureTracksDialog = new JK.ConfigureTracksDialog(JK.app)
            configureTracksDialog.initialize();

            var networkTestDialog = new JK.NetworkTestDialog(JK.app);
            networkTestDialog.initialize();

            var jamtrackAvailabilityDialog = new JK.JamtrackAvailabilityDialog(JK.app);
            jamtrackAvailabilityDialog.initialize();

            var jamtrackLicenseDialog = new JK.JamtrackLicenseDialog(JK.app);
            jamtrackLicenseDialog.initialize();
            
            var jamtrackPaymentHistoryDialog = new JK.JamtrackPaymentHistoryDialog(JK.app);
            jamtrackPaymentHistoryDialog.initialize();
            

            var audioProfileInvalidDialog = new JK.AudioProfileInvalidDialog(JK.app);
            audioProfileInvalidDialog.initialize();

            var clientUpdate = new JK.ClientUpdate(JK.app);
            JK.ClientUpdateInstance = clientUpdate;
            clientUpdate.initialize();

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

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

            var bandProfileScreen = new JK.BandProfileScreen(JK.app);
            bandProfileScreen.initialize();

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

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

            var accountSessionsScreen = new JK.AccountSessions(JK.app);
            accountSessionsScreen.initialize();

            var accountJamTracksScreen = new JK.AccountJamTracks(JK.app);
            accountJamTracksScreen.initialize();

            var accountSessionDetailScreen = new JK.AccountSessionDetail(JK.app);
            accountSessionDetailScreen.initialize(JK.InvitationDialogInstance);

            var accountSessionPropertiesScreen = new JK.AccountSessionProperties(JK.app);
            accountSessionPropertiesScreen.initialize();

            var accountAffiliateScreen = new JK.AccountAffiliateScreen(JK.app);
            accountAffiliateScreen.initialize();

            var affiliateReportScreen = new JK.AffiliateReportScreen(JK.app);
            affiliateReportScreen.initialize();

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

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

            var accountProfileExperience = new JK.AccountProfileExperience(JK.app);
            accountProfileExperience.initialize();

            var accountProfileInterests = new JK.AccountProfileInterests(JK.app);
            accountProfileInterests.initialize();

            var accountProfileSamples = new JK.AccountProfileSamples(JK.app, $(".screen.account-profile-samples"), api.getUserProfile, api.updateUser)
            accountProfileSamples.initialize();

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

            var accountVideoProfile = new JK.AccountVideoProfile(JK.app);
            accountVideoProfile.initialize();

            //var accountPaymentHistoryScreen = new JK.AccountPaymentHistoryScreen(JK.app);
            //accountPaymentHistoryScreen.initialize();

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

            var instrumentSelectorInstance = new JK.InstrumentSelector(JK.app);
            instrumentSelectorInstance.initialize(false);
            var instrumentSelectorRSVPInstance = new JK.InstrumentSelector(JK.app);
            instrumentSelectorRSVPInstance.initialize(true);
            var createScheduledSessionScreen = new JK.CreateScheduledSession(JK.app);
                createScheduledSessionScreen.initialize(
                    JK.InvitationDialogInstance,
                    JK.FriendSelectorDialogInstance,
                    instrumentSelectorInstance,
                    instrumentSelectorRSVPInstance
            );

            var bandSetupScreen = new JK.BandSetupScreen(JK.app);
            bandSetupScreen.initialize(JK.InvitationDialogInstance, JK.FriendSelectorDialogInstance);

            var bandSetupPhotoScreen = new JK.BandSetupPhotoScreen(JK.app);
            bandSetupPhotoScreen.initialize();

            var feedScreen = new JK.FeedScreen(JK.app);
            feedScreen.initialize();

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

            //var jamtrackScreen = new JK.JamTrackScreen(JK.app);
            //jamtrackScreen.initialize();

            //var jamtrackLanding = new JK.JamTrackLanding(JK.app);
            //jamtrackLanding.initialize();

            var shoppingCartScreen = new JK.ShoppingCartScreen(JK.app);
            shoppingCartScreen.initialize();

            var checkoutSignInScreen = new JK.CheckoutSignInScreen(JK.app);
            checkoutSignInScreen.initialize();

            var checkoutPaymentScreen = new JK.CheckoutPaymentScreen(JK.app);
            checkoutPaymentScreen.initialize();

            var checkoutOrderScreen = new JK.CheckoutOrderScreen(JK.app);
            checkoutOrderScreen.initialize();

            var checkoutCompleteScreen = new JK.CheckoutCompleteScreen(JK.app);
            checkoutCompleteScreen.initialize();

            var findMusicianScreen = new JK.MusicianSearchFilter();
            findMusicianScreen.init(JK.app);
            // var findMusicianScreen = new JK.FindMusicianScreen(JK.app);
            //findMusicianScreen.initialize(JK.TextMessageDialogInstance);

            var findBandScreen = new JK.BandSearchFilter();
            findBandScreen.init(JK.app);

            var redeemSignUpScreen = new JK.RedeemSignUpScreen(JK.app);
            redeemSignUpScreen.initialize();

            var redeemCompleteScreen = new JK.RedeemCompleteScreen(JK.app);
            redeemCompleteScreen.initialize();

            AppActions.appInit.trigger(JK.app)

            var addNewGearDialog = new JK.AddNewGearDialog(JK.app);
            addNewGearDialog.initialize();

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

            var adjustGearSpeed = new JK.AdjustGearSpeedDialog(JK.app);
            adjustGearSpeed.initialize();

            var loopbackWizard = new JK.LoopbackWizard(JK.app);
            loopbackWizard.initialize();

            var gearWizard = new JK.GearWizard(JK.app);
            gearWizard.initialize(loopbackWizard, adjustGearSpeed);

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

            var changeSearchLocationDialog = new JK.ChangeSearchLocationDialog(JK.app);
            changeSearchLocationDialog.initialize();

            var allSyncsDialog = new JK.AllSyncsDialog(JK.app);
            allSyncsDialog.initialize();

            var singlePlayerProfileGuardDialog = new JK.SinglePlayerProfileGuardDialog(JK.app);
            singlePlayerProfileGuardDialog.initialize();

            //var sessionMasterMixDialog = new JK.SessionMasterMixDialog(JK.app);
            //sessionMasterMixDialog.initialize();

            var signinDialog = new JK.SigninDialog(JK.app);
            signinDialog.initialize();


            JK.SigninPage(); // initialize signin helper

            // do a client update early check upon initialization
            JK.ClientUpdateInstance.check()

            JK.app.initialRouting();


            JK.hideCurtain(300);
        }

        JK.app = JK.JamKazam();
        var jamServer = new JK.JamServer(JK.app, function(event_type) {return JK.app.activeElementEvent(event_type)});
        jamServer.initialize();

        var clientInit = new JK.ClientInit();
        clientInit.init();

        // latency_tester does not want to be here - redirect it
        if(window.jamClient.getOperatingMode && window.jamClient.getOperatingMode() == "server") {
          window.location = "/latency_tester";
          return;
        }

        JK.RecordingUtils.init();

        JK.app.initialize();

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

            JK.JamServer.registerMessageCallback(JK.MessageType.CLIENT_UPDATE, function(header, payload) {
              // do a client update early check upon initialization
              JK.ClientUpdateInstance.runCheck(payload.product, payload.version, payload.uri, payload.size)
            });


            JK.TickDuration('.feed-entry.music-session-history-entry .inprogress .tick-duration');

            JK.JamServer.connect() // singleton here defined in JamServer.js
                .done(function() {
                  _initAfterConnect(true);
                })
                .fail(function() {
                  _initAfterConnect(false);
                });

            // 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, null);
        }
        else {
          _initAfterConnect(false);
        }
        
        JK.bindHoverEvents();
    })
</script>

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


