<?
	require_once(APPPATH."views/m/common/navigation.php");
	
	?>


	<!-- 슬라이드 시작 -->
	<div class="swiper-container mainswiper">
		<div class="swiper-wrapper">

			<!-- 은혜 -->
            <div class="swiper-slide" data-hash="grace">
                <?require_once(APPPATH."views/m/grace/main.php");?>
            </div>
			<!-- 은혜 끝 -->
            
			<!-- 라이프 -->
            <div class="swiper-slide" data-hash="life">
			     <?require_once(APPPATH."views/m/life/main.php");?>
            </div>
			<!-- 라이프 끝 -->

			<!-- 뉴스 -->
            <div class="swiper-slide" data-hash="newss">
			     <?require_once(APPPATH."views/m/news/main.php");?>
            </div>
			<!-- 뉴스 끝 -->

			<!-- 바로가기 -->
            <div class="swiper-slide" data-hash="shortcut">
			     <?require_once(APPPATH."views/m/shortcut/main.php");?>
            </div>
			<!-- 바로가기 끝 -->

		</div>
	</div>


<script>

</script>

<!-- 슬라이드 스크립트 -->
<!--script src="/js/m/swiper.js"></script-->
<script>
	if(location.hash == '#grace'){
		pager = 0;
	}
	else if(location.hash == '#life'){
		pager = 1;
	}
	else if(location.hash == '#newss'){
		pager = 2;
	}
	else if(location.hash == '#shortcut'){
		pager = 3;
	}
	else{
		pager = 0;
	}
	$(".news_nav").find("span").removeClass("current");
	$(".news_nav").find("span").eq(pager).addClass("current");

	console.log(location.hash);
	// 루프용 슬라이드
	var swiper1 = new Swiper('.mainswiper', {
		loop: true,
		autoHeight: true,
		hashNavigation: {
        	watchState: true,
            //replaceState: true,
      	},
        initialSlide : pager,
        //history: {
         //   replaceState: true,
        //},
	});
    $('.news_media3').click(function(){
        swiper1.updateAutoHeight();
    });
    //swiper1.on('tap', function () {
    //    swiper1.updateAutoHeight();
    // });
    console.log(location.hash);
	$(document).on("touchend mousemove", ".mainswiper", function(){
		console.log(swiper1.activeIndex);
		// 슬라이드 당겼을 때, 전 current 제거
		$(".news_nav .current").removeClass('current')
		// 슬라이드 당겼을 떄, 후 current 생성
		slide_index = swiper1.activeIndex-1;
		if(swiper1.activeIndex==5){
			slide_index = 0; 
		}
		$(".news_nav span").eq(slide_index).addClass('current')
        $(window).scrollTop(0);
        
	});
	var swiper2 = new Swiper('.swiper-03', {
		slidesPerView: 3,
		spaceBetween: 10,
		navigation: {
			nextEl: '.swiper-button-next',
			prevEl: '.swiper-button-prev',
		},
	});
</script>


<script>

	// 홈 만나 를 클릭했을때 슬라이드 이동
	$(".news_nav span").on('touchstart mousedown',function(e){
		//console.log('클릭이동');
		// 터치하거나, 마우스 다운을 눌렀을 때, 실행 금지
		e.preventDefault();
		// 은혜, 라이프,,, 클릭시, 전 current 제거
		$(".news_nav .current").removeClass('current')
		// 후 current 생성
		$(this).addClass('current');
        $(window).scrollTop(0);
		// 후 슬라이드로 이동
		swiper1.slideTo( $(this).index()+1 );
		$(".life_list_top > li > a").removeClass("current");
		$(".life_list_top > li > a").eq($(this).index() ).addClass("current");

	})
	$(".news_nav span").click(function(e){
		// 홈 만나 클릭시 실행 금지.
		e.preventDefault()
	})

	function change_slide(i){

		$('.life_close').trigger("click");
		setTimeout(function(){

			$(".news_nav span").eq(i).trigger("mousedown");
			$(".life_list_top > li > a").removeClass("current");
			$(".life_list_top > li > a").eq(i).addClass("current");

		},100);;

		$(window).scrollTop(0);


	}
</script>
<!-- 슬라이드 스크립트 끝-->

<script>
	var mySwiper ;
	$(document).ready(function(){

		$('.news_menu').click(function(){
			$('.life_menu_l').addClass('active');
			$('.mainswiper').css('height','740px');
		});
		$('.life_close').click(function(){
			$('.life_menu_l').removeClass('active');
			$('.mainswiper').css('height','auto');
		});
        $('.dims').click(function(){
			$('.life_menu_l').removeClass('active');
			$('.mainswiper').css('height','auto');
		});
	});
</script>
<script>
	function detectswipe(el,func) {
		swipe_det = new Object();
		swipe_det.sX = 0;
		swipe_det.sY = 0;
		swipe_det.eX = 0;
		swipe_det.eY = 0;
		var min_x = 20;  //min x swipe for horizontal swipe
		var max_x = 40;  //max x difference for vertical swipe
		var min_y = 40;  //min y swipe for vertical swipe
		var max_y = 50;  //max y difference for horizontal swipe
		var direc = "";
		ele = document.getElementById(el);
		ele.addEventListener('touchstart',function(e){
			var t = e.touches[0];
			swipe_det.sX = t.screenX;
			swipe_det.sY = t.screenY;
		},false);
		ele.addEventListener('touchmove',function(e){
			e.preventDefault();
			var t = e.touches[0];
			swipe_det.eX = t.screenX;
			swipe_det.eY = t.screenY;
		},false);
		ele.addEventListener('touchend',function(e){
			//horizontal detection
			if ((((swipe_det.eX - min_x > swipe_det.sX) || (swipe_det.eX + min_x < swipe_det.sX)) && ((swipe_det.eY < swipe_det.sY + max_y) && (swipe_det.sY > swipe_det.eY - max_y)))) {
				if(swipe_det.eX > swipe_det.sX) direc = "r";
				else direc = "l";
			}
			//vertical detection
			if ((((swipe_det.eY - min_y > swipe_det.sY) || (swipe_det.eY + min_y < swipe_det.sY)) && ((swipe_det.eX < swipe_det.sX + max_x) && (swipe_det.sX > swipe_det.eX - max_x)))) {
				if(swipe_det.eY > swipe_det.sY) direc = "d";
				else direc = "u";
			}

			if (direc != "") {
				if(typeof func == 'function') func(el,direc);
			}
			direc = "";
		},false);
	}

	function myfunction(el,d) {
		$('.life_menu_l').removeClass('active');
		$('.mainswiper').css('height','auto');
	}
	detectswipe('swipeme',myfunction);
    
</script>

	<!-- 슬라이드 끝 -->
