
let currentLanguage = 'en';

function toggleLanguage() {
    const langButton = document.getElementById('lang-text');
    const elementsWithTranslation = document.querySelectorAll('[data-en]');
    
    if (currentLanguage === 'en') {
        // Switch to Tamil
        currentLanguage = 'ta';
        langButton.textContent = 'English';
        
        elementsWithTranslation.forEach(element => {
            const tamilText = element.getAttribute('data-ta');
            if (tamilText) {
                element.textContent = tamilText;
            }
        });
    } else {
        // Switch to English
        currentLanguage = 'en';
        langButton.textContent = 'தமிழ்';
        
        elementsWithTranslation.forEach(element => {
            const englishText = element.getAttribute('data-en');
            if (englishText) {
                element.textContent = englishText;
            }
        });
    }
}

function toggleMobileMenu() {
    const navMenu = document.querySelector('.nav-menu');
    const mobileToggle = document.querySelector('.mobile-menu-toggle');
    navMenu.classList.toggle('active');
    mobileToggle.classList.toggle('open');
}

// Form submission handler
document.addEventListener('DOMContentLoaded', function() {
    const enquiryForm = document.getElementById('contactForm');
    if (enquiryForm) {
        enquiryForm.addEventListener('submit', function(e) {
            e.preventDefault();
            alert(currentLanguage === 'en' ? 
                'Thank you for your enquiry! We will contact you soon.' : 
                'உங்கள் விசாரணைக்கு நன்றி! நாங்கள் விரைவில் உங்களைத் தொடர்பு கொள்வோம்.');
            this.reset();
        });
    }

    // Set active navigation item based on current page
    const currentPage = window.location.pathname.split('/').pop() || 'index.html';
    const navLinks = document.querySelectorAll('.nav-menu a');
    
    navLinks.forEach(link => {
        const href = link.getAttribute('href');
        if (href === currentPage) {
            link.classList.add('active');
        } else {
            link.classList.remove('active');
        }
    });

    // Close mobile menu when clicking on a link
    const mobileNavLinks = document.querySelectorAll('.nav-menu a');
    mobileNavLinks.forEach(link => {
        link.addEventListener('click', () => {
            document.querySelector('.nav-menu').classList.remove('active');
        });
    });

    // Close mobile menu when clicking outside
    document.addEventListener('click', function(e) {
        const nav = document.querySelector('.nav');
        const mobileToggle = document.querySelector('.mobile-menu-toggle');
        const navMenu = document.querySelector('.nav-menu');

        if (!nav.contains(e.target) && navMenu.classList.contains('active')) {
            navMenu.classList.remove('active');
        }
    });
});
