-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
313 lines (270 loc) · 10.5 KB
/
script.js
File metadata and controls
313 lines (270 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
document.addEventListener("DOMContentLoaded", function () {
console.log("Atom Next AI website loaded!");
// Initialize hero section animations
const heroSection = document.querySelector('.hero');
const sphere = document.querySelector('.sphere-3d');
const techCards = document.querySelectorAll('.tech-card');
const heroContent = document.querySelector('.hero-content');
// Animate hero content on load
if (heroContent) {
heroContent.style.opacity = '0';
heroContent.style.transform = 'translateY(20px)';
setTimeout(() => {
heroContent.style.transition = 'opacity 0.8s ease, transform 0.8s ease';
heroContent.style.opacity = '1';
heroContent.style.transform = 'translateY(0)';
}, 300);
}
// Animate tech cards
techCards.forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
setTimeout(() => {
card.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
card.style.opacity = '1';
card.style.transform = 'translateY(0)';
}, 500 + (index * 200));
});
// Sphere rotation animation
if (sphere) {
let rotation = 0;
function animateSphere() {
rotation += 0.5;
sphere.style.transform = `rotateY(${rotation}deg)`;
requestAnimationFrame(animateSphere);
}
animateSphere();
}
// Parallax effect for tech cards
document.addEventListener('mousemove', (e) => {
const mouseX = e.clientX / window.innerWidth;
const mouseY = e.clientY / window.innerHeight;
techCards.forEach((card) => {
const speed = card.getAttribute('data-speed') || 0.1;
const x = (mouseX - 0.5) * speed * 100;
const y = (mouseY - 0.5) * speed * 100;
card.style.transform = `translate(${x}px, ${y}px)`;
});
});
// Scroll animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all sections for scroll animations
document.querySelectorAll('section').forEach(section => {
observer.observe(section);
});
// Particle effect
const particleContainer = document.querySelector('.particle-network');
if (particleContainer) {
for (let i = 0; i < 50; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100}%`;
particle.style.animationDuration = `${Math.random() * 3 + 2}s`;
particle.style.animationDelay = `${Math.random() * 2}s`;
particleContainer.appendChild(particle);
}
}
});
// Navigation scroll effect
window.addEventListener("scroll", function () {
const nav = document.querySelector("nav");
if (nav) {
nav.classList.toggle("scrolled", window.scrollY > 50);
}
});
const text = "We Build AI Automations for Businesses";
let index = 0;
function typeEffect() {
if (index < text.length) {
document.getElementById("hero-title").textContent += text.charAt(index);
index++;
setTimeout(typeEffect, 100);
}
}
document.addEventListener("DOMContentLoaded", typeEffect);
// Mobile menu functionality
document.addEventListener('DOMContentLoaded', function () {
const hamburger = document.querySelector('.hamburger');
const navItems = document.querySelector('.nav-items');
const navLinks = document.querySelectorAll('.nav-items a');
const body = document.body;
// Toggle menu
if (hamburger && navItems) {
hamburger.addEventListener('click', function (e) {
e.stopPropagation();
this.classList.toggle('active');
navItems.classList.toggle('active');
body.classList.toggle('no-scroll');
});
}
// Close menu when clicking a link
navLinks.forEach(link => {
link.addEventListener('click', function (e) {
if (navItems.classList.contains('active')) {
navItems.classList.remove('active');
hamburger.classList.remove('active');
body.classList.remove('no-scroll');
}
});
});
// Close menu when clicking outside
document.addEventListener('click', function (e) {
if (navItems.classList.contains('active') &&
!e.target.closest('.nav-items') &&
!e.target.closest('.hamburger')) {
navItems.classList.remove('active');
hamburger.classList.remove('active');
body.classList.remove('no-scroll');
}
});
// Prevent clicks inside nav from closing it
navItems.addEventListener('click', function (e) {
e.stopPropagation();
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
// Skip if it's just "#" or if target doesn't exist
if (href === '#' || href.length === 1) {
e.preventDefault();
return;
}
const targetElement = document.querySelector(href);
if (targetElement) {
e.preventDefault();
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// Close mobile menu if open
if (navItems.classList.contains('active')) {
navItems.classList.remove('active');
hamburger.classList.remove('active');
body.classList.remove('no-scroll');
}
}
});
});
});
// Chatbot functionality
document.addEventListener('DOMContentLoaded', function () {
const chatbotContainer = document.querySelector('.chatbot-container');
const chatbotToggle = document.querySelector('.chatbot-toggle');
const chatbotClose = document.querySelector('.chatbot-close');
const chatbotInput = document.querySelector('.chatbot-text-input');
const chatbotSend = document.querySelector('.chatbot-send');
const chatbotMessages = document.querySelector('.chatbot-messages');
const chatbotWelcome = document.querySelector('.chatbot-welcome');
const chatbotWelcomeClose = document.querySelector('.chatbot-welcome-close');
// Generate a unique session ID
const sessionId = 'session_' + Math.random().toString(36).substr(2, 9);
// Show welcome popup after a short delay
setTimeout(() => {
chatbotWelcome.classList.add('active');
}, 2000);
// Close welcome popup
chatbotWelcomeClose.addEventListener('click', () => {
chatbotWelcome.classList.remove('active');
});
// Toggle chatbot
chatbotToggle.addEventListener('click', () => {
chatbotContainer.classList.add('active');
chatbotWelcome.classList.remove('active');
});
// Close chatbot
chatbotClose.addEventListener('click', () => {
chatbotContainer.classList.remove('active');
});
// Add typing indicator
function addTypingIndicator() {
const typingDiv = document.createElement('div');
typingDiv.className = 'message bot typing';
typingDiv.innerHTML = `
<div class="message-content">
<div class="typing-indicator">
<span></span>
<span></span>
<span></span>
</div>
</div>
`;
chatbotMessages.appendChild(typingDiv);
chatbotMessages.scrollTop = chatbotMessages.scrollHeight;
return typingDiv;
}
// Remove typing indicator
function removeTypingIndicator(typingDiv) {
if (typingDiv && typingDiv.parentNode) {
typingDiv.parentNode.removeChild(typingDiv);
}
}
// Send message function
async function sendMessage() {
const message = chatbotInput.value.trim();
if (message) {
// Add user message
addMessage(message, 'user');
chatbotInput.value = '';
// Show typing indicator
const typingIndicator = addTypingIndicator();
try {
// Send message to backend
const response = await fetch('/.netlify/functions/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: message,
session_id: sessionId
})
});
const data = await response.json();
// Remove typing indicator
removeTypingIndicator(typingIndicator);
if (data.status === 'success') {
// Add bot response
addMessage(data.response, 'bot');
} else {
// Handle error
addMessage('I apologize, but I encountered an error. Please try again later.', 'bot');
}
} catch (error) {
// Remove typing indicator
removeTypingIndicator(typingIndicator);
// Handle network error
addMessage('I apologize, but I\'m having trouble connecting to the server. Please try again later.', 'bot');
console.error('Error:', error);
}
}
}
// Add message to chat
function addMessage(text, sender) {
const messageDiv = document.createElement('div');
messageDiv.className = `message ${sender}`;
messageDiv.innerHTML = `<div class="message-content">${text}</div>`;
chatbotMessages.appendChild(messageDiv);
chatbotMessages.scrollTop = chatbotMessages.scrollHeight;
}
// Send message on button click
chatbotSend.addEventListener('click', sendMessage);
// Send message on Enter key
chatbotInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendMessage();
}
});
});