// ================================
// FAQ Accordion Functionality
// ================================
document.addEventListener('DOMContentLoaded', function() {
const faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(item => {
const question = item.querySelector('.faq-question');
question.addEventListener('click', () => {
// Close all other items
faqItems.forEach(otherItem => {
if (otherItem !== item && otherItem.classList.contains('active')) {
otherItem.classList.remove('active');
}
});
// Toggle current item
item.classList.toggle('active');
});
});
});
// ================================
// Smooth Scroll for Anchor Links
// ================================
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const href = this.getAttribute('href');
// Don't prevent default for empty or just # hrefs
if (href === '#' || href === '') {
e.preventDefault();
return;
}
const target = document.querySelector(href);
if (target) {
e.preventDefault();
const headerOffset = 80;
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
// ================================
// Scroll-triggered 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);
// Apply fade-in animation to elements
document.addEventListener('DOMContentLoaded', function() {
const animatedElements = document.querySelectorAll(
'.course-card, .testimonial-card, .audience-card, .timeline-item'
);
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});
// ================================
// Countdown Timer (Optional Enhancement)
// ================================
function createCountdownTimer(targetDate) {
const countdownElement = document.querySelector('.countdown-timer');
if (!countdownElement) return;
function updateCountdown() {
const now = new Date().getTime();
const distance = targetDate - now;
if (distance < 0) {
countdownElement.innerHTML = 'OFFER EXPIRED';
return;
}
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
countdownElement.innerHTML = `
${days}
Days
:
${hours}
Hours
:
${minutes}
Minutes
:
${seconds}
Seconds
`;
}
updateCountdown();
setInterval(updateCountdown, 1000);
}
// Example: Set countdown for 7 days from now
// Uncomment and adjust the date as needed
// const offerEndDate = new Date();
// offerEndDate.setDate(offerEndDate.getDate() + 7);
// createCountdownTimer(offerEndDate.getTime());
// ================================
// Sticky Header on Scroll
// ================================
let lastScroll = 0;
const header = document.querySelector('.header');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
header.classList.remove('scroll-up');
return;
}
if (currentScroll > lastScroll && !header.classList.contains('scroll-down')) {
// Scrolling down
header.classList.remove('scroll-up');
header.classList.add('scroll-down');
} else if (currentScroll < lastScroll && header.classList.contains('scroll-down')) {
// Scrolling up
header.classList.remove('scroll-down');
header.classList.add('scroll-up');
}
lastScroll = currentScroll;
});
// ================================
// Analytics Event Tracking (Placeholder)
// ================================
function trackEvent(eventName, eventData = {}) {
// Placeholder for analytics tracking
// Replace with actual analytics implementation (Google Analytics, etc.)
console.log('Event tracked:', eventName, eventData);
// Example Google Analytics implementation:
// if (typeof gtag !== 'undefined') {
// gtag('event', eventName, eventData);
// }
}
// Track CTA button clicks
document.querySelectorAll('.btn-primary, .btn-secondary').forEach(button => {
button.addEventListener('click', function(e) {
const buttonText = this.textContent.trim();
const section = this.closest('section')?.className || 'unknown';
trackEvent('cta_click', {
button_text: buttonText,
section: section,
button_location: window.pageYOffset
});
});
});
// Track pricing card interactions
document.querySelectorAll('.pricing-card').forEach(card => {
card.addEventListener('mouseenter', function() {
const planName = this.querySelector('.pricing-plan')?.textContent || 'unknown';
trackEvent('pricing_hover', {
plan: planName
});
});
});
// ================================
// Form Validation (if forms added)
// ================================
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
function validatePhone(phone) {
const re = /^[\d\s\-\(\)\+]+$/;
return re.test(phone) && phone.replace(/\D/g, '').length >= 10;
}
// ================================
// Exit Intent Popup (Optional)
// ================================
let exitIntentShown = false;
document.addEventListener('mouseleave', function(e) {
if (e.clientY <= 0 && !exitIntentShown) {
exitIntentShown = true;
// Trigger exit intent popup
// showExitIntentPopup();
}
});
// ================================
// Price Calculation Display
// ================================
function updatePriceDisplay() {
const priceElements = document.querySelectorAll('[data-original-price]');
priceElements.forEach(element => {
const originalPrice = parseFloat(element.dataset.originalPrice);
const discountPercent = parseFloat(element.dataset.discount) || 0;
const discountedPrice = originalPrice * (1 - discountPercent / 100);
element.textContent = `$${discountedPrice.toFixed(2)}`;
});
}
// ================================
// Lazy Loading for Images (if needed)
// ================================
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
document.querySelectorAll('img.lazy').forEach(img => {
imageObserver.observe(img);
});
}
// ================================
// Add to Cart / Checkout Functionality
// ================================
function initializeCheckout() {
const checkoutButtons = document.querySelectorAll('[data-checkout]');
checkoutButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const plan = this.dataset.plan;
const price = this.dataset.price;
// Track checkout initiation
trackEvent('checkout_initiated', {
plan: plan,
price: price
});
// Redirect to checkout page or open checkout modal
// window.location.href = `/checkout?plan=${plan}&price=${price}`;
console.log('Checkout initiated:', { plan, price });
});
});
}
// Initialize on page load
document.addEventListener('DOMContentLoaded', function() {
initializeCheckout();
});
// ================================
// Testimonial Carousel (Optional Enhancement)
// ================================
function initTestimonialCarousel() {
const carousel = document.querySelector('.testimonials-carousel');
if (!carousel) return;
let currentSlide = 0;
const slides = carousel.querySelectorAll('.testimonial-slide');
const totalSlides = slides.length;
function showSlide(n) {
slides.forEach(slide => slide.style.display = 'none');
currentSlide = (n + totalSlides) % totalSlides;
slides[currentSlide].style.display = 'block';
}
function nextSlide() {
showSlide(currentSlide + 1);
}
function prevSlide() {
showSlide(currentSlide - 1);
}
// Auto-advance every 5 seconds
setInterval(nextSlide, 5000);
// Initialize
showSlide(0);
}
// ================================
// Console Welcome Message
// ================================
console.log('%c👋 Welcome to REM Program!', 'font-size: 20px; font-weight: bold; color: #1a4d2e;');
console.log('%cInterested in real estate investing? Get started at https://remprogram.org', 'font-size: 14px; color: #666;');
// ================================
// Performance Monitoring
// ================================
window.addEventListener('load', function() {
if ('performance' in window) {
const perfData = window.performance.timing;
const pageLoadTime = perfData.loadEventEnd - perfData.navigationStart;
console.log(`Page loaded in ${pageLoadTime}ms`);
// Track page load time
trackEvent('page_performance', {
load_time: pageLoadTime,
page: window.location.pathname
});
}
});