(function($){
	"use strict";
	jQuery(document).on('ready', function () {

		var wind = $(window);
		var parallaxSlider;
		var parallaxSliderOptions = {
			speed: 1000,
			autoplay: true,
			parallax: true,
			loop: true,

			on: {
				init: function () {
					var swiper = this;
					for (var i = 0; i < swiper.slides.length; i++) {
						$(swiper.slides[i])
							.find('.bg-img')
							.attr({
								'data-swiper-parallax': 0.75 * swiper.width
							});
					}
				},
				resize: function () {
					this.update();
				}
			},

			pagination: {
				el: '.slider-prlx .parallax-slider .swiper-pagination',
				dynamicBullets: true,
				clickable: true
			},

			navigation: {
				nextEl: '.slider-prlx .parallax-slider .next-ctrl',
				prevEl: '.slider-prlx .parallax-slider .prev-ctrl'
			}
		};
		parallaxSlider = new Swiper('.slider-prlx .parallax-slider', parallaxSliderOptions);
	
		// Var Background image
		var pageSection = $(".bg-img, section");
		pageSection.each(function (indx) {
			if ($(this).attr("data-background")) {
				$(this).css("background-image", "url(" + $(this).data("background") + ")");
			}
		});
	
        // Header Sticky
		$(window).on('scroll',function() {
            if ($(this).scrollTop() > 120){  
                $('.navbar-area').addClass("is-sticky");
            }
            else{
                $('.navbar-area').removeClass("is-sticky");
            }
        });
        
        // Mean Menu
		jQuery('.mean-menu').meanmenu({
			meanScreenWidth: "991"
        });

        // Button Hover JS
        $(function() {
            $('.default-btn')
            .on('mouseenter', function(e) {
                var parentOffset = $(this).offset(),
                relX = e.pageX - parentOffset.left,
                relY = e.pageY - parentOffset.top;
                $(this).find('span').css({top:relY, left:relX})
            })
            .on('mouseout', function(e) {
                var parentOffset = $(this).offset(),
                relX = e.pageX - parentOffset.left,
                relY = e.pageY - parentOffset.top;
                $(this).find('span').css({top:relY, left:relX})
            });
        });

		// Progress bar
		wind.on('scroll', function () {
			$(".skill-progress .progres").each(function () {
				var bottom_of_object = $(this).offset().top + $(this).outerHeight();
				var bottom_of_window = $(window).scrollTop() + $(window).height();
				var myVal = $(this).attr('data-value');
				if (bottom_of_window > bottom_of_object) {
					$(this).css({
						width: myVal
					});
				}
			});
		});
        
        // Testimonial Slider
		$('.testimonial-slider').owlCarousel({
			loop: true,
			nav: true,
			dots: true,
			autoplayHoverPause: true,
            autoplay: true,
            smartSpeed: 1000,
            margin: 20,
            navText: [
                "<i class='fa fa-chevron-left'></i>",
                "<i class='fa fa-chevron-right'></i>"
            ],
			responsive: {
                0: {
                    items: 1,
                },
                768: {
                    items: 2,
                },
                1200: {
                    items: 3,
                }
            }
        });


        // Nice Select JS
        $('select').niceSelect();
		
		//  Star Counter
		$('.counter-number').counterUp({
			delay: 15,
			time: 2000
		});
		
        // Input Plus & Minus Number JS
        $('.input-counter').each(function() {
            var spinner = jQuery(this),
            input = spinner.find('input[type="text"]'),
            btnUp = spinner.find('.plus-btn'),
            btnDown = spinner.find('.minus-btn'),
            min = input.attr('min'),
            max = input.attr('max');
            
            btnUp.on('click', function() {
                var oldValue = parseFloat(input.val());
                if (oldValue >= max) {
                    var newVal = oldValue;
                } else {
                    var newVal = oldValue + 1;
                }
                spinner.find("input").val(newVal);
                spinner.find("input").trigger("change");
            });
            btnDown.on('click', function() {
                var oldValue = parseFloat(input.val());
                if (oldValue <= min) {
                    var newVal = oldValue;
                } else {
                    var newVal = oldValue - 1;
                }
                spinner.find("input").val(newVal);
                spinner.find("input").trigger("change");
            });
        });

        // FAQ Accordion
        $(function() {
            $('.accordion').find('.accordion-title').on('click', function(){
                // Adds Active Class
                $(this).toggleClass('active');
                // Expand or Collapse This Panel
                $(this).next().slideToggle('slow');
                // Hide The Other Panels
                $('.accordion-content').not($(this).next()).slideUp('slow');
                // Removes Active Class From Other Titles
                $('.accordion-title').not($(this)).removeClass('active');	
            });
        });

        // Image Sliders
		$('.image-sliders').owlCarousel({
			loop: true,
			nav: true,
			dots: false,
			autoplayHoverPause: true,
            autoplay: true,
            smartSpeed: 1000,
            margin: 20,
            navText: [
                "<i class='fa fa-chevron-left'></i>",
                "<i class='fa fa-chevron-right'></i>"
            ],
			responsive: {
                0: {
                    items: 1,
                },
                768: {
                    items: 1,
                },
                1200: {
                    items: 1,
                }
            }
        });
		
		// Porfolio isotope and filter
		$(window).on('load', function () {
			var projectIsotope = $('.project-container').isotope({
				itemSelector: '.project-grid-item'
			});
			$('#project-flters li').on('click', function () {
				$("#project-flters li").removeClass('filter-active');
				$(this).addClass('filter-active');
				projectIsotope.isotope({
					filter: $(this).data('filter')
				});
			});
		});

        // Go to Top
        $(function(){
            // Scroll Event
            $(window).on('scroll', function(){
                var scrolled = $(window).scrollTop();
                if (scrolled > 600) $('.go-top').addClass('active');
                if (scrolled < 600) $('.go-top').removeClass('active');
            });  
            // Click Event
            $('.go-top').on('click', function() {
                $("html, body").animate({ scrollTop: "0" },  500);
            });
        });
        
        // Count Time 
        function makeTimer() {
            var endTime = new Date("June 10, 2022 17:00:00 PDT");			
            var endTime = (Date.parse(endTime)) / 1000;
            var now = new Date();
            var now = (Date.parse(now) / 1000);
            var timeLeft = endTime - now;
            var days = Math.floor(timeLeft / 86400); 
            var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
            var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
            var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
            if (hours < "10") { hours = "0" + hours; }
            if (minutes < "10") { minutes = "0" + minutes; }
            if (seconds < "10") { seconds = "0" + seconds; }
            $("#days").html(days + "<span>Days</span>");
            $("#hours").html(hours + "<span>Hours</span>");
            $("#minutes").html(minutes + "<span>Minutes</span>");
            $("#seconds").html(seconds + "<span>Seconds</span>");
        }
        setInterval(function() { makeTimer(); }, 1000);

    });
	
	// WOW JS
	$(window).on ('load', function (){
        if ($(".wow").length) { 
            var wow = new WOW ({
                boxClass:     'wow',      // Animated element css class (default is wow)
                animateClass: 'animated', // Animation css class (default is animated)
                offset:       20,         // Distance to the element when triggering the animation (default is 0)
                mobile:       true,       // Trigger animations on mobile devices (default is true)
                live:         true,       // Act on asynchronously loaded content (default is true)
            });
            wow.init();
        }
    });

    // Preloader Area
	/*
    $(window).on('load', function() {
		$('.preloader').addClass('preloader-deactivate');
	});
    */

}(jQuery));

//main sec2 모바일 기기 이미지
if(document.querySelector('.api-area .api-content-text')) {

    let api_parent = document.querySelector('.api-area .api-content-text');
    let api_child = document.querySelectorAll('.api-content-text__inner-wrap');

    api_parent.addEventListener('click', function(el) {
        if (el.target.nodeName === 'UL') {
            return;
        }

        Array.from(api_child).forEach(child => child.classList.remove('selected'))

        if(el.target.nodeName == 'H5' || el.target.nodeName == 'P') {
            el.target.parentElement.classList.add('selected');
        } else if(el.target.classList.contains('api-content-text__inner-wrap')) {
            el.target.classList.add('selected');
        }

        let mobile_imgEls = document.querySelectorAll('.screen-img-content img');

        for(let i=0; i<api_child.length; i++) {
            mobile_imgEls[i].style.opacity = '0';
            mobile_imgEls[i].style.transform = 'translate(0, 180px)'

            if(api_child[i].classList.contains('selected')) {
                mobile_imgEls[i].style.opacity = '1';
                mobile_imgEls[i].style.transform = 'translate(0, 0)'
            }
        }

        //스크롤 이동 (모바일이 보이게)
        const apiEl_top = document.querySelector('.api-area').offsetTop;

        window.scroll({
            top: apiEl_top,
            behavior: 'smooth'
        });
    });
}

//푸터 아코디언
const footerAccordianBtn = document.querySelector('.com-info-wrap .footer-heading h3');
const rsInfoWrap = document.querySelector('.com-info-wrap');
const rsInfoCon = document.querySelector('com-info-detail')

footerAccordianBtn.onclick = function() {
    rsInfoWrap.classList.toggle('active')
}

//검색창 포커스
const searchEl = document.querySelector('.figure-area .search-field');

if(searchEl) {
    searchEl.focus();
};

//검색 이미지, 텍스트 세로 정렬
function searchLayout() {
    if(document.querySelector('.figure-area') && document.querySelector('.figure-area').classList.contains('search-result-page') === false) {
        const winH = window.innerHeight;
        const figureEl = document.getElementsByClassName('figure-area')[0];

        if(window.innerWidth <= 991){
            figureEl.setAttribute('style', `height:calc((${winH} - 80) * 1px)`);
        } else if (window.innerWidth > 991) {
            figureEl.setAttribute('style', 'height:70vh');
        }

    };
}

searchLayout();
window.addEventListener('resize', searchLayout);

//카카오 문의하기
// function chatTimer() {
// 	document.querySelector('.floating-chat__overflow-hide').setAttribute('style', 'width: 220px');  
// 	setTimeout(() => {
// 		document.querySelector('.floating-chat__overflow-hide').setAttribute('style', 'width: 60px'); 
// 	}, 4000);
	
// 	sessionStorage.setItem('floatChat', 'floatChat');
// }

// window.addEventListener('load', function() {
//     if(sessionStorage.getItem('floatChat') === null) {
//         var login = "<?php echo $member['mb_id']; ?>";
//         setTimeout(() => {
//             if (window.alarmWebScreen) {
//                 // clearTimeout(chatTimeoutNum);
//                 console.log('chatTimeoutClear')
//             } else {
//                 if (!login) {
//                     chatTimer();
//                     console.log(sessionStorage.getItem('floatChat'));
//                 }
//                 setTimeout(() => {
//                     chatTimer();
//                 }, 94000);
//             }
//         }, 1000);
//     } else {
//         console.log(sessionStorage.getItem('floatChat'));
//     }
// })

// window.addEventListener('load', function() {
// 	chatTimer();
// })