jQuery(function($){

	// animate
	animate();
	$(window).scroll(animate);
	$(window).resize(animate);
	function animate(){
		$('.motion').each(function(index){
			var scrollPos = $(window).scrollTop()+($(window).height()/1.3);
			if(scrollPos > $(this).offset().top){
				$(this).addClass('animate');
			}
		});
	};

	/* 전체메뉴 */
	$('.amenu_open').click(function() {
		$('body').addClass("fixed");
		anioption = {
			time: 0.8,
			easing: 'easeOutCubic'
		};
		$('#allMenu').animate({
			"right": "0"
		}, anioption);
		$('.dim').fadeIn();
		return false;
	});
	$('.amenu_close').click(function() {
		anioption = {
			time: 0.6,
			easing: 'easeOutCubic'
		};
		$('.amenu_area').animate({
			"right": "-360px"
		}, anioption);
		$('body').removeClass("fixed");
		$('.dim').fadeOut();
		return false;
	});
	$('.dim').click(function() {
		anioption = {
			time: 0.6,
			easing: 'easeOutCubic'
		};
		$('.amenu_area').animate({
			"right": "-360px"
		}, anioption);
		$('body').removeClass("fixed");
		$('.dim').fadeOut();
	});

	$("#anb > li").each(function(){
		$(this).has('.depth2').addClass('parent');
	});

	/* 전체메뉴 토글 */
	var anb_flag = 0;
	$("#anb > li.parent > a").click(function() {
		if(anb_flag == 0){
			if($(this).hasClass('active')){
				anb_flag = 1;
				$(this).removeClass('active').next('.depth2').slideUp( 300, function(){
					anb_flag = 0;
				});
			}else{
				anb_flag = 1;
				$("#anb .depth1 > a").removeClass('active').next('.depth2').slideUp(300);
				$(this).addClass('active').next('.depth2').slideDown( 300, function(){
					anb_flag = 0;
				});
			}
		}
		return false;
	});

	/* GNB */
	var $header = $('#header'),
		$gnb_wrap = $('#headGlobal'),
		$gnb = $('#gnb'),
		$gnb_item = $('#gnb > li'),
		$gnb_btn = $('#gnb > li > a'),
		$gnb_depth2 = $('#gnb .depth2'),
		min_height = '6rem',
		max_height = '31rem';

	function gnb_open(){

		if($(this).parent().children().hasClass('active')){
			$gnb_item.removeClass('active');
			$(this).addClass('active');
		}else{
			$(this).addClass('active');
		}

		$gnb_wrap.stop().animate({'height' : max_height}, 400, 'easeInOutExpo' );
		$header.addClass('active');
		$gnb_depth2.show();
	}

	function gnb_close(){
		$gnb_item.removeClass('active');
		$gnb_wrap.stop().animate({'height' : min_height}, 400, 'easeInOutExpo', function(){
			$header.removeClass('active');
			$gnb_depth2.hide();
		});
	}

	$gnb_wrap.on('mouseleave', gnb_close);
	$gnb.on('focusout', gnb_close);
	$gnb_item.on('mouseenter focusin click', gnb_open);

	var mediaSwiper = new Swiper(".visual-slider", {
		slidesPerView: 1,
		spaceBetween: 0,
		loop: true,
		loopAdditionalSlides : 1,
		speed : 900,
		autoplay: {
			delay: 4000,
			disableOnInteraction: false,
		},
		pagination: {
			el: '.swiper-pagination',
			clickable: true,
		},
	});
	$('.visual-slider').on('mouseenter', function(e){
		mediaSwiper.autoplay.stop();
	})
	$('.visual-slider').on('mouseleave', function(e){
		mediaSwiper.autoplay.start();
	})

	var bannerSwiper = new Swiper(".banner-swiper", {
		slidesPerView: "auto",
		spaceBetween: 0,
		freeMode: true,
		loop: true,
		loopAdditionalSlides : 1,
		speed : 700,
		allowTouchMove : false,
		autoplay: {
			delay: 2000,
			disableOnInteraction: false,
		}
	});

	$('.banner-swiper').on('mouseenter', function(e){
		bannerSwiper.autoplay.stop();
	})
	$('.banner-swiper').on('mouseleave', function(e){
		bannerSwiper.autoplay.start();
	})

	$('#mainSectRnw01 .exaLst li').on('mouseover',function(){
		let idx = $(this).index();

		$('#mainSectRnw01 .exaLst li').removeClass('on');
		$('#mainSectRnw01 .exaLst li').eq(idx).addClass('on');

		$('#mainSectRnw01 .exaCont .box').removeClass('on');
		$('#mainSectRnw01 .exaCont .box').eq(idx).addClass('on');
	})

});