$(document).on("ready", function() {
	aside_sns();
	aside_article();
	conSlider();
	conContent();
	schPost();
	breadcrumbs();
	audioCnt ();
	//outSiteChk();
	outSiteChk();
});

$(window).on('load', function() {
	prevNext();
	scrollIndicator();
	ellipsis();
	page();
});

function page () {

	var activeNavDep1 = $('.header .gnb .nav > li.on > a').text();
	//	var activeNavDep2 = $('.header .gnb .nav > li.on div li.on a').text();
	var activeNavDep2 = $('.breadcrumbs .lst .dep2 span').text();
	var pageTitle = $('.view_title h1').text();
	if(pageTitle=='' || activeNavDep2==''){
		printNav = activeNavDep2;
	}else if((pageTitle!='' && activeNavDep2!='')){
		printNav = '<span>' + activeNavDep2 + '</span>';
	}

	$('body:not(.main) .header > .container').append('<h2 class="page_title">' + printNav + '<strong>' + pageTitle + '</strong>' + '</h2>');

	//뷰페이지 상단 이전페이지
	if($('#main').hasClass('view')){
		$('.header').addClass('view');
		$('body:not(.main) .header > .container').prepend('<button type="button" class="view_prev">이전페이지</button>')
	}

	$(document).on('click', '.view_prev',function(){
		window.history.go(-1);
	});
};

function scrollIndicator () {

	$('body:not(.main) #header').append('<i class="scroll_indicator"><span></span></i>');

	$(window).on("scroll", function() {
		if ($('body:not(.main) .scroll_indicator').length && $('.area_contents').height() > 780 ) {
			var articleHeight = $('.footer').offset().top - $('main.sub').offset().top - window.innerHeight;
			var articleStart = $(window).scrollTop() - $('main.sub').offset().top;
			var percentage = (articleStart / articleHeight) * 100;
			percentage = percentage > 100 ? 100 : percentage;
			$('.scroll_indicator span').css('width', Math.floor(percentage) + '%');
			$('.scroll_indicator').removeClass('hide');
		}
	});

};


function breadcrumbs () {
	$('.breadcrumbs .select button').attr('title','메뉴 열기')
	$('.breadcrumbs .select button').on('click', function() {
		if($(this).parent().hasClass('is-open')){
			$(this).parent().removeClass('is-open');
			$(this).next('.blst').stop().slideUp(150);
			$(this).attr('title','메뉴 열기')
		}else{
			$(this).parent().addClass('is-open');
			$(this).next('.blst').stop().slideDown(300);
			$(this).attr('title','메뉴 닫기')
		}
	});

	//브래드크럼 하위 토글 영역 외 닫기
	if($('.breadcrumbs .select').length > 0){
		window.addEventListener('click', (e) => {
			if(!e.target.closest('.lst')){
				$('.breadcrumbs .select').removeClass('is-open').children('.blst').stop().slideUp(150);
				$('.breadcrumbs .select button').attr('title','메뉴 열기');
			}
		});
		/*$(document).on('click focusin', function(e) {
			if(!$('.breadcrumbs .select').is(e.target) && $('.breadcrumbs .select').has(e.target).length === 0){
				$('.breadcrumbs .select').removeClass('is-open').children('.blst').stop().slideUp(150);
				$('.breadcrumbs .select button').attr('title','메뉴 열기')
			}
		});*/
	}

	/*
	$('.blst').css({ width: $('.blst > ul').innerWidth() + 'px'});
	$('.breadcrumbs .select').each(function(i){
		$(this).find('.blst').css({ top: $('.blst > ul').innerWidth() + 'px'});
	});
	*/

};

function aside_sns () {

	$('.share .open').on('click', function() {
		if($(this).find('span').text() == '공유열기' ){
			$(this).next('.share_lst').stop().fadeIn(300);
			$(this).find('span').text('공유닫기');
			$(this).parent().addClass('is-open');
		}else{
			$(this).find('span').text('공유열기');
			$(this).next('.share_lst').stop().fadeOut(300);
			$(this).parent().removeClass('is-open');
		}
	});

	$('.share_lst .close').on('click focusout', function() {
		$(this).parent('.share_lst').stop().fadeOut(300);
		$(this).parent().parent('li').removeClass('is-open');
		$('.share .open span').text('공유열기');
		$('.share .open').focus();
	});

	if($('.share').length > 0){
		$(document).on('click', function(e) {
			if(!$('.share').is(e.target) && $('.share').has(e.target).length === 0){
				$('.share').removeClass('is-open');
				$('.share .open span').text('공유열기');
				$('.share_lst').stop().fadeOut(300);
			}
		});
	}

	$('.as_sns .comment').on('click', function() {
		$('.livere_comment').addClass('close').next('.livere_box').show();
		$('.livere_comment').find('span i').text('닫기');
		$('html').animate({scrollTop:$('.livere_box').offset().top - 200},100);
		$('.livere_comment button').focus();
    });

};

function aside_article () {

	$('.policy_home .btn').on('click',function(){
		if($(this).find('span').text() == '전체보기' ){
			$(this).find('span').text('닫기');
			$(this).addClass('close').parent().addClass('active');
		}else{
			$(this).find('span').text('전체보기');
			$(this).removeClass('close').parent().removeClass('active');
		}
	});
	$('.policy_home .list').append('<div class="control"><div class="dots"></div><button type="button" class="playing pause">정지</button></div>');
	$('.policy_home .slider').on('init', function(event, slick) {
		if($(this).hasClass('slick-dotted')){
			$('.policy_home .control').show();
		}else{
			$('.policy_home .control').hide();
		}
	}).slick({
		autoplay: true,
		autoplaySpeed: 5000,
		arrows: false,
		dots: true,
		variableWidth:false,
		adaptiveHeight: true,
		cssEase: 'ease-in-out',
		swipe:true,
		appendDots: $('.policy_home .control .dots'),
	});
	$('.policy_home .playing').click(function(){
		if($(this).hasClass('pause')){
			$(this).parent().parent().find('.slider').slick('slickPause');
		}else if ($(this).hasClass("play")) {
			$(this).parent().parent().children('.slider').slick("slickPlay");
		}
	});


	$('.as_tab li:first-child button').attr('title','선택됨');
	$('.as_tab li > button').on('click focus',function(){
		$(this).attr('title','선택됨').parent().addClass('active').siblings().removeClass('active').children('button').attr('title','');
		var idx = $(this).parent().index();
		$(this).next('.cont').eq(idx).fadeIn().siblings('.cont').fadeOut();
		$('.as_tab li.active .lst li .text span').trigger('update.dot');
	});


	/*
	$('.focus_menu .keywords').on('init', function(event, slick) {
		$('.focus_menu .keywords .slick-arrow').insertBefore('.focus_menu .keywords .slick-list');
		$(this).append('<div class="slick-counter"><span class="current"></span> / <span class="total"></span></div>');
		$('.focus_menu .keywords .current').text(slick.currentSlide + 1);
		$('.focus_menu .keywords .total').text(slick.slideCount);
	}).slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		infinite:false,
		autoplay: false,
		arrows: true,
		adaptiveHeight: true,
	}).on('beforeChange', function(event, slick, currentSlide, nextSlide) {
		$('.focus_menu .keywords .current').text(nextSlide + 1);
	});
	*/

};

function conSlider () {

	$('.slider_nav').flexslider({
		animation: 'slide',
		controlNav: false,
		animationLoop: false,
		slideshow: false,
		itemWidth: 120,
		maxItems: 5,
		minItems: 5,
		itemMargin:0,
		touch: false,
		asNavFor: '.slider_for',
		isFirefox: true,
	});
	$('.slider_for').flexslider({
		animation: 'slide',
		controlNav: false,
		animationLoop: false,
		slideshow: false,
		slideshowSpeed: 500,
		animationSpeed: 150,
		sync: '.slider_nav',
		isFirefox: true,
		after: function(slider) {
			$('.slider_wrap .current-slide').text(slider.currentSlide + 1);
			if(slider.count === slider.currentSlide + 1){
				$('.slider_wrap .first').show();
			}else{
				$('.slider_wrap .first').hide();
			};
			$('#photoText ul li').each(function(i){
				if (i + 1 == slider.currentSlide + 1 ){
					$(this).show();
				} else {
					$(this).hide();
				}
			});
			$('.photoview_slider .down ul li').each(function(i){
				if (i + 1 == slider.currentSlide + 1 ){
					$(this).addClass('active');
				} else {
					$(this).removeClass('active');
				}
			});
		},
		start: function(slider) {
			$('.slider_nav').resize();
			$('.slider_wrap .slider_for').append('<div class="current"><span class="current-slide"></span>/<span class="total-slides"></span></div>');
			$('.slider_wrap .current-slide').text(slider.currentSlide + 1);
			$('.slider_wrap .total-slides').text(slider.count);
			$('#photoText ul li').each(function(i){
				if (i + 1 == slider.currentSlide + 1 ){
					$(this).show();
				} else {
					$(this).hide();
				}
			});
			$('.photoview_slider .down ul li').each(function(i){
				if (i + 1 == slider.currentSlide + 1 ){
					$(this).addClass('active');
				} else {
					$(this).removeClass('active');
				}
			});

		}

	});

	$('.slider_wrap .first button').on('click', function(){
		$('.slider_for').flexslider(0);
		$('.slider_nav').flexslider(0);
    });

	$('.slider_nav button').on('focusin', function(){
		var bt = this;
		var cnt = 0;
		$('.slider_nav button').each(function(i){
			if(this == bt){
				cnt = i
			}
		})
		$('.slider_for').flexslider(cnt)
	});

	$('.slider_wrap .clickFalse').bind('contextmenu', function(e){
		alert('우클릭금지');
		return false;
    });

	$('.slider_nav .slides').each(function(){
		if ($(this).find('li').length > 5){
			$(this).removeClass('center');
		} else {
			$(this).addClass('center');
		}
	});

	$('.column_list .slider').slick({
		slidesToShow: 5,
		slidesToScroll: 1,
		autoplay: false,
		autoplaySpeed: 5000,
		arrows: true,
		accessibility: true,
	 });

};

function prevNext () {

	if ($('main.sub').find('.area_page').length > 0){
		$('footer').css('padding-bottom','100px');
		$('.go_top').css('bottom','95px');
	} else if ($('main.sub').find('.area_audio_player').length > 0){
		$('footer').css('padding-bottom','130px');
		$('.go_top').css('bottom','160px');
	} else {
		$('footer').removeAttr('style');
		$('.go_top').css('bottom','50px');
	}

	$(window).on('scroll', function() {
		if($(window).scrollTop()>430){
			$('.area_page').addClass('active');
		}else{
			$('.area_page').removeClass('active');
		}
	});

};

function schPost () {

	$('.sch_post:not(.expert) .tab_nav li > .btn').on('click',function(){
		$(this).attr('title','선택됨').parent().addClass('active').siblings().removeClass('active').children('a').attr('title','');
		var idx = $(this).parent().index();
		$(this).parent().parent().next('.tab_cont_wrap').children('.cont').eq(idx).show().siblings('.cont').hide();
		return false;
	});
	
	/*
	$('.sch_post:not(.expert) .tab_cont_wrap .cont').each(function(){
		if ($(this).children('div').length > 0){
			var idx = $(this).index();
			$(this).parent().parent().find('li').eq(idx).children('a').addClass('ico');
		}
	});
	*/

	$('.sch_post:not(.expert) .tab_cont_wrap button').on('click', function(){
		if($(this).hasClass('close')){
			$(this).removeClass('close').next().stop().hide();
			$(this).find('span i').text('열기');
		}else{
			$(this).addClass('close').next().stop().show();
			$(this).find('span i').text('닫기');
		}
    });

	$('.sort_wrap > li > button').on('click', function(){
		if($(this).hasClass('close')){
			$(this).removeClass('close');
			$(this).attr('title','열기');
		}else{
			$(this).addClass('close');
			$(this).attr('title','닫기');
		}
    });

	$('.sch_post .detail_sch').on('click',function(){
		if($(this).hasClass('active')){
			$('.sch_post .sch_tab').removeClass('active');
			$(this).add($(this).parent('.sch')).removeClass('active');
			$(this).find('span i').text('열기');
			$('#datepicker_box').hide();
		}else{
			$('.sch_post .sch_tab').addClass('active');
			$(this).add($(this).parent('.sch')).addClass('active');
			$(this).find('span i').text('접기');
		}
	});

	$('.sch_brief .inquire #period').on('change',function(){
		if(this.value=='direct'){
			$('.sch_brief .period').stop().show();
		}else{
			$('.sch_brief .period').stop().hide();
		}
	});

	$('.sch_post.expert .sort_tab li:first-child > a').attr('title','선택됨');
	$('.sch_post.expert .sort_tab li').click(function(){
		$(this).children('a').attr('title','선택됨').parent().addClass('active').siblings().removeClass('active').children('a').attr('title','');
		return false;
	});

	$('.sites button').click(function() {
		if($(this).find('i').text() == '열기' ){
			$(this).find('i').text('닫기');
			$(this).next('ul').addClass('active');
		}else{
			$(this).find('i').text('열기');
			$(this).next('ul').removeClass('active');
		}
	});

	$('.sites ul').each(function(){
		if( $('.sites ul').innerHeight() >= 300 ){
			$('.sites ul').css({'overflow':'auto', 'height':'300px'});
		}else{
			$('.sites ul').removeAttr('style');
		}
	});

	if($('.sites').length > 0){
		$(document).on('click focusin', function(e) {
			if(!$('.sites').is(e.target) && $('.sites').has(e.target).length === 0){
				$('.sites button').find('i').text('열기');
				$('.sites').children('ul').removeClass('active');
			}
		});
	}

};

function ellipsis () {

	$('.area_contents .as_side .as_tab  .lst li .text span').dotdotdot({watch:'window', wrap:'letter'});
	$('.area_contents .as_side .as_tab .photo li .text span').dotdotdot({watch:'window', wrap:'letter'});
	$('.area_news_like .lst li a .text strong').dotdotdot({watch:'window', wrap:'letter'});
	$('.area_news_like .lst li a .text span').dotdotdot({watch:'window', wrap:'letter'});
	$('.article_top .text.multi strong').dotdotdot({watch:'window', wrap:'letter'});
	$('.list_type:not(.tbsty, .writer) .text strong').dotdotdot({watch:'window', wrap:'letter'});
	$('.list_type:not(.writer, .type2) .text .lead').dotdotdot({watch:'window', wrap:'letter'});
	$('.photo_list:not(.ebook) .text strong').dotdotdot({watch:'window', wrap:'letter'});
	$('.news_top50 ul li:nth-child(-n+10) .lead').dotdotdot({watch:'window', wrap:'letter'});
	$('.speech-info .text').dotdotdot({watch:'window', wrap:'letter'});
	$('.policy_home .list .slider ul li span.lead').dotdotdot({watch:'window', wrap:'letter'});
	$('.channel_box .sns_lst .lst a .text strong').dotdotdot({watch:'false', wrap:'letter'});
	$('.channel_box .sns_lst .lst a .text span').dotdotdot({watch:'false', wrap:'letter'});

	$('.custom_news_list .text strong').dotdotdot({watch:'false', wrap:'letter'});
	$('.custom_news_list .text span').dotdotdot({watch:'false', wrap:'letter'});

	$('.focus_sea_slide .col1 .text strong, .focus_sea_slide .col1 .text .lead, .focus_sea_slide .text.multi strong, .policy_focus_article .lst .text strong').dotdotdot({watch:'window', wrap:'letter'});
	
	$('.table_list.multiline .subject a').dotdotdot({watch:'false', wrap:'letter'});

};

// 서브페이지 콘텐츠
function conContent () {

	/* 뷰페이지 배너슬라이드 slick */
	$('.area_banner.slider.slick .slide').on('init', function(event, slick) {
		$('.area_banner.slider.slick .current').text(slick.currentSlide + 1);
		$('.area_banner.slider.slick .total').text(slick.slideCount);
	}).slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		dots: false,
		arrows: true,
		focusOnSelect: false,
		vertical: true,
		verticalSwiping: true,
		prevArrow: $('.area_banner.slider.slick .prev'),
		nextArrow: $('.area_banner.slider.slick .next'),
		infinite: true,
		swipe : true,
		accessibility: true,
		autoplay : true,
		autoplaySpeed: 5000,
	}).on('beforeChange', function(event, slick, currentSlide, nextSlide) {
		$('.area_banner.slider.slick .current').text(nextSlide + 1);
	});

	$('.area_banner.slider.slick .slide').slickAuto({
		auto : $('.area_banner.slider.slick .control > div > button.playing'),
		arrows : $('.area_banner.slider.slick .slide .slick-arrow'),
		arrowClickAfterStop : true
	});

	function playStop () {
		if($('.area_banner.slider.slick .control button').hasClass('slick-hidden')){
			$('.area_banner.slider.slick .control').hide();
		}else{
			$('.area_banner.slider.slick .control').show();
		}
	};
	playStop();

	/* 뷰페이지 저작권법 */
	$('.law_copy .text > div > a').on('click', function(){
		$(this).parent().addClass('active').siblings().removeClass('active');
		return false;
	});
	$('.law_law_copy .text > div > a').on('click', function(){
		return false;
	});
	$('.tooltip .close').on('click focusout', function(){
		$(this).parent().parent().removeClass('active');
		$(this).parent().parent().children('a').focus();
	});
	if($('.law_copy_wrap').length > 0){
		$(document).on('click', function(e) {
			if(!$('.law_copy .text > div > a').is(e.target) && $('.law_copy .text > div > a').has(e.target).length === 0){
				$('.law_copy .text > div > a').parent().removeClass('active');
			}
		});
	}

	/* 뷰페이지 관련기사 탭 */
	$('.related .rkey button:first-child').attr('title','선택됨');
	$('.related').on('click', '.rkey button', function(){
		$(this).attr('title','선택됨').addClass('active').siblings().removeClass('active').attr('title','');
	});

	/* 댓글 운영원칙 */
	$('.livere_box .open').on('click', function(){
		$('.livere_info').stop().fadeIn();
		$(this).find('span').text('닫기');
    });
	$('.livere_box .livere_info .close').on('click focusout', function(){
		$('.livere_info').stop().fadeOut();
		$('.livere_box .open').focus();
		$('.livere_box .open').find('span').text('열기');
    });
	if($('.livere_box').length > 0){
		$(document).on('click', function(e) {
			if(!$('.livere_box .open').is(e.target) && $('.livere_box .open').has(e.target).length === 0){
				$('.livere_info').stop().fadeOut();
				$('.livere_box .open').find('span').text('열기');
			}
		});
	}

	/* 브리핑룸 테이블 리스트 수어, 일반 */
	$('.table_list .subject').each(function(){
		if ($(this).find('.vid').length > 0){
			$(this).css('direction','rtl');
		} else {
			$(this).removeAttr('style');
		}
	});

	/* 전자책 부처간행물 국정백서 권 보기 */
	$('.book_btns button').on('click', function(){
		if($(this).hasClass('active')){
			$(this).removeClass('active').next().removeClass('active');
			$(this).find('i').text('열기');
		}else{
			$(this).addClass('active').next().addClass('active');
			$(this).find('i').text('닫기');
		}
    });
	$('.book_btns ul li:last-child a + a').on('focusout', function(){
		$(this).parent().parent('ul').removeClass('active');
    });
	if($('.book_btns').length > 0){
		$(document).on('click', function(e) {
			if(!$('.book_btns button').is(e.target) && $('.book_btns button').has(e.target).length === 0){
				$('.book_btns button').removeClass('active').next().removeClass('active');
			}
		});
	}

	/* 정부소개 - 국가안전보장회의 팝업 */
	$('.orgpop01').on('click', function(){
		$(".pop_org").fadeIn();
		$(".pop_org .close").focus();
		return false;
    });
	$('.pop_org .close').on('click', function(){
		$(".pop_org").fadeOut();
		$(".orgpop01").focus();
		return false;
    });
	if($('.orgpop01').length > 0){
		$(document).on('click', function(e) {
			if(!$('.orgpop01').is(e.target) && $('.orgpop01').has(e.target).length === 0){
				$('.pop_org').fadeOut();
			}
		});
	}

	/* 채널소개 */
	$('.video_lst .slide > ul').addClass('swiper-wrapper');
	$('.video_lst .slide > ul > li').addClass('swiper-slide');
	var videoSlide  = new Swiper($('.video_lst .slide'), {
		slidesPerView: 2,
		slidesPerGroup: 1,
		spaceBetween: 10,
		speed: 600,
		observer: true,
		loop: true,
		loopAdditionalSlides: 1,
		observer: true,
		observeParents: true,
		pagination: {
			el: '.video_lst .swiper-pagination',
			clickable:true,
			renderBullet: function (index, className){
				return '<button class="' + className + '"><span>' + (index + 1) + '</span></button>';
			}
		},
		on: {
			init: function(){
				var idx = this.activeIndex
				$('.video_lst .swiper-slide .video').on('focus', function(e){
					e.preventDefault();
					var idx = $(this).parent().index();
					videoSlide.slideTo(idx);
				});
				if( this.activeIndex <= 2) {
					$('.video_lst .swiper-wrapper').parent().addClass('disabled');
					$('.video_lst .control').hide();
				}else{
					$('.video_lst .swiper-wrapper').parent().removeClass('disabled');
				}
			},
			slideChangeTransitionEnd : function() {
				$('.video_lst .swiper-slide').find('.video').attr('tabindex', '0');
				$('.video_lst .swiper-slide-duplicate .video').attr('tabIndex', '-1');
				$('.video_lst .swiper-slide-duplicate .video video').attr('tabIndex', '-1');
				var videos = document.querySelectorAll('video');
				Array.prototype.forEach.call(videos, function(video){
					video.pause();
				});
			},
		},
	});

	/* 채널소개 - 대한민국 정부 누리소통망 */
	$('.govsns_box > .tab > ul > li:first-child > button').attr('title','선택됨');
	function tabPlay() {
		var tabs = $('.govsns_box > .tab > ul > li');
		timerId = setInterval(function() {
			var onTab = tabs.filter('.active');
			var nextTab = onTab.index() < tabs.length-1 ? onTab.next() : tabs.first();
			nextTab.children('button').attr('title','선택됨').parent().addClass('active').siblings().removeClass('active').children('button').attr('title','');
			nextTab.parent().parent().css('height', $('.govsns_box .tab > ul > li > button').innerHeight() + nextTab.children('.govsns_box .list').innerHeight());
		}, 3000);
	};
	function tabStop() {
		clearInterval(timerId);
	};
	tabPlay();
	$('.govsns_box .tab .playing').on('click', function(){
		if($(this).hasClass('pause')){
			$(this).removeClass("pause").addClass("play").find('span').text('재생');
			tabStop();
		}else if ($(this).hasClass('play')) {
			$(this).removeClass('play').addClass("pause").find('span').text('정지');
			tabPlay();
		}
	});
	$('.govsns_box .tab').css('height', $('.govsns_box .tab').innerHeight() + $('.govsns_box .list').innerHeight());
	$('.govsns_box .tab > ul > li > button').on('click focusin',function(){
		$(this).parent().addClass('active').children('button').attr('title','선택됨');
		$(this).parent().siblings().removeClass('active').children('button').attr('title','');
		$(this).parent().parent().parent().css('height', $(this).next('.list').innerHeight() + $(this).innerHeight());
		tabStop();
		$('.govsns_box .tab .playing').removeClass("pause").addClass("play").find('span').text('재생');
	});
	$('.govsns_box .intab > li > button').on('click focusin',function(){
		$(this).parent().addClass('active').children('button').attr('title','선택됨');
		$(this).parent().siblings().removeClass('active').children('button').attr('title','');
		tabStop();
		$('.govsns_box .tab .playing').removeClass("pause").addClass("play").find('span').text('재생');
	});

	/* 뉴스레터 개인정보 레이어 */
	$(".newsletter_signin .open").click(function(){
		$(".newsletter_signin_cont").fadeIn(300);
		return false;
	});
	$('.newsletter_signin_cont .close').on('click focusout', function() {
		$('.newsletter_signin_cont').fadeOut(300);
		$('.newsletter_signin .open').focus();
		return false;
	});
	if($('.newsletter_signin').length > 0){
		$(document).on('click', function(e) {
			if(!$('.newsletter_signin .open').is(e.target) && $('.newsletter_signin .open').has(e.target).length === 0){
				$(".newsletter_signin_cont").fadeOut(300);
			}
		});
	}

	/* 공통 탭 */
	$('.tabs_common.run ul li > button').on('click focus',function(){
		$(this).parent().addClass('active').siblings().removeClass('active');
		var idx = $(this).parent().index();
		$(this).parent().parent().parent().next('.tabs_commom_cont').children('.cont').eq(idx).show().siblings('.cont').hide();
	});

	$('.tabs_common_focus ul > li:first-child > button').attr('title','선택됨');

	$('.tabs_common_focus:not(.dept_sns)').css('height', $('.tabs_common_focus').innerHeight() + $('.tabs_common_focus .list').innerHeight());

	$('.tabs_common_focus ul li > button').on('click focus',function(){

		$(this).parent().addClass('active').children('button').attr('title','선택됨').parent().siblings().removeClass('active').children('button').attr('title','');

		$(this).parent().parent().parent().css('height', $(this).next('.list').outerHeight() + $(this).outerHeight());
	});

	$('.livere_comment button').on('click', function(){
		if($(this).parent().hasClass('close')){
			$(this).parent().removeClass('close').next().stop().hide();
			$(this).find('span i').text('보기');
		}else{
			$(this).parent().addClass('close').next().stop().show();
			$(this).find('span i').text('닫기');
		}
    });

	$('.news_top50 ul li:nth-child(n+11)').each(function(){
		var title = $("strong", this);
		var dateSpan = $(".date", this);
		title.css("width", "calc(100% - " + (dateSpan.outerWidth() + 15 ) + "px)");
	});

	/* 맞춤정책뉴스 */
	$('.custom_news_select .select > button').on('click', function() {
		if($(this).parent().hasClass('is-open')){
			$(this).parent().removeClass('is-open');
			$(this).next('ul').stop().fadeOut(150);
		}else{
			$(this).parent().addClass('is-open');
			$(this).next('ul').stop().fadeIn(150);
		}
	});
	$('.custom_news_select .select ul li button').on('click',function(){
		var text = $(this).text();
		$(this).parent().parent().prev('button').html(text);
		$(this).parent().parent('ul').stop().fadeOut(150);
		$('.custom_news_select .select').removeClass('is-open');
	});

	if($('.custom_news_select .select').length > 0){
		$(document).on('click focusin', function(e) {
			if(!$('.custom_news_select .select').is(e.target) && $('.custom_news_select .select').has(e.target).length === 0){
				$('.custom_news_select .select').removeClass('is-open').children('ul').stop().fadeOut(150);
			}
		});
	}
	$('.custom_news_tab ul > li:first-child > button').attr('title','선택됨');
	$('.custom_news_tab ul > li button').on('click', function() {
		$(this).parent().addClass('active').children('button').attr('title','선택됨').parent().siblings().removeClass('active').children('button').attr('title','');
	});
	$('.custom_news_list ul li:not(:has(.thumb))').each(function(){
		var cnTitle = $('.text strong', this);
		var cnLead = $('.text span', this);
		if (cnTitle.outerHeight() < 42){
			cnLead.addClass('ehg');
		}
	});

	$('.focus_sea_slide .slide').slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		dots: true,
		arrows: true,
		focusOnSelect: false,
		infinite: true,
		swipe : true,
		accessibility: true,
		appendArrows: $('.focus_sea_slide .control'),
		appendDots: $('.focus_sea_slide .control'),
	});

	/* 자주 묻는 질문 */
	$('.faq_lst > ul > li > button').on('click', function() {
		if($(this).find('span').text() == '펼치기' ){
			$(this).find('span').text('접기');
			$(this).removeClass('close');
		}else{
			$(this).find('span').text('펼치기');
			$(this).addClass('close');
		}
	});

	/* 개인정보처리방침 */
	$('.privacy_togl').on('click', function() {
		if($(this).text() == '내용보기' ){
			$(this).text('내용닫기');
			$(this).addClass('open');
			$('.privacy_togl_box').show();
		}else{
			$(this).text('내용보기');
			$(this).removeClass('open');
			$('.privacy_togl_box').hide();
		}
	});

	$('.cnt_lst a, .cnt_index a, .terms_wrap .label a').on('click', function(e) {
		e.preventDefault();
		$('html, body').animate({scrollTop : $(this.hash).offset().top - 100}, 0);
	});

	/* 의료개혁 */
	$('.medical_slide .slide').slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		dots: true,
		arrows: true,
		prevArrow: $('.medical_slide .prev'),
		nextArrow: $('.medical_slide .next'),
		appendDots: $('.medical_slide .control > div'),
		focusOnSelect: false,
		infinite: true,
		swipe : true,
		accessibility: true,
		autoplay : true,
		autoplaySpeed: 3000,
		//centerMode: true,
		//centerPadding: '15%',
	});
	$('.medical_slide .slide').slickAuto({
		auto : $('.medical_slide button.playing'),
		arrows : $('.medical_slide .slick-arrow'),
		arrowClickAfterStop : true
	});
		
	/* 체고원전 */
	$('.focus_slide.czech .slide').on('init', function(event, slick){
		//$('.focus_slide.czech .control .playing').before('<div class="counter"><span class="current"></span> / <span class="total"></span></div>');
		$('.focus_slide.czech .counter .current').text(slick.currentSlide + 1);
		$('.focus_slide.czech .counter .total').text(slick.slideCount);
	}).slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		dots: true,
		arrows: true,
		prevArrow: $('.focus_slide.czech .prev'),
		nextArrow: $('.focus_slide.czech .next'),
		appendDots: $('.focus_slide.czech .control > div'),
		focusOnSelect: false,
		infinite: true,
		swipe : true,
		accessibility: true,
		autoplay : true,
		autoplaySpeed: 3000,
		//centerMode: true,
		//centerPadding: '15%',
	}).on('beforeChange', function(event, slick, currentSlide, nextSlide) {
		$('.focus_slide.czech .slick-counter .current').text(nextSlide + 1);
	});
	$('.focus_slide.czech .slide').slickAuto({
		auto : $('.focus_slide.czech button.playing'),
		arrows : $('.focus_slide.czech .slick-arrow'),
		arrowClickAfterStop : true
	});
		
	/* 예산안 */
	$('.focus_slide.budget .slide').on('init', function(event, slick) {
		$('.focus_slide.budget .control .current').text(slick.currentSlide + 1);
		$('.focus_slide.budget .control .total').text(slick.slideCount);
	}).slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		arrows: true,
		prevArrow: $('.focus_slide.budget .prev'),
		nextArrow: $('.focus_slide.budget .next'),
		focusOnSelect: false,
		infinite: true,
		swipe : true,
		accessibility: true,
		autoplay : true,
		autoplaySpeed: 3000,
	}).slickAuto({
		auto : $('.focus_slide.budget button.playing'),
		arrows : $('.focus_slide.budget .slick-arrow'),
		arrowClickAfterStop : true
	}).on('beforeChange', function(event, slick, currentSlide, nextSlide) {
		$('.focus_slide.budget .control .current').text(nextSlide + 1);
	});

};


function audioCnt () {
/*
	$('.audio_menu .keywords').on('init', function(event, slick) {
		$('.audio_menu .keywords .slick-arrow').insertBefore('.audio_menu .keywords .slick-list');
		$(this).append('<div class="slick-counter"><span class="current"></span> / <span class="total"></span></div>');
		$('.audio_menu .keywords .current').text(slick.currentSlide + 1);
		$('.audio_menu .keywords .total').text(slick.slideCount);
	}).slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		infinite:false,
		autoplay: false,
		arrows: true,
		adaptiveHeight: true,
	}).on('beforeChange', function(event, slick, currentSlide, nextSlide) {
		$('.audio_menu .keywords .current').text(nextSlide + 1);
	});
*/
	$('.audio_ch_lst .slide > ul').addClass('swiper-wrapper');
	$('.audio_ch_lst .slide > ul > li').addClass('swiper-slide');
	var audioChLst  = new Swiper($('.audio_ch_lst .slide'), {
		slidesPerView: 4,
		spaceBetween: 12,
		speed: 600,
		loop: true,
		loopAdditionalSlides: 1,
		observer: true,
		observeParents: true,
		centeredslides:false,
		navigation: {
			nextEl: '.audio_ch_lst .next',
			prevEl: '.audio_ch_lst .prev'
		},
		pagination: {
			el: '.audio_ch_lst .swiper-pagination',
			clickable:true,
			renderBullet: function (index, className){
				return '<button class="' + className + '"><span>' + (index + 1) + '</span></button>';
			}
		},
		autoplay: {
			delay: 5000,
			disableOnInteraction: false,
		},
		on: {
			init: function(){
				var idx = this.activeIndex
				if( this.activeIndex < 5) {
					$('.audio_ch_lst .swiper-wrapper').addClass('disabled');
					$('.audio_ch_lst .control').hide();
				}else{
					$('.audio_ch_lst .swiper-wrapper').removeClass('disabled');
				}
				$('.audio_ch_lst .swiper-slide a').on('focus', function(e){
					e.preventDefault();
					var idx = $(this).parent().index();
					audioChLst.slideTo(idx);
				});
				$('.audio_ch_lst .swiper-button-play').on('click', function(){
					if($(this).is('.play')) {
						$(this).removeClass('play');
						$(this).addClass('pause');
						$(this).find('span').text('자동슬라이드 멈춤');
						audioChLst.autoplay.start();
					}else if ($(this).is('.pause'))	{
						$(this).removeClass('pause');
						$(this).addClass('play');
						$(this).find('span').text('자동슬라이드 시작');
						audioChLst.autoplay.stop();
					}
				});
				$('.audio_ch_lst .swiper-pagination, .audio_ch_lst .swiper-navigation').on('click', function(){
					$('.audio_ch_lst .swiper-button-play').removeClass('pause');
					$('.audio_ch_lst .swiper-button-play').addClass('play');
					$('.audio_ch_lst .swiper-button-play').find('span').text('자동슬라이드 시작');
					audioChLst.autoplay.stop();
				});
			},
			slideChangeTransitionEnd : function() {
				$('.audio_ch_lst .swiper-slide').find('a').attr('tabindex', '');
				$('.audio_ch_lst .swiper-slide-duplicate a').attr('tabIndex', '-1');
				$('.audio_ch_lst .swiper-slide-duplicate button').attr('tabIndex', '-1');
			},
		},
	});

	$('.ch_share .open').on('click', function() {
		if($(this).find('span').text() == '열기' ){
			$(this).next('.lst').stop().fadeIn(300);
			$(this).find('span').text('닫기');
			$(this).parent().addClass('is-open');
		}else{
			$(this).find('span').text('열기');
			$(this).next('.lst').stop().fadeOut(300);
			$(this).parent().removeClass('is-open');
		}
	});

	$('.ch_share .lst .close').on('click focusin', function() {
		$(this).parent('.ch_share .lst').stop().fadeOut(300);
		$(this).parent().parent('li').removeClass('is-open');
		$('.ch_share .open span').text('열기');
		$('.ch_share .open').focus();
	});

	if($('.ch_share').length > 0){
		$(document).on('click', function(e) {
			if(!$('.ch_share').is(e.target) && $('.ch_share').has(e.target).length === 0){
				$('.ch_share').removeClass('is-open');
				$('.ch_share .open span').text('열기');
				$('.ch_share .lst').stop().fadeOut(300);
			}
		});
	}

	$('.controls_play').on('click', function() {
		if($(this).find('span').text() == '재생하기' ){
			$(this).find('span').text('일시정지');
			$(this).addClass('pause');
		}else{
			$(this).find('span').text('재생하기');
			$(this).removeClass('pause');
		}
	});

	$('.controls_speed').on('click', function() {
		if($(this).find('span:last-child').text() == '재생 속도 바꾸기 열기' ){
			$(this).next('.speed_wrap').stop().fadeIn(300);
			$(this).find('span:last-child').text('재생 속도 바꾸기 닫기');
			$(this).addClass('is-open');
		}else{
			$(this).find('span:last-child').text('재생 속도 바꾸기 열기');
			$(this).next('.speed_wrap').stop().fadeOut(300);
			$(this).removeClass('is-open');
		}
	});
	$('.speed_wrap .close').on('click focusout', function() {
		$(this).parent('.speed_wrap').stop().fadeOut(300);
		$('.controls_speed').removeClass('is-open').find('span:last-child').text('재생 속도 바꾸기 열기');
		$('.controls_speed').focus();
	});

	$('.speed_wrap .close').on('click focusout', function() {
		$(this).parent('.speed_wrap').stop().fadeOut(300);
		$('.controls_speed').removeClass('is-open').find('span:last-child').text('재생 속도 바꾸기 열기');
		$('.controls_speed').focus();
	});

	$('.area_audio_player .buttons .volume').on('click', function() {
		if($(this).find('span').text() == '음소거 해제' ){
			$(this).find('span').text('음소거');
			$(this).addClass('mute');
		}else{
			$(this).find('span').text('음소거 해제');
			$(this).removeClass('mute');
		}
	});

	$('.area_audio_player .buttons .small').on('click', function() {
		if($(this).find('span').text() == '소형플레이어 열기' ){
			$(this).find('span').text('확장플레이어 열기');
			$(this).addClass('is-open');
			$('.area_audio_player').addClass('small');
			$('.speed_wrap').hide();
			$('.controls_speed').removeClass('is-open').find('span:last-child').text('재생 속도 바꾸기 열기');
		}else{
			$(this).find('span').text('소형플레이어 열기');
			$(this).removeClass('is-open');
			$('.area_audio_player').removeClass('small');
		}
	});

	$(window).resize(function() {
		var widthOut = $('.area_audio_player .controller .text strong').width();
		var widthIn = $('.area_audio_player .controller .text strong span').width();
		if( widthIn >= widthOut ){
			$(".area_audio_player .controller .text strong").addClass("is_marquee");
		}else{
			$('.area_audio_player .controller .text strong').removeClass('is_marquee');
		}
	}).trigger('resize');

};

$(function(){
	let ac = 'active';

	//게시글 상단 검색_상세검색
	$('.sch_brief .btn_detail').attr('title','펼치기');
	$('.sch_brief .btn_detail').on('click',function(){
		const t = $(this);
		if(!t.closest('.sch_brief').hasClass(ac)){
			t.attr('title','접기').closest('.sch_brief').addClass(ac);
		}else{
			t.attr('title','펼치기').closest('.sch_brief').removeClass(ac);
		}
	});

	//게시글 상단 상세검색_하위검색조건 열기
	$('.chk_lst .custom_chk input').on('click', function(){
		const data = $(this).data('target');
		if ($(this).attr('name').indexOf('srchOutSite') > -1) {
			$('#srchArea3').closest('.sch_detail').find('.select_opt').removeClass('active');
			$('#srchArea3').closest('.row_item').find('.row_detail').removeClass('active');
		} else {
			$(this).closest('.row_item').find('.row_detail').removeClass(ac);
		}
		$('.' + data).addClass(ac);
	});

	//게시글 상단 상세검색 전체체크
	$('.ul_wrap .chk_all').on('click',function(){
		const t = $(this);
		const chk_target = t.closest('li').find('> ul input[type=checkbox]');
		if(t.is(':checked')){
			chk_target.prop('checked',true);
		}else{
			chk_target.prop('checked',false);
		}
	});

	$('.ul_wrap ul input[type=checkbox]').on('click',function(){
		const t = $(this);
		const total = t.closest('ul').find('input[type=checkbox]').length;
		const checked = t.closest('ul').find('input[type=checkbox]:checked').length;
		const target = t.closest('ul').siblings('.chk_tit').find('input');

		if(total != checked){
			target.prop('checked',false);
		}else{
			target.prop('checked',true);
		}
	});

	//연설문 > 연설자 아이콘
	$('.speechmaker').each(function(){
		const t = $(this);
		if(t.text() == '대통령'){
			t.addClass('t1');
		}else if(t.text() == '국무총리'){
			t.addClass('t2');
		}
	});
	
	//검색버튼 이후 포커스 이동
	$('.sch_detail .btn_bx button:last-child').on('focusout', function() {
		$('.sch_brief .btn_detail').focus().attr('title','펼치기');
		$('.sch_brief').removeClass('active');
	});
});

