File size: 8,889 Bytes
5e92b2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// Interactive elements for TN Medical Connect

document.addEventListener('DOMContentLoaded', function () {
    // Initialize all interactive components
    initAnimations();
    initCounters();
    initCarousels();
    initFlipCards();
    initDarkMode();
    initFilterSystem();
    initScrollReveal();
    initScrollToTop();

    // Add event listeners for interactive features
    document.querySelectorAll('.collapsible-content').forEach(setupCollapsible);
    document.querySelectorAll('.tabs-container').forEach(setupTabs);
});

// === SCROLL-BASED FADE-IN ===
function initScrollReveal() {
    const animatedElements = document.querySelectorAll('.fade-in, .fade-in-up, .fade-in-left, .fade-in-right');

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('visible'); // ✅ USES .visible NOW
                observer.unobserve(entry.target);
            }
        });
    }, { threshold: 0.1 });

    animatedElements.forEach(element => {
        element.style.opacity = 0;
        observer.observe(element);
    });
}

// === COUNTER ANIMATIONS ===
function initCounters() {
    const counterElements = document.querySelectorAll('.counter-animation');

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                const target = parseInt(entry.target.getAttribute('data-target'), 10);
                const duration = parseInt(entry.target.getAttribute('data-duration') || 2000, 10);
                let startTime = null;

                function updateCounter(timestamp) {
                    if (!startTime) startTime = timestamp;
                    const elapsed = timestamp - startTime;
                    const progress = Math.min(elapsed / duration, 1);
                    const currentCount = Math.floor(progress * target);
                    entry.target.textContent = currentCount.toLocaleString();

                    if (progress < 1) {
                        requestAnimationFrame(updateCounter);
                    }
                }

                requestAnimationFrame(updateCounter);
                observer.unobserve(entry.target);
            }
        });
    }, { threshold: 0.5 });

    counterElements.forEach(el => observer.observe(el));
}

// === TESTIMONIAL CAROUSELS ===
function initCarousels() {
    document.querySelectorAll('.testimonial-carousel').forEach(carousel => {
        const track = carousel.querySelector('.testimonial-track');
        const slides = carousel.querySelectorAll('.testimonial-slide');
        const dotsContainer = carousel.querySelector('.testimonial-navigation');
        let currentIndex = 0;

        if (dotsContainer) {
            slides.forEach((_, index) => {
                const dot = document.createElement('div');
                dot.classList.add('testimonial-dot');
                if (index === 0) dot.classList.add('active');
                dot.addEventListener('click', () => goToSlide(index));
                dotsContainer.appendChild(dot);
            });
        }

        const nextBtn = carousel.querySelector('.testimonial-next');
        const prevBtn = carousel.querySelector('.testimonial-prev');

        if (nextBtn) nextBtn.addEventListener('click', nextSlide);
        if (prevBtn) prevBtn.addEventListener('click', prevSlide);

        function nextSlide() {
            goToSlide((currentIndex + 1) % slides.length);
        }

        function prevSlide() {
            goToSlide((currentIndex - 1 + slides.length) % slides.length);
        }

        function goToSlide(index) {
            currentIndex = index;
            track.style.transform = `translateX(-${index * 100}%)`;

            carousel.querySelectorAll('.testimonial-dot').forEach((dot, i) => {
                dot.classList.toggle('active', i === index);
            });
        }

        if (carousel.hasAttribute('data-auto-slide')) {
            const interval = parseInt(carousel.getAttribute('data-auto-slide'), 10) || 5000;
            setInterval(nextSlide, interval);
        }
    });
}

// === FLIP CARDS ===
function initFlipCards() {
    document.querySelectorAll('.flip-card').forEach(card => {
        if (card.classList.contains('click-to-flip')) {
            card.addEventListener('click', function () {
                this.classList.toggle('flipped');
            });
        }
    });
}

// === DARK MODE TOGGLE ===
function initDarkMode() {
    const darkModeToggle = document.getElementById('dark-mode-toggle');
    if (!darkModeToggle) return;

    const prefersDarkMode = localStorage.getItem('darkMode') === 'true';
    const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)').matches;

    if (prefersDarkMode || (prefersDarkScheme && localStorage.getItem('darkMode') === null)) {
        document.body.classList.add('dark-mode');
        darkModeToggle.checked = true;
    }

    darkModeToggle.addEventListener('change', function () {
        if (this.checked) {
            document.body.classList.add('dark-mode');
            localStorage.setItem('darkMode', 'true');
        } else {
            document.body.classList.remove('dark-mode');
            localStorage.setItem('darkMode', 'false');
        }
    });
}

// === FILTERING SYSTEM ===
function initFilterSystem() {
    document.querySelectorAll('.filter-container').forEach(container => {
        const filterControls = container.querySelectorAll('.filter-control');
        const filterItems = container.querySelectorAll('.filter-item');

        filterControls.forEach(control => {
            control.addEventListener('click', function () {
                filterControls.forEach(c => c.classList.remove('active'));
                this.classList.add('active');
                const filterValue = this.getAttribute('data-filter');

                filterItems.forEach(item => {
                    if (filterValue === 'all' || item.classList.contains(filterValue)) {
                        item.style.display = '';
                    } else {
                        item.style.display = 'none';
                    }
                });
            });
        });
    });
}

// === STAGGERED ELEMENTS + PROGRESS BARS ===
function initAnimations() {
    document.querySelectorAll('.stagger-fade-in').forEach(container => {
        const children = container.children;
        Array.from(children).forEach((child, index) => {
            child.style.opacity = 0;
            child.style.animation = `fadeIn 0.5s ease-out ${index * 0.1}s forwards`;
        });
    });

    document.querySelectorAll('.progress-bar').forEach(progressBar => {
        const fill = progressBar.querySelector('.progress-bar-fill');
        const targetWidth = fill.getAttribute('data-width') || '0';

        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    fill.style.width = targetWidth;
                    observer.unobserve(entry.target);
                }
            });
        }, { threshold: 0.5 });

        observer.observe(progressBar);
    });
}

// === COLLAPSIBLE SECTIONS ===
function setupCollapsible(container) {
    const header = container.querySelector('.collapsible-header');
    const content = container.querySelector('.collapsible-body');

    header.addEventListener('click', function () {
        container.classList.toggle('active');
        content.style.maxHeight = container.classList.contains('active')
            ? content.scrollHeight + 'px'
            : 0;
    });

    content.style.maxHeight = 0;
}

// === TABS ===
function setupTabs(container) {
    const tabButtons = container.querySelectorAll('.tab-button');
    const tabContents = container.querySelectorAll('.tab-content');

    tabButtons.forEach((button, index) => {
        button.addEventListener('click', function () {
            tabButtons.forEach(btn => btn.classList.remove('active'));
            tabContents.forEach(content => content.classList.remove('active'));
            button.classList.add('active');
            tabContents[index].classList.add('active');
        });
    });

    if (tabButtons.length > 0) {
        tabButtons[0].click();
    }
}

// === SCROLL TO TOP BUTTON ===
function initScrollToTop() {
    const scrollTopBtn = document.getElementById('scroll-top-btn');
    if (!scrollTopBtn) return;

    window.addEventListener('scroll', function () {
        if (window.pageYOffset > 300) {
            scrollTopBtn.classList.add('show');
        } else {
            scrollTopBtn.classList.remove('show');
        }
    });

    scrollTopBtn.addEventListener('click', function () {
        window.scrollTo({ top: 0, behavior: 'smooth' });
    });
}