// Track initialization state
let initialized = false;
let workflowInitialized = false;
function initScrollReveal() {
const sections = document.querySelectorAll('.bp-section:not([data-revealed])');
sections.forEach(s => {
s.setAttribute('data-revealed', 'true');
s.style.opacity = '0';
s.style.transform = 'translateY(40px) scale(0.98)';
s.style.transition = 'opacity 1s cubic-bezier(0.22, 1, 0.36, 1), transform 1s cubic-bezier(0.22, 1, 0.36, 1)';
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0) scale(1)';
}
});
}, { threshold: 0.15 });
observer.observe(s);
});
}
function initWorkflow() {
const aiItems = document.querySelectorAll('.bp-ai-item');
const useCaseTitle = document.getElementById('use-case-title');
const useCaseFlow = document.getElementById('use-case-workflow');
if (aiItems.length > 0 && useCaseTitle && useCaseFlow && !workflowInitialized) {
workflowInitialized = true;
const domainLabels = {
agriculture: 'Agriculture',
healthcare: 'Healthcare',
finance: 'Finance',
ecommerce: 'E-commerce',
manufacturing: 'Manufacturing',
education: 'Education',
transportation: 'Transportation'
};
const workflows = {
agriculture: `
AG.01
๐
GoalCollects herd size, milking routine, tank capacity, target yield, and compliance constraints.
RequirementsConstraints
AG.02
๐
InputsIngests milk yield, SCC, temperature, activity, feed intake, and milking machine telemetry.
IoTQualityTelemetry
AG.03
๐ง
DecisionFlags mastitis risk, heat stress, and milk quality anomalies with explainable contributing factors.
DetectionExplainability
AG.04
๐ฅ
OutputRecommends feeding adjustments, milking schedule tuning, and routing to maximize yield and quality.
OptimizationProduction
AG.05
๐งพ
LoopCreates audit-ready logs, triggers tasks, and notifies staff for interventions and quality holds.
AutomationAuditingCompliance
`,
healthcare: `01
๐
ResponsibilitiesCaptures patient demographics, symptoms, and insurance information.
RegistrationInsurance Check
02
๐
ResponsibilitiesAnalyzes symptoms and determines urgency level.
Symptom AnalysisUrgency Level
03
โก
ResponsibilitiesEvaluates severity and routes to care pathway.
Severity ScoringRouting
04
๐จ
ResponsibilitiesAlerts ER staff for critical cases.
Critical AlertReal-time Notify
05
๐จโโ๏ธ
ResponsibilitiesAI-assisted diagnosis recommendations.
Diagnosis AssistTreatment Plan
06
โ
ResponsibilitiesGenerates treatment plan with prescriptions.
PrescriptionsFollow-up
`,
finance: `01
๐ณ
ResponsibilitiesCaptures and validates transaction data.
Transaction CaptureValidation
02
๐
ResponsibilitiesAnalyzes patterns for fraudulent activity.
Pattern AnalysisAnomaly Detection
03
โก
ResponsibilitiesCalculates risk score and determines approval.
Risk ScoringDecision Routing
04
๐จ
ResponsibilitiesBlocks high-risk transactions.
Transaction BlockSecurity Alert
05
๐
ResponsibilitiesPerforms detailed financial analysis.
Financial AnalysisReporting
06
๐ฐ
ResponsibilitiesValidates compliance with regulations.
Regulatory CheckFinal Approval
`,
ecommerce: `01
๐
ResponsibilitiesTracks browsing behavior and preferences.
User TrackingPreference Capture
02
๐ง
ResponsibilitiesAnalyzes user intent and behavior.
Intent DetectionBehavior Analysis
03
๐ฆ
ResponsibilitiesChecks product availability.
Stock CheckAvailability
04
๐
ResponsibilitiesGenerates personalized recommendations.
RecommendationsPersonalization
05
๐ฌ
ResponsibilitiesManages cart operations and promos.
Cart ManagementPromo Codes
06
โ
ResponsibilitiesProcesses checkout and payment.
Payment ProcessOrder Confirm
`,
manufacturing: `01
๐
ResponsibilitiesCollects real-time sensor data.
Data CollectionIoT Integration
02
๐
ResponsibilitiesMonitors equipment health.
Health MonitoringPerformance
03
โก
ResponsibilitiesDetects anomalies in processes.
Anomaly DetectionAlert Generation
04
๐ง
ResponsibilitiesPredicts failures and schedules maintenance.
Failure PredictionMaintenance Sched
05
๐ญ
ResponsibilitiesOptimizes production schedules.
Production SchedResource Alloc
06
โ
ResponsibilitiesPerforms quality inspection.
Quality InspectValidation
`,
education: `01
๐
ResponsibilitiesAuthenticates and loads profile.
AuthenticationProfile Load
02
๐
ResponsibilitiesEvaluates student knowledge.
AssessmentKnowledge Check
03
๐ง
ResponsibilitiesBuilds personalized profile.
Profile BuildingPersonalization
04
๐ฏ
ResponsibilitiesAdapts content to proficiency level.
Content AdaptDifficulty Adjust
05
๐
ResponsibilitiesProvides personalized tutoring.
TutoringConcept Explain
06
โ
ResponsibilitiesTracks learning progress.
Progress TrackSkill Mastery
`,
transportation: `01
๐บ๏ธ
ResponsibilitiesProcesses route requests.
Route CaptureDestination
02
๐ฆ
ResponsibilitiesAnalyzes traffic conditions.
Traffic DataCongestion Analysis
03
๐
ResponsibilitiesManages fleet assignments.
Fleet MgmtVehicle Assign
04
โก
ResponsibilitiesOptimizes routes for efficiency.
Route OptimEfficiency
05
โฝ
ResponsibilitiesPlans fuel stops and refueling.
Fuel PlanningRefuel Sched
06
๐
ResponsibilitiesManages final delivery execution.
Delivery ExecPOD Collection
`
};
const selected = document.querySelector('.bp-ai-item--selected') || aiItems[0];
const initialDomain = selected && selected.dataset && selected.dataset.domain ? selected.dataset.domain : 'healthcare';
useCaseTitle.textContent = domainLabels[initialDomain] || initialDomain;
useCaseFlow.innerHTML = workflows[initialDomain] || workflows['healthcare'] || '';
aiItems.forEach(item => {
item.addEventListener('click', () => {
aiItems.forEach(i => i.classList.remove('bp-ai-item--selected'));
item.classList.add('bp-ai-item--selected');
const domain = item.dataset.domain;
useCaseTitle.textContent = domainLabels[domain] || domain;
useCaseFlow.innerHTML = workflows[domain] || workflows['healthcare'] || '';
// Re-init drag scroll after workflow change
setTimeout(initWorkflowDragScroll, 0);
});
});
// Initialize drag scroll for workflow
initWorkflowDragScroll();
}
}
// Drag-to-scroll for workflow container
function initWorkflowDragScroll() {
const workflow = document.querySelector('.bp-use-case__workflow');
if (!workflow || workflow.dataset.dragInit) return;
workflow.dataset.dragInit = 'true';
let isDown = false;
let startX;
let scrollLeft;
workflow.addEventListener('mousedown', (e) => {
isDown = true;
workflow.classList.add('bp-dragging');
startX = e.pageX - workflow.offsetLeft;
scrollLeft = workflow.scrollLeft;
}, { passive: true });
workflow.addEventListener('mouseleave', () => {
isDown = false;
workflow.classList.remove('bp-dragging');
}, { passive: true });
workflow.addEventListener('mouseup', () => {
isDown = false;
workflow.classList.remove('bp-dragging');
}, { passive: true });
workflow.addEventListener('mousemove', (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - workflow.offsetLeft;
const walk = (x - startX) * 1.5; // Scroll speed multiplier
workflow.scrollLeft = scrollLeft - walk;
});
// Touch support
let touchStartX;
let touchScrollLeft;
workflow.addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].pageX - workflow.offsetLeft;
touchScrollLeft = workflow.scrollLeft;
}, { passive: true });
workflow.addEventListener('touchmove', (e) => {
const x = e.touches[0].pageX - workflow.offsetLeft;
const walk = (x - touchStartX) * 1.5;
workflow.scrollLeft = touchScrollLeft - walk;
}, { passive: true });
}
function initToTop() {
const toTop = document.getElementById('toTop');
if (toTop && !toTop.hasAttribute('data-listener')) {
toTop.setAttribute('data-listener', 'true');
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
toTop.classList.add('bp-totop--visible');
} else {
toTop.classList.remove('bp-totop--visible');
}
}, { passive: true });
toTop.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
}
function initHeroShuffle() {
const title = document.getElementById('hero-title');
if (!title || title.dataset.shuffled) return;
title.dataset.shuffled = 'true';
title.style.opacity = '1';
const kanaChars = 'ใใใใใใใใใใใใใใใใใกใคใฆใจใชใซใฌใญใฎใฏใฒใตใธใปใพใฟใใใใใใใใใใใ';
const kanjiChars = 'ๆฅฝใใใใใใฏใชใพใใใฌใกใจใใใใใใใใ';
const alphaChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*';
const finalKanji = ['ๆฅฝ', 'ใ', 'ใ'];
const finalText = 'Computing';
function runShuffle() {
const kanaPart = title.querySelector('.bp-kanji');
const textPart = title.querySelector('.bp-title-text');
if (kanaPart) {
const rb = kanaPart.querySelector('rb');
rb.innerHTML = '';
const spans = finalKanji.map(char => {
const span = document.createElement('span');
span.className = 'shuffling';
span.dataset.final = char;
span.textContent = kanaChars[Math.floor(Math.random() * kanaChars.length)];
rb.appendChild(span);
return span;
});
spans.forEach((span, i) => {
setTimeout(() => {
let shuffled = 0;
const interval = setInterval(() => {
span.textContent = kanaChars[Math.floor(Math.random() * kanaChars.length)];
shuffled++;
if (shuffled >= 4) {
clearInterval(interval);
span.textContent = span.dataset.final;
span.classList.remove('shuffling');
span.style.transition = 'transform 0.2s ease, opacity 0.2s ease';
span.style.transform = 'scale(1.1)';
span.style.opacity = '0.7';
setTimeout(() => {
span.style.transform = 'scale(1)';
span.style.opacity = '1';
}, 150);
}
}, 60);
}, i * 120);
});
}
if (textPart) {
textPart.innerHTML = '';
const chars = finalText.split('');
const spans = chars.map(char => {
const span = document.createElement('span');
span.className = 'shuffling';
span.dataset.final = char;
span.textContent = char === ' ' ? ' ' : alphaChars[Math.floor(Math.random() * alphaChars.length)];
textPart.appendChild(span);
return span;
});
spans.forEach((span, i) => {
setTimeout(() => {
let shuffled = 0;
const isSpace = span.dataset.final === ' ';
const interval = setInterval(() => {
span.textContent = isSpace ? ' ' : alphaChars[Math.floor(Math.random() * alphaChars.length)];
shuffled++;
if (shuffled >= 4) {
clearInterval(interval);
span.textContent = span.dataset.final;
span.classList.remove('shuffling');
span.style.transition = 'transform 0.2s ease, opacity 0.2s ease';
span.style.transform = 'scale(1.1)';
span.style.opacity = '0.7';
setTimeout(() => {
span.style.transform = 'scale(1)';
span.style.opacity = '1';
}, 150);
}
}, 50);
}, i * 100);
});
}
setTimeout(runShuffle, 25000);
}
runShuffle();
}
function initAll() {
initScrollReveal();
initWorkflow();
initToTop();
initHeroShuffle();
initHeroSlider();
}
// Handle reduced motion preference
function initReducedMotion() {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReducedMotion) {
document.documentElement.classList.add('reduced-motion');
}
}
// Hero Slider
let heroSliderInterval;
function initHeroSlider() {
const dots = document.querySelectorAll('.bp-hero__dot');
const slides = document.querySelectorAll('.bp-hero__slide');
if (dots.length === 0 || slides.length === 0) return;
let currentSlide = 0;
function showSlide(index) {
slides.forEach((slide, i) => {
slide.classList.toggle('bp-hero__slide--active', i === index);
});
dots.forEach((dot, i) => {
dot.classList.toggle('bp-hero__dot--active', i === index);
});
currentSlide = index;
}
dots.forEach((dot, index) => {
dot.addEventListener('click', () => {
showSlide(index);
resetAutoPlay();
});
});
function nextSlide() {
const next = (currentSlide + 1) % slides.length;
showSlide(next);
}
function resetAutoPlay() {
clearInterval(heroSliderInterval);
heroSliderInterval = setInterval(nextSlide, 5000);
}
// Auto-play every 5 seconds
resetAutoPlay();
}
// Handle htmx loaded content - use event delegation
document.body.addEventListener('htmx:afterSwap', (evt) => {
// Only run if the swapped element is a section
if (evt.target.tagName === 'SECTION') {
initScrollReveal();
initWorkflow();
initHeroShuffle();
initHeroSlider();
}
});
// Expose functions to window so app.js can access them
window.initAll = initAll;
window.initReducedMotion = initReducedMotion;
window.initScrollReveal = initScrollReveal;
window.initWorkflow = initWorkflow;
window.initToTop = initToTop;
window.initHeroShuffle = initHeroShuffle;
window.initHeroSlider = initHeroSlider;
window.initWorkflowDragScroll = initWorkflowDragScroll;
console.log('[PAGE] Page initialization functions exposed to window')