// Enhanced Typewriter Effect with multiple phrases const typewriterPhrases = [ "12 Years of Technical Excellence", "Enterprise-Grade Solutions", "Cutting-Edge Digital Architectures" ]; const typewriterElement = document.getElementById('typewriter'); let phraseIndex = 0; let charIndex = 0; let isDeleting = false; let typingSpeed = 100; function typeWriter() { const currentPhrase = typewriterPhrases[phraseIndex]; if (isDeleting) { typewriterElement.innerHTML = currentPhrase.substring(0, charIndex - 1); charIndex--; typingSpeed = 50; } else { typewriterElement.innerHTML = currentPhrase.substring(0, charIndex + 1); charIndex++; typingSpeed = 100; } if (!isDeleting && charIndex === currentPhrase.length) { typingSpeed = 1500; isDeleting = true; } else if (isDeleting && charIndex === 0) { isDeleting = false; phraseIndex = (phraseIndex + 1) % typewriterPhrases.length; typingSpeed = 500; } setTimeout(typeWriter, typingSpeed); } // Initialize with error handling document.addEventListener('DOMContentLoaded', async () => { try { typeWriter(); await Promise.all([ loadProjects(), loadOrders(), loadBlogPosts() ]); setupIntersectionObservers(); setupAdminAccess(); } catch (error) { console.error('Initialization error:', error); showErrorToast('Failed to load page content'); } }); // Fetch projects from API with caching async function fetchProjects() { const cacheKey = 'projectsCache'; const cacheTime = 3600000; // 1 hour try { // Check cache first const cached = localStorage.getItem(cacheKey); if (cached) { const { data, timestamp } = JSON.parse(cached); if (Date.now() - timestamp < cacheTime) { return data; } } // Fetch from API (mock API for demonstration) const response = await fetch('https://api.mocki.io/v2/1a1f1d1a/projects'); if (!response.ok) throw new Error('Failed to fetch projects'); const data = await response.json(); // Cache the response localStorage.setItem(cacheKey, JSON.stringify({ data, timestamp: Date.now() })); return data; } catch (error) { console.error('Project fetch error:', error); // Fallback to local data return [ { title: "Enterprise Cloud Migration", description: "Seamless transition to AWS for Fortune 500 company", image: "http://static.photos/technology/640x360/1", tags: ["AWS", "Migration", "DevOps"] }, { title: "AI-Powered Analytics", description: "Machine learning platform for real-time business insights", image: "http://static.photos/abstract/640x360/2", tags: ["AI", "Machine Learning", "Data"] }, { title: "Blockchain Security", description: "Decentralized identity verification system", image: "http://static.photos/minimal/640x360/3", tags: ["Blockchain", "Security", "Web3"] }, { title: "IoT Fleet Management", description: "Connected vehicle platform with predictive maintenance", image: "http://static.photos/technology/640x360/4", tags: ["IoT", "Automotive", "Predictive"] }, { title: "Digital Banking Platform", description: "Next-gen mobile banking with biometric auth", image: "http://static.photos/finance/640x360/5", tags: ["Fintech", "Banking", "Mobile"] }, { title: "Healthcare Data Hub", description: "HIPAA-compliant patient data management system", image: "http://static.photos/medical/640x360/6", tags: ["Healthcare", "HIPAA", "Data"] } ]; } } // Load Projects with Intersection Observer async function loadProjects() { try { const container = document.getElementById('projects-container'); container.innerHTML = '
'; const projects = await fetchProjects(); container.innerHTML = ''; projects.forEach((project, index) => { const projectElement = document.createElement('div'); projectElement.className = 'project-card opacity-0 transform translate-y-10 transition-all duration-500 ease-out bg-secondary/50 rounded-xl overflow-hidden border border-gray-700/50 hover:border-accent/50 hover:shadow-lg hover:shadow-accent/10'; projectElement.dataset.index = index; projectElement.innerHTML = `
${project.title}

${project.title}

${project.description}

${project.tags.map(tag => `${tag}`).join('')}
`; container.appendChild(projectElement); }); } catch (error) { console.error('Error loading projects:', error); showErrorToast('Failed to load projects'); } } // Intersection Observers for animations function setupIntersectionObservers() { const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -100px 0px' }; // Project cards observer const projectObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const delay = parseInt(entry.target.dataset.index) * 100; setTimeout(() => { entry.target.classList.remove('opacity-0', 'translate-y-10'); }, delay); projectObserver.unobserve(entry.target); } }); }, observerOptions); document.querySelectorAll('.project-card').forEach(card => { projectObserver.observe(card); }); // Other section observers const sectionObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-fadeInUp'); sectionObserver.unobserve(entry.target); } }); }, { threshold: 0.1 }); document.querySelectorAll('section').forEach(section => { sectionObserver.observe(section); }); } // Toast notifications function showToast(message, type = 'success') { const toast = document.createElement('div'); toast.className = `fixed bottom-6 left-1/2 transform -translate-x-1/2 px-6 py-3 rounded-lg shadow-lg ${ type === 'success' ? 'bg-green-600' : 'bg-red-600' } text-white font-medium z-50 animate-fadeInUp`; toast.textContent = message; document.body.appendChild(toast); setTimeout(() => { toast.classList.replace('animate-fadeInUp', 'animate-fadeOutDown'); setTimeout(() => toast.remove(), 500); }, 3000); } function showErrorToast(message) { showToast(message, 'error'); } // Orders Data (Initial) let orders = JSON.parse(localStorage.getItem('orders')) || [ { id: 1, service: "Enterprise Web Development", description: "Custom web applications with React/Node.js stack", price: "$25,000+" }, { id: 2, service: "Cloud Architecture", description: "AWS/GCP/Azure infrastructure design & implementation", price: "$15,000+" }, { id: 3, service: "Cybersecurity Audit", description: "Comprehensive security assessment & hardening", price: "$8,000+" }, { id: 4, service: "AI Integration", description: "Machine learning model development & deployment", price: "$30,000+" } ]; // Load Orders Table function loadOrders() { const tableBody = document.getElementById('orders-table'); tableBody.innerHTML = ''; orders.forEach(order => { const row = document.createElement('tr'); row.className = 'border-b border-gray-700 hover:bg-secondary/30 transition-colors'; row.innerHTML = ` ${order.service} ${order.description} ${order.price} `; tableBody.appendChild(row); }); feather.replace(); } // Add New Order function addOrder(service, description, price) { const newId = orders.length > 0 ? Math.max(...orders.map(o => o.id)) + 1 : 1; const newOrder = { id: newId, service, description, price }; orders.push(newOrder); localStorage.setItem('orders', JSON.stringify(orders)); loadOrders(); } // Delete Order function deleteOrder(id) { orders = orders.filter(order => order.id !== id); localStorage.setItem('orders', JSON.stringify(orders)); loadOrders(); } // Blog Posts Data let blogPosts = JSON.parse(localStorage.getItem('blogPosts')) || [ { id: 1, title: "The Future of Cloud Computing in 2023", content: "Exploring the latest trends in cloud architecture and how businesses can leverage them for competitive advantage.", date: "May 15, 2023" }, { id: 2, title: "Securing Your Digital Assets", content: "Best practices for enterprise cybersecurity in an increasingly complex threat landscape.", date: "April 28, 2023" }, { id: 3, title: "AI Integration Strategies", content: "How to successfully implement AI solutions without disrupting existing workflows.", date: "March 10, 2023" } ]; // Load Blog Posts function loadBlogPosts() { const container = document.getElementById('blog-container'); container.innerHTML = ''; blogPosts.forEach(post => { const postElement = document.createElement('div'); postElement.className = 'bg-secondary/50 backdrop-blur-lg rounded-xl p-6 border border-gray-700/50 hover:border-accent/50 transition-all duration-300'; postElement.innerHTML = `

${post.title}

${post.content.substring(0, 150)}...

${post.date}
`; container.appendChild(postElement); }); feather.replace(); } // Add New Blog Post function addBlogPost(title, content) { const newId = blogPosts.length > 0 ? Math.max(...blogPosts.map(p => p.id)) + 1 : 1; const newPost = { id: newId, title, content, date: new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) }; blogPosts.push(newPost); localStorage.setItem('blogPosts', JSON.stringify(blogPosts)); loadBlogPosts(); } // Delete Blog Post function deleteBlogPost(id) { blogPosts = blogPosts.filter(post => post.id !== id); localStorage.setItem('blogPosts', JSON.stringify(blogPosts)); loadBlogPosts(); } // Admin Controls (Now moved to admin.html) function setupAdminAccess() { // This function is now handled by the admin login modal // All admin functionality moved to admin.html } // Make functions available globally window.deleteOrder = deleteOrder; window.deleteBlogPost = deleteBlogPost;