// Home page JavaScript - Use built-in carousel system + AI Features
console.log('Home page JavaScript loaded');
// =============================
// CAROUSEL FUNCTIONALITY
// =============================
let autoPlayInterval;
let carousel;
function initAutoPlay() {
// Find the carousel
carousel = document.querySelector('[data-landingsite-carousel]');
if (!carousel) {
console.log('Carousel not found, retrying...');
setTimeout(initAutoPlay, 1000);
return;
}
console.log('Carousel found - using built-in system');
// Start auto-play using the built-in system
startAutoPlay();
// Add hover pause functionality
carousel.addEventListener('mouseenter', pauseAutoPlay);
carousel.addEventListener('mouseleave', resumeAutoPlay);
}
function startAutoPlay() {
if (!carousel) return;
// Clear any existing interval
if (autoPlayInterval) {
clearInterval(autoPlayInterval);
}
autoPlayInterval = setInterval(() => {
// Find the right arrow button and click it
const nextButton = carousel.querySelector('[data-landingsite-carousel-controls-right]');
if (nextButton) {
nextButton.click();
}
}, 4000); // Change every 4 seconds
console.log('Auto-play started');
}
function pauseAutoPlay() {
if (autoPlayInterval) {
clearInterval(autoPlayInterval);
autoPlayInterval = null;
console.log('Auto-play paused');
}
}
function resumeAutoPlay() {
if (!autoPlayInterval) {
startAutoPlay();
console.log('Auto-play resumed');
}
}
function stopAutoPlay() {
if (autoPlayInterval) {
clearInterval(autoPlayInterval);
autoPlayInterval = null;
console.log('Auto-play stopped');
}
}
// =============================
// AI FEATURES FUNCTIONALITY
// =============================
// Knowledge base for AI-powered search
const knowledgeBase = {
// Grant Application Information
'application': {
keywords: ['apply', 'application', 'grant', 'funding', 'how to apply', 'submit', 'eligibility'],
title: 'Grant Application Process',
content: 'Apply for funding from The Alison Bainbridge Grace Fund. We support 501(c)(3) nonprofits in Greater Houston.',
url: '/funding-application',
icon: 'fas fa-file-alt',
suggestions: [
'Start your grant application →',
'Check eligibility requirements →',
'View application timeline →',
'Read application FAQ →'
]
},
// Recipients Information
'recipients': {
keywords: ['recipients', 'who received', 'grant recipients', 'awarded', 'winners', 'past recipients'],
title: 'Grant Recipients',
content: 'View organizations that have received grants from The Alison Bainbridge Grace Fund and their impact stories.',
url: '/recipients',
icon: 'fas fa-users',
suggestions: [
'See all grant recipients →',
'Read recipient success stories →',
'View recipient testimonials →',
'Learn about funded projects →'
]
},
// Impact Information
'impact': {
keywords: ['impact', 'results', 'outcomes', 'dashboard', 'statistics', 'metrics', 'transparency'],
title: 'Impact Dashboard',
content: 'Explore the comprehensive impact dashboard showing financial transparency and community outcomes.',
url: '/impact-dashboard',
icon: 'fas fa-chart-line',
suggestions: [
'View impact metrics →',
'See financial transparency →',
'Explore community outcomes →',
'Download impact reports →'
]
},
// FAQ Information
'faq': {
keywords: ['faq', 'questions', 'help', 'process', 'frequently asked', 'how', 'when', 'what'],
title: 'Frequently Asked Questions',
content: 'Find answers to common questions about the grant application and review process.',
url: '/process-questions',
icon: 'fas fa-question-circle',
suggestions: [
'View all FAQs →',
'Application process questions →',
'Eligibility questions →',
'Timeline questions →'
]
},
// Mission & Vision
'mission': {
keywords: ['mission', 'vision', 'purpose', 'about', 'goal', 'values'],
title: 'Mission & Vision',
content: 'Learn about our mission to support Houston nonprofits and our vision for community impact.',
url: '/mission-vision',
icon: 'fas fa-bullseye',
suggestions: [
'Read our mission statement →',
'Explore our vision →',
'Learn about our values →',
'See areas of impact →'
]
},
// Contact Information
'contact': {
keywords: ['contact', 'reach out', 'get in touch', 'email', 'phone', 'communication'],
title: 'Contact Information',
content: 'Get in touch with The Alison Bainbridge Grace Fund team for inquiries and support.',
url: '/contact',
icon: 'fas fa-envelope',
suggestions: [
'Send us a message →',
'View contact information →',
'Schedule a consultation →',
'Find our location →'
]
},
// Alison's Story
'alison': {
keywords: ['alison', 'founder', 'story', 'background', 'biography', 'about founder'],
title: 'About the Founder',
content: 'Learn about Alison Bainbridge\'s inspiring journey and why she started this philanthropic initiative.',
url: '/about-us',
icon: 'fas fa-user-circle',
suggestions: [
'Read Alison\'s story →',
'Learn about her background →',
'Understand her motivation →',
'See her community impact →'
]
}
};
// AI Search functionality
let searchDebounceTimer;
function performAISearch(isMobile = false) {
const searchInput = isMobile ?
document.getElementById('ai-search-mobile') :
document.getElementById('ai-search-desktop');
const resultsContainer = isMobile ?
document.getElementById('mobile-search-results') :
document.getElementById('ai-search-results');
const resultsContent = isMobile ?
document.getElementById('mobile-search-results-content') :
document.getElementById('search-results-content');
if (!searchInput || !resultsContainer || !resultsContent) return;
const query = searchInput.value.trim().toLowerCase();
if (query.length < 2) {
resultsContainer.classList.add('hidden');
return;
}
// Simulate AI processing
resultsContent.innerHTML = `
AI is analyzing your query...
`;
resultsContainer.classList.remove('hidden');
setTimeout(() => {
const results = searchKnowledgeBase(query);
displayAISearchResults(resultsContent, results, query);
}, 800);
}
function searchKnowledgeBase(query) {
const results = [];
for (const [key, entry] of Object.entries(knowledgeBase)) {
let score = 0;
for (const keyword of entry.keywords) {
if (query.includes(keyword)) {
score += keyword.length / query.length * 100;
}
}
const titleMatch = entry.title.toLowerCase().includes(query);
const contentMatch = entry.content.toLowerCase().includes(query);
if (titleMatch) score += 50;
if (contentMatch) score += 25;
if (score > 0) {
results.push({ ...entry, score, key });
}
}
return results.sort((a, b) => b.score - a.score).slice(0, 4);
}
function displayAISearchResults(container, results, query) {
if (results.length === 0) {
container.innerHTML = `
No results found for "${query}"
Try searching for:
`;
return;
}
let html = `
AI Analysis:
Found ${results.length} relevant results for "${query}". Click any result to learn more.
`;
results.forEach((result) => {
html += `
${result.title}
${result.content}
${result.suggestions.slice(0, 2).map(suggestion => `
${suggestion}
`).join('')}
`;
});
container.innerHTML = html;
}
function quickSearch(term) {
const desktopInput = document.getElementById('ai-search-desktop');
const mobileInput = document.getElementById('ai-search-mobile');
if (desktopInput && !desktopInput.closest('.hidden')) {
desktopInput.value = term;
performAISearch(false);
} else if (mobileInput && !mobileInput.closest('.hidden')) {
mobileInput.value = term;
performAISearch(true);
}
}
function navigateToResult(url) {
setTimeout(() => {
window.location.href = url;
}, 150);
}
function toggleMobileSearch() {
const searchBar = document.getElementById('mobile-search-bar');
const searchInput = document.getElementById('ai-search-mobile');
if (searchBar) {
searchBar.classList.toggle('hidden');
if (!searchBar.classList.contains('hidden') && searchInput) {
setTimeout(() => searchInput.focus(), 100);
}
}
}
function showSmartSuggestion(type) {
const suggestions = {
'application': {
title: 'Grant Application Process',
content: 'Ready to apply for funding? Our streamlined application process is designed for 501(c)(3) nonprofits in Greater Houston.',
actions: [
{ text: 'Start Application', url: '/funding-application', primary: true },
{ text: 'View Requirements', url: '/process-questions' },
{ text: 'See Timeline', url: '/process-questions' }
]
},
'recipients': {
title: 'Grant Recipients Showcase',
content: 'Discover the amazing nonprofits we\'ve supported and the incredible impact they\'re making in Houston.',
actions: [
{ text: 'View Recipients', url: '/recipients', primary: true },
{ text: 'Read Success Stories', url: '/our-recipients' },
{ text: 'See Impact Data', url: '/impact-dashboard' }
]
},
'impact': {
title: 'Community Impact Dashboard',
content: 'Explore transparent metrics showing exactly how your donations create measurable community impact.',
actions: [
{ text: 'View Dashboard', url: '/impact-dashboard', primary: true },
{ text: 'Financial Transparency', url: '/impact-dashboard' },
{ text: 'Community Outcomes', url: '/impact-dashboard' }
]
},
'faq': {
title: 'Frequently Asked Questions',
content: 'Get quick answers to common questions about eligibility, application process, and grant decisions.',
actions: [
{ text: 'View All FAQs', url: '/process-questions', primary: true },
{ text: 'Application Help', url: '/process-questions' },
{ text: 'Contact Support', url: '/contact' }
]
}
};
const suggestion = suggestions[type];
if (!suggestion) return;
showSmartModal(suggestion);
}
function showSmartModal(suggestion) {
const existingModal = document.getElementById('smart-modal');
if (existingModal) {
existingModal.remove();
}
const modal = document.createElement('div');
modal.id = 'smart-modal';
modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4';
modal.innerHTML = `
`;
document.body.appendChild(modal);
setTimeout(() => {
const content = document.getElementById('smart-modal-content');
if (content) {
content.classList.remove('scale-95', 'opacity-0');
content.classList.add('scale-100', 'opacity-100');
}
}, 10);
modal.addEventListener('click', (e) => {
if (e.target === modal) {
closeSmartModal();
}
});
}
function closeSmartModal() {
const modal = document.getElementById('smart-modal');
const content = document.getElementById('smart-modal-content');
if (content) {
content.classList.add('scale-95', 'opacity-0');
content.classList.remove('scale-100', 'opacity-100');
}
setTimeout(() => {
if (modal) {
modal.remove();
}
}, 300);
}
// Set up AI features
function initAIFeatures() {
console.log('Initializing AI features...');
const desktopSearch = document.getElementById('ai-search-desktop');
const mobileSearch = document.getElementById('ai-search-mobile');
if (desktopSearch) {
desktopSearch.addEventListener('input', () => {
clearTimeout(searchDebounceTimer);
searchDebounceTimer = setTimeout(() => performAISearch(false), 300);
});
desktopSearch.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
performAISearch(false);
}
});
}
if (mobileSearch) {
mobileSearch.addEventListener('input', () => {
clearTimeout(searchDebounceTimer);
searchDebounceTimer = setTimeout(() => performAISearch(true), 300);
});
mobileSearch.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
performAISearch(true);
}
});
}
document.addEventListener('click', (e) => {
const desktopResults = document.getElementById('ai-search-results');
const mobileResults = document.getElementById('mobile-search-results');
const desktopSearch = document.getElementById('ai-search-desktop');
const mobileSearch = document.getElementById('ai-search-mobile');
if (desktopResults && !desktopResults.contains(e.target) && !desktopSearch.contains(e.target)) {
desktopResults.classList.add('hidden');
}
if (mobileResults && !mobileResults.contains(e.target) && !mobileSearch.contains(e.target)) {
mobileResults.classList.add('hidden');
}
});
console.log('AI features initialized successfully');
}
// Global functions
window.performAISearch = performAISearch;
window.toggleMobileSearch = toggleMobileSearch;
window.showSmartSuggestion = showSmartSuggestion;
window.closeSmartModal = closeSmartModal;
window.quickSearch = quickSearch;
window.navigateToResult = navigateToResult;
function init() {
console.log('Home page initialized');
// Initialize carousel
setTimeout(() => {
initAutoPlay();
}, 1000);
// Initialize AI features
setTimeout(() => {
initAIFeatures();
}, 500);
// Fallback for carousel
setTimeout(() => {
if (!carousel) {
initAutoPlay();
}
}, 3000);
}
function teardown() {
console.log('Home page teardown');
// Cleanup carousel
stopAutoPlay();
if (carousel) {
carousel.removeEventListener('mouseenter', pauseAutoPlay);
carousel.removeEventListener('mouseleave', resumeAutoPlay);
}
// Cleanup AI features
clearTimeout(searchDebounceTimer);
const modal = document.getElementById('smart-modal');
if (modal) {
modal.remove();
}
}
// Export functions
module.exports = {
init: init,
teardown: teardown
};