File size: 6,543 Bytes
ebaa130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a10c94
c260a3c
2a10c94
 
 
 
 
 
c260a3c
 
 
 
 
 
 
 
2a10c94
 
 
 
 
 
c260a3c
2a10c94
 
c260a3c
2a10c94
 
 
 
 
 
 
 
 
c260a3c
 
 
2a10c94
 
 
 
ebaa130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a10c94
ebaa130
 
 
 
 
 
 
 
 
 
 
 
 
 
2a10c94
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Theme toggle functionality
const themeToggle = document.createElement('button');
themeToggle.innerHTML = '<i data-feather="moon" class="w-5 h-5"></i>';
themeToggle.className = 'dark-mode-toggle p-2 rounded-full bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300';
themeToggle.setAttribute('aria-label', 'Toggle theme');

// Check for saved theme preference or default to light mode
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.classList.toggle('dark', savedTheme === 'dark');

// Update icon based on current theme
function updateThemeIcon() {
    const isDark = document.documentElement.classList.contains('dark');
    themeToggle.innerHTML = `<i data-feather="${isDark ? 'sun' : 'moon'}" class="w-5 h-5"></i>`;
    localStorage.setItem('theme', isDark ? 'dark' : 'light');
}

// Toggle theme
themeToggle.addEventListener('click', () => {
    document.documentElement.classList.toggle('dark');
    updateThemeIcon();
    feather.replace();
});

// Initialize theme icon
updateThemeIcon();

// Newsletter form handling
document.querySelector('form').addEventListener('submit', (e) => {
    e.preventDefault();
    const email = e.target.querySelector('input[type="email"]').value;
    if (email) {
        // Simulate form submission
        const button = e.target.querySelector('button');
        const originalText = button.textContent;
        button.textContent = '✓';
        button.classList.add('bg-green-500');
        
        setTimeout(() => {
            button.textContent = originalText;
            button.classList.remove('bg-green-500');
            e.target.reset();
        }, 2000);
    }
});

// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
            target.scrollIntoView({
                behavior: 'smooth',
                block: 'start'
            });
        }
    });
});

// Intersection Observer for fade-in animations
const observerOptions = {
    threshold: 0.1,
    rootMargin: '0px 0px -50px 0px'
};

const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.style.opacity = '1';
            entry.target.style.transform = 'translateY(0)';
        }
    });
}, observerOptions);

// Observe all cards
document.querySelectorAll('article').forEach(card => {
    card.style.opacity = '0';
    card.style.transform = 'translateY(20px)';
    card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
    observer.observe(card);
});

// Add loading states for dynamic content
function showLoading(element) {
    element.innerHTML = `
        <div class="flex justify-center items-center py-12">
            <div class="loading-dots">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </div>
        </div>
    `;
}

// Simulate content loading
window.addEventListener('load', () => {
    // Add a subtle loading animation for stats
    const stats = document.querySelectorAll('.text-4xl');
    stats.forEach((stat, index) => {
        const finalValue = stat.textContent;
        stat.textContent = '0';
        
        setTimeout(() => {
            let counter = 0;
            const increment = finalValue.includes('M') ? 1000000 : 
                             finalValue.includes('k') ? 1000 : 1;
            const max = parseInt(finalValue);
            
            const timer = setInterval(() => {
                counter += increment/10;
                stat.textContent = Math.floor(counter).toLocaleString() + finalValue.replace(/[0-9,]/g, '');
                if (counter >= max) {
                    clearInterval(timer);
                    stat.textContent = finalValue;
                }
            }, 50);
        }, index * 200);
    });
});

// Add keyboard navigation
document.addEventListener('keydown', (e) => {
    if (e.key === 't' && e.ctrlKey) {
        e.preventDefault();
        themeToggle.click();
    }
});
// Background music player
let musicPlaying = true; // Start with music playing
let youtubePlayer = null;

// Initialize background music
function initBackgroundMusic() {
    const musicToggle = document.getElementById('music-toggle');
    const volumeSlider = document.getElementById('volume-slider');
    const backgroundAudio = document.getElementById('background-audio');
    
    // Start audio automatically
    if (backgroundAudio) {
        backgroundAudio.volume = 0.2; // Set initial volume
    backgroundAudio.play().catch(e => {
        console.log('Autoplay prevented:', e);
    });
    
    if (musicToggle) {
        musicToggle.addEventListener('click', () => {
            musicPlaying = !musicPlaying;
            
            if (musicPlaying) {
                backgroundAudio.play();
                musicToggle.innerHTML = '<i data-feather="pause" class="w-5 h-5"></i>';
            } else {
                backgroundAudio.pause();
                musicToggle.innerHTML = '<i data-feather="play" class="w-5 h-5"></i>';
            }
            
            feather.replace();
        });
    }
    
    if (volumeSlider) {
        volumeSlider.addEventListener('input', (e) => {
            const volume = e.target.value / 100;
            if (backgroundAudio) {
                backgroundAudio.volume = volume;
            }
        });
    }
}
// Initialize tooltips
function initTooltips() {
    const tooltips = document.querySelectorAll('[data-tooltip]');
    tooltips.forEach(element => {
        const tooltip = document.createElement('span');
        tooltip.className = 'tooltiptext';
        tooltip.textContent = element.getAttribute('data-tooltip');
        element.classList.add('tooltip');
        element.appendChild(tooltip);
    });
}

// Run after DOM loads
document.addEventListener('DOMContentLoaded', () => {
    initTooltips();
    initBackgroundMusic();
    
    // Add subtle parallax effect to hero
    window.addEventListener('scroll', () => {
        const scrolled = window.pageYOffset;
        const hero = document.querySelector('section');
        if (hero) {
            hero.style.transform = `translateY(${scrolled * 0.5}px)`;
        }
    });
});

// Export for components
window.METAPODCAST = {
    themeToggle,
    updateThemeIcon,
    musicPlaying
};