/**
 * Player insertion script with jQuery availability check
 * Handles cases where optimization plugins defer/async jQuery loading
 */
(function() {
    'use strict';

    var attempts = 0;
    var maxAttempts = 50; // 5 seconds max wait (50 * 100ms)

    function waitForjQuery() {
        if (typeof jQuery !== 'undefined') {
            initializePlayerInsert();
        } else if (attempts < maxAttempts) {
            attempts++;
            setTimeout(waitForjQuery, 100);
        } else {
            // jQuery not available after waiting - log error only if console exists
            if (window.mementorTTSDebugSettings && window.mementorTTSDebugSettings.isDebug) {
                console.error('[TTS Player Insert] jQuery not available after ' + maxAttempts + ' attempts');
            }
        }
    }

    function initializePlayerInsert() {
        jQuery(document).ready(function($) {
    // We now rely on the centralized debug logic in mementor-tts-debug-settings.js
    // The global mementorTTSDebugEnabled variable should already be set
    // The global mementorTTSDebug function should already be defined

    // Create a safe wrapper for debug logging
    var safeDebug = function() {
        if (typeof window.mementorTTSDebug === 'function') {
            window.mementorTTSDebug.apply(window, arguments);
        }
    };

    // Player insertion is handled by PHP hooks for better compatibility
    // This script is kept for backward compatibility but does not insert players
        }); // End jQuery(document).ready
    } // End initializePlayerInsert

    // Start waiting for jQuery
    waitForjQuery();
})(); // End IIFE