/*
Author       : theme_ocean
Template Name: Bitchain - Cryptocurrency ICO Landing Page HTML Template 
Version      : 1.0
*/
(function($) {
	'use strict';
	
	jQuery(document).on('ready', function(){
	
		/*PRELOADER JS*/
		$(window).on('load', function() { 
			$('.status').fadeOut();
			$('.preloader').delay(350).fadeOut('slow'); 
		}); 
		/*END PRELOADER JS*/		
			
		/*START MENU JS*/		
		function windowScroll() {
			const navbar = document.getElementById("navbar");
			if (
				document.body.scrollTop >= 50 ||
				document.documentElement.scrollTop >= 50
			) {
				navbar.classList.add("nav-sticky");
			} else {
				navbar.classList.remove("nav-sticky");
			}
		}

		window.addEventListener('scroll', (ev) => {
			ev.preventDefault();
			windowScroll();
		})	  	
		/*END MENU JS*/	

		/*START COUNUDOWN JS*/		
		$('[data-countdown]').each(function() {
			var $this = $(this),
				finalDate = $(this).data('countdown');
			$this.countdown(finalDate, function(event) {
				$this.html(event.strftime('<span class="cdown days"><span class="time-count">%-D</span> <p>Days</p></span> <span class="cdown hour"><span class="time-count">%-H</span> <p>Hours</p></span> <span class="cdown minutes"><span class="time-count">%M</span> <p>Minutes</p></span> <span class="cdown second"> <span><span class="time-count">%S</span> <p>Seconds</p></span>'));
			});
		});	
		/*END COUNUDOWN JS*/			
		
		/*START VIDEO JS*/
		$('.video-play').magnificPopup({
            type: 'iframe'
        });
		/*END VIDEO JS*/		
		
		/* START COUNTDOWN JS*/
		$('.counter_feature').on('inview', function(event, visible, visiblePartX, visiblePartY) {
			if (visible) {
				$(this).find('.counter-num').each(function () {
					var $this = $(this);
					$({ Counter: 0 }).animate({ Counter: $this.text() }, {
						duration: 2000,
						easing: 'swing',
						step: function () {
							$this.text(Math.ceil(this.Counter));
						}
					});
				});
				$(this).unbind('inview');
			}
		});
		/* END COUNTDOWN JS */
				
		/*START TESTIMONIAL*/
// 		 $("#testimonial-slider").owlCarousel({
// 			items:1,
// 			itemsDesktop:[1000,1],
// 			itemsDesktopSmall:[979,1],
// 			itemsTablet:[768,1],
// 			itemsMobile:[650,1],
// 			pagination:true,
// 			autoPlay:false
// 		});
		/*END TESTIMONIAL*/	
		
		/*START TESTIMONIAL JS*/	
// 		$("#testimonial-slider-two").owlCarousel({
// 		   items:2,
// 			itemsDesktop:[1000,2],
// 			itemsDesktopSmall:[980,2],
// 			itemsTablet:[768,2],
// 			itemsMobile:[650,1],
// 			pagination:true,
// 			navigation:false,
// 			slideSpeed:1000,
// 			autoPlay:false
// 		});
		/*END TESTIMONIAL JS*/		
		
		/*START ROADMAP*/
// 		 $("#roadmap-slider").owlCarousel({
// 			items:4,
// 			itemsDesktop:[1000,4],
// 			itemsDesktopSmall:[979,2],
// 			itemsTablet:[768,2],
// 			itemsMobile:[650,1],
// 			pagination:true,
// 			autoPlay:false
// 		});
		/*END ROADMAP*/		
		
		/*START PARTNER LOGO*/
// 		$('.partner').owlCarousel({
// 		  autoPlay: 3000, //Set AutoPlay to 3 seconds
// 		  items : 5,
// 		  itemsDesktop : [1199,3],
// 		  itemsDesktopSmall : [979,3]
// 		});
		/*END PARTNER LOGO*/	
		
	}); 	

	/*START WOW ANIMATION JS*/
	  new WOW().init();	
	/*END WOW ANIMATION JS*/	

 document.getElementById('get-a-quote').addEventListener('submit', async function(event) {
		event.preventDefault();
		    document.getElementById('loader-spinner').style.display = 'block';
            document.getElementById('btn_one_submit').style.display  = 'none';
		const formData = new FormData(this);
 try {
        const response = await fetch('contact.php', {
          method: 'POST',
          body: formData,
        });

        const result = await response.json();
        if (result.success) {
                        document.getElementById('response').style.color = 'green';
            document.getElementById('response').innerHTML = "<i class='fa fa-check' style='color: #fff;background: green;font-size: 60px;'></i> We've received your request and will be in touch with you shortly.!";
        } else {
                      document.getElementById('response').style.color = 'red';
            document.getElementById('response').innerHTML = "<i class='fa fa-times' style='color: #fff;background: #e60202;font-size: 30px;'></i> There was an issue processing your request. Please try again later.";
        }
      } catch (error) {
        console.error('Error:', error);
                document.getElementById('response').style.color = 'red';
        document.getElementById('response').innerHTML = "<i class='fa fa-times' style='color: #fff;background: #e60202;font-size: 30px;'></i> Something went wrong. Please try again after a while.";
      }finally {
        // Hide the loader after the process is done (success or error)
        
        document.getElementById('mainform').style.display  = 'none';
                document.getElementById('response').style.display = 'block';
        document.getElementById('loader-spinner').style.display  = 'none';
    }
	  });
	  
	  
	  document.getElementById('contactform').addEventListener('submit', async function(event) {
		event.preventDefault();
		    document.getElementById('loader-spinner2').style.display = 'block';
            document.getElementById('submitButton').style.display  = 'none';
		const formData = new FormData(this);
 try {
        const response = await fetch('contact.php', {
          method: 'POST',
          body: formData,
        });

        const result = await response.json();
        if (result.success) {
                        document.getElementById('response2').style.color = 'green';
            document.getElementById('response2').innerHTML = "<i class='fa fa-check' style='color: #fff;background: green;font-size: 60px;'></i> We've received your request and will be in touch with you shortly.!";
        } else {
                      document.getElementById('response2').style.color = 'red';
            document.getElementById('response2').innerHTML = "<i class='fa fa-times' style='color: #fff;background: #e60202;font-size: 30px;'></i> There was an issue processing your request. Please try again later.";
        }
      } catch (error) {
        console.error('Error:', error);
                document.getElementById('response2').style.color = 'red';
        document.getElementById('response2').innerHTML = "<i class='fa fa-times' style='color: #fff;background: #e60202;font-size: 30px;'></i> Something went wrong. Please try again after a while.";
      }finally {
        // Hide the loader after the process is done (success or error)
        
        document.getElementById('mainform2').style.display  = 'none';
                document.getElementById('response2').style.display = 'block';
        document.getElementById('loader-spinner2').style.display  = 'none';
    }
	  });
        var swiper = new Swiper('.swiper', {
            loop: true,
            autoplay: {
                delay: 2500,disableOnInteraction: true,
            },
            breakpoints: {
                400: {
                    slidesPerView: 2,
                },
                760: {
                    slidesPerView: 3,
                },
                2400: {
                    slidesPerView: 4,
                },
            }
        });
        document.querySelector('.swiper').addEventListener('mouseenter', function () {swiper.autoplay.stop();});
        document.querySelector('.swiper').addEventListener('mouseleave', function () {swiper.autoplay.start();});
        document.addEventListener('DOMContentLoaded', () => {
                document.querySelectorAll('.statistic-counter').forEach(counter => {
                    const target = +counter.getAttribute('data-target');
                    let current = 0;
                    const increment = target / 500; // Adjust 200 for speed

                    const updateCounter = () => {
                        current = Math.min(current + increment, target);
                        counter.textContent = Math.floor(current);
                        if (current < target) requestAnimationFrame(updateCounter);
                    };

                    updateCounter();
                });
            });
            
})(jQuery);


  

