$(document).ready(function(){
    gnbMenu();
    selectTab("#tab01");  //선생님 메인1
    selectTab("#tab02");  //선생님 메인2
    selectTab("#tab04");  //수험정보 sub01
    selectTab("#tab05");  //수험정보 sub02
    selectTab("#tab07"); //자주묻는질문 tab
    selectTab("#tab08"); //인터넷서점

    try {
        minHeight();
    } catch (e) { }

    /*공통 header 왼쪽 배너*/
    if ($('#headerB .swiper-slide').length > 1) {
        var swiper = new Swiper('#headerB', {
            direction: 'vertical',
            autoplay: {
	            delay: 2500,
	            disableOnInteraction: false,
	        },
            loop: true,
            pagination: {
                el: '#headerB .swiper-pagination',
                clickable: true,
            },
        });
    }

	/* GNB 고정 Test */
	(function(){
		var root = $('.hd_utility');
		var hdLogo = $('.hd_logo');
		$(window).scroll(function(){
			$.fn.gnbFixed = function(){
				if($(window).scrollTop() > hdLogo.offset().top + hdLogo.innerHeight()){
					root.addClass('fixed');
					$('.hd_bottom').addClass('fixed');
					hdLogo.addClass('fixed');
					$('.scr_header').css({top:'62px'});
				}else{
					root.removeClass('fixed');
					$('.hd_bottom').removeClass('fixed');
					hdLogo.removeClass('fixed');
				};
			};
//			$(document).gnbFixed();
		});
    })();
    


    /* ---헤더 링크 리스트 .homep_link --- */
    $('.hd_top .homep_link .road1').click(function () {
        //console.log($(this).hasClass('on'));
        if ($(this).hasClass('on')) {
            $(this).removeClass('on');
        } else {
            $('.hd_top .homep_link .road1').removeClass('on');
            $(this).addClass('on');
        }
    });
    
    /* ---// 헤더 링크 리스트 .homep_link --- */


    /* --- 헤더 '공무원강좌' 9/7급 셀렉트 --- */
    
    
    var dthidx;

    $("#headertop .hd_utility .mnu_list.off .depview").hover(function(){
        dthidx = $(this).index();

        $("#headertop .hd_utility .mnu_list.off  > li").each(function(i){
            if(dthidx == i){
                //over
                $(this).addClass("on");
                $(this).find(".depth_hover").show();
            }else{
                //out
                $(this).removeClass("on");
                $(this).find(".depth_hover").hide();
            };
        });

    },  function(){

        dthidx = $("#headertop .hd_utility .mnu_list.off  > li").length;


        $("#headertop .hd_utility .mnu_list.off  > li").each(function(i){
            if(dthidx == i){
                //over
                $(this).addClass("on");
                $(this).find(".depth_hover").show();
            }else{
                //out
                $(this).removeClass("on");
                $(this).find(".depth_hover").hide();
            };
        });
    }); 



    
    /* --- // 헤더 '공무원강좌' 9/7급 셀렉트 --- */



    /* ---온라인 학원 링크 리스트 .hd_utility.right_btn --- */

    // depth2
    $('.hd_utility .right_btn.online > a').click(function () {
        if ($(this).hasClass('on')) {
            $(this).removeClass('on');
        } else {
            $('.hd_utility .right_btn.online > a').removeClass('on');
            $(this).addClass('on');

        }
    });

    // depth3
    $('.hd_utility .right_btn.online a.road2').click(function () {
        if ($(this).hasClass('on')) {
            $(this).removeClass('on');
        } else {
            $(this).addClass('on');
        }
    });

    /* ---// 온라인 학원 링크 리스트 homep_link --- */


    

});

function gnbMenu(){
  $('.lnb li').bind('click', function () {
	var target = $(this);
    if(!$(this).hasClass("on")){
  		$(this).parents().find('.lnb li').removeClass("on");
  		$(this).addClass("on");
  	}else{
  		$(this).removeClass('on');
  	}
	});
}

function minHeight() {
    try {
        var footerH = document.getElementById('mFooter').offsetHeight,
          headerH = document.getElementById('mheader').offsetHeight,
          sectionH = (window.innerHeight) - footerH - headerH;
        document.getElementById('mContainer').style.minHeight = sectionH + 'px';
    } catch (e) {
        var footerH = document.getElementById('footer').offsetHeight,
          headerH = document.getElementById('headertop').offsetHeight,
          sectionH = (window.innerHeight) - footerH - headerH;
        document.getElementById('mContainer').style.minHeight = sectionH + 'px';
    }
}

/*common tab*/
function selectTab(selector){
   var selectedTab =null;
   var Tabs = $(selector).find("li");
   Tabs.click(function(){
     selectedTab = $(this);
     if(selectedTab!=null){
       selectedTab.parent().find("li").removeClass("on");
       selectedTab.addClass("on");
       selectedTab.parent().siblings().find($(".tab_content")).css('display','none');
       var activeTab = selectedTab.attr("rel");
       $("#" + activeTab).fadeIn()
     }
   });
 }


 //공용레이어 처리////////////////////////////////////////////////////////
function fncLayerShow(i, a, s) {

    //팝업개체
    var e = $('#' + i);

    //화면의 높이와 너비를 구한다.
    var maskWidth = $(document).width();
    var maskHeight = $(document).height();

    var popWidth = e.width();

    var popHeight = e.height();
    $("body").append("<div class='darkmask'></div>");
    var t = $(".darkmask");
    //마스크의 높이와 너비를 화면 것으로 만들어 전체 화면을 채운다.
    t.css({ 'width': '100%', 'height': maskHeight });

    //애니메이션 효과 - 일단 1초동안 까맣게 됐다가 80% 불투명도로 간다.
    t.fadeIn(1);
    $('html,body').css('overflow','hidden');
    t.fadeTo("slow", 0.8);

    var ph = $(window).height() - popHeight;
    if (ph < 0) { ph = 0; }
    e.css({ 'left': ($(window).width() - popWidth) / 2, 'top': (ph) / 2 });

    eval("e." + a + "('" + s + "')");
}

function fncLayerHide(i, a, s) {
    var t = $(".darkmask");

    t.fadeOut('fast');
    $('.darkmask').remove();
    $('html,body').css('overflow','visible');
    var e = $('#' + i);
    eval("e." + a + "('" + s + "')");
}
//공용레이어 처리////////////////////////////////////////////////////////

// 슬릭 랜덤처리시 사용 , ex : $(".elem").randomize().slick();
$.fn.randomize = function (selector) {
  var $elems = selector ? $(this).find(selector) : $(this).children(),
      $parents = $elems.parent();

  $parents.each(function () {
      $(this).children(selector).sort(function (childA, childB) {
          // * Prevent last slide from being reordered
          if($(childB).index() !== $(this).children(selector).length - 1) {
              return Math.round(Math.random()) - 0.5;
          }
      }.bind(this)).detach().appendTo(this);
  });

  return this;
};

