function layout(arg) {

    var SCOPE = this;

    SCOPE.option = arg;

    var Selector = SCOPE.option.selector;

    var active = 'in_active';
    var navOffstTop = $(Selector.nav).offset().top;

    $(window).on('scroll', function (event) {

        var tScrollPos = $(this).scrollTop();

        if (tScrollPos > navOffstTop + $(Selector.nav).height()) {
            // 스크롤이 기준을 넘었을 때

            if (!$(Selector.nav).hasClass(active)) {

                $(Selector.nav).addClass(active)
                    .attr('style', 'position:fixed;top:' + ($(Selector.nav).height() * -1) + 'px;left:0;width:100%;')
                    .stop(0, 1).delay(300).animate({
                        'top': '0'
                    }, 500, 'easeOutExpo');
            }
        }

        if (tScrollPos < navOffstTop) {
            // 스크롤이 기준안으로 들어왔을 때

            if ($(Selector.nav).hasClass(active)) {

                $(Selector.nav).removeClass(active)
                    .removeAttr('style');
            }
        }

    });

    /* nav 드롭다운 메뉴 */
    var locateDropnMenuLen = $(Selector.locateDropnMenu).length;

    for (var i = 0; i < locateDropnMenuLen; i++) {

        var locateDropnMenu = $(Selector.locateDropnMenu).eq(i);

        locateDropnMenu.attr({
            'data-height': locateDropnMenu.outerHeight()
        });
    }

    function outDropMenu() {

        for (var j = 0; j < locateDropnMenuLen; j++) {

            var locateDropnMenu = $(Selector.locateDropnMenu).eq(j);

            if (locateDropnMenu.css('display') == 'block') {

                locateDropnMenu
                    .stop(0, 1).animate({
                        'height': '0',
                        'opacity': '0'
                    }, 100, 'easeOutExpo', function () {

                        $(this).css('display', 'none');
                    });
            } else {

                continue;
            }
        }

        return 1;
    }

    var idx = null;

    $(Selector.locate).on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (idx != $(Selector.locate).index(t)) {

            outDropMenu();

            t.next()
                .css({

                    'left': t.position().left,
                    'display': 'block',
                    'height': '0',
                    'opacity': '0',
                    'min-width': t.outerWidth() + 1 // border-left 로 인해 우측 1px 이 부족하기 때문에

                })
                .stop(0, 1).animate({
                    'opacity': '1',
                    'height': t.next().data('height') + 'px'
                }, 100, 'easeOutCubic');
        }

        idx = $(Selector.locate).index(t);
    });

    $(Selector.nav).on('mouseleave', function (event) {

        outDropMenu();

        idx = null;
    });

    return 1;
}

function allCheckedUnChecked(_this, _parents, _child) {

    var allcheckBox = $('input[name=' + _this.name + ']');

    var idx = allcheckBox.index(_this);

    // 전체체크상자가 한 화면에 두개 이상 있을 때
    if (allcheckBox.length > 1) {

        // 현재 것이 아닌 전체선택 상자를 찾아서 체크상태로 만들어 준다.
        var notAllCheckBox = allcheckBox.not(allcheckBox.eq(idx))[0];

        // 현재 것이 아닌 전체선택 상자가 체크된 상태면
        if (notAllCheckBox.checked) {

            // 체크 해제
            notAllCheckBox.checked = false;
        }
        // 체크 상태가 아니면
        else {

            // 체크
            notAllCheckBox.checked = true;
        }
    }

    var parent = $(_this).parents(_parents);

    var bodyTr = parent.find('input[name=' + _child + ']').parent();

    var checkTest = parent.find('input[name=' + _child + ']');
    var checkTestLen = checkTest.length;
    var checkedTrueNumber = 0;

    if (checkTest.filter(':checked').length == checkTestLen) {

        for (var i = 0; i < checkTestLen; i++) {

            checkTest.get(i).checked = false;
        }
    } else {

        for (var i = 0; i < checkTestLen; i++) {

            if (checkTest.get(i).checked == false) {

                checkTest.get(i).checked = true;
            } else {

                continue;
            }
        }
    }

    checkTest.on('click', function (event) {

        _this.checked = false;
    });

    return true;
}

function removeLayer(callBack) {

    $('.huyang_layer').fadeOut(300, 'easeOutCubic', function () {

        $(this).remove();
    });

    if (callBack) {

        if ($.isArray(callBack)) {

            for (var i = 0; i < callBack.length; i++) {

                callBack[i](id);
            }

            return false;
        }

        callBack(id);
    }
}


function photoswipe() {
    // 레이어팝업 이미지 뷰어, 스와이프

    /*

     <!-- Core CSS file -->
     <link rel="stylesheet" href="path/to/photoswipe.css">

     <!-- Skin CSS file (styling of UI - buttons, caption, etc.)
     In the folder of skin CSS file there are also:
     - .png and .svg icons sprite,
     - preloader.gif (for browsers that do not support CSS animations) -->
     <link rel="stylesheet" href="path/to/default-skin/default-skin.css">

     <!-- Core JS file -->
     <script src="path/to/photoswipe.min.js"></script>

     <!-- UI JS file -->
     <script src="path/to/photoswipe-ui-default.min.js"></script>

     */
    var diaPop = $('.diaPop, .diaPopGroup');
    var pswp = $('.pswp');

    if (!diaPop.length) {

        return false;
    }

    if (!pswp.length) {

        var pswp = '' +
            '<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">' +
            '  <div class="pswp__bg"></div>' +
            '  <div class="pswp__scroll-wrap">' +
            '      <div class="pswp__container">' +
            '          <div class="pswp__item"></div>' +
            '          <div class="pswp__item"></div>' +
            '          <div class="pswp__item"></div>' +
            '      </div>' +
            '      <div class="pswp__ui pswp__ui--hidden">' +
            '        <div class="pswp__top-bar">' +
            '          <div class="pswp__counter"></div>' +
            '          <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>' +
            '          <button class="pswp__button pswp__button--share" title="Share"></button>' +
            '          <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>' +
            '          <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>' +
            '          <div class="pswp__preloader">' +
            '              <div class="pswp__preloader__icn">' +
            '                <div class="pswp__preloader__cut">' +
            '                  <div class="pswp__preloader__donut"></div>' +
            '                </div>' +
            '              </div>' +
            '          </div>' +
            '      </div>' +
            '      <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">' +
            '          <div class="pswp__share-tooltip"></div>' +
            '      </div>' +
            '      <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>' +
            '      <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>' +
            '      <div class="pswp__caption">' +
            '          <div class="pswp__caption__center"></div>' +
            '      </div>' +
            '    </div>' +
            '  </div>' +
            '</div>';


        $('body').append(pswp);

        // 리소스 추가
        var doc = document;
        var photoswipeCss = doc.createElement('link');
        photoswipeCss.rel = 'stylesheet';
        photoswipeCss.href = '../js/photoswipe/photoswipe.css';

        var defaultSkinCss = doc.createElement('link');
        defaultSkinCss.rel = 'stylesheet';
        defaultSkinCss.href = '../js/photoswipe/default-skin/default-skin.css';

        var photoswipeMinJs = doc.createElement('script');
        photoswipeMinJs.src = '../js/photoswipe/photoswipe.min.js';

        var photoswipeUiDefaultMinJs = doc.createElement('script');
        photoswipeUiDefaultMinJs.src = '../js/photoswipe/photoswipe-ui-default.min.js';

        var insertTarget = doc.getElementsByTagName('script')[0];

        var arr = [photoswipeCss, defaultSkinCss, photoswipeMinJs, photoswipeUiDefaultMinJs];

        for (var i = 0; i < arr.length; i++) {

            insertTarget.parentNode.insertBefore(arr[i], insertTarget);
        }
    }

    var diaPopImg = '';
    var dataSize = '';
    var size = '';

    // 속성 추가
    for (var j = 0; j < diaPop.length; j++) {

        if (diaPop.eq(j).hasClass('diaPopGroup')) {

            diaPopImg = $('.diaPopGroup img').get(j);

            diaPop.eq(j)
                .wrap('<div class="photoswipe" itemscope itemtype="http://schema.org/ImageGallery">')
                .find('a').attr({

                    'itemprop': 'contentUrl',
                    'data-size': diaPopImg.getAttribute("data-menual") ? diaPopImg.getAttribute("data-menual") : diaPopImg.naturalWidth + 'x' + diaPopImg.naturalHeight

                })
                .wrap('<figure itemprop="associatedMedia">')
                .after('<figcaption itemprop="caption description">')
                .children().attr('itemprop', 'thumbnail');

        } else {

            diaPopImg = $('.diaPop img').get(j);

            diaPop.eq(j)
                .attr({
                    'itemprop': 'contentUrl',
                    'data-size': diaPopImg.getAttribute("data-menual") ? diaPopImg.getAttribute("data-menual") : diaPopImg.naturalWidth + 'x' + diaPopImg.naturalHeight
                })
                .wrap('<div class="photoswipe" itemscope itemtype="http://schema.org/ImageGallery"><figure itemprop="associatedMedia">')
                .after('<figcaption itemprop="caption description" class="photoswipe_caption">')
                .children().attr('itemprop', 'thumbnail');

        }
    }

    var initPhotoSwipeFromDOM = function (gallerySelector) {

        // parse slide data (url, title, size ...) from DOM elements
        // (children of gallerySelector)
        var parseThumbnailElements = function (el) {
            var thumbElements = el.childNodes,
                numNodes = thumbElements.length,
                items = [],
                figureEl,
                linkEl,
                size,
                item;

            for (var i = 0; i < numNodes; i++) {

                figureEl = thumbElements[i]; // <figure> element

                // include only element nodes
                if (figureEl.nodeType !== 1) {
                    continue;
                }

                linkEl = figureEl.children[0]; // <a> element

                size = linkEl.getAttribute('data-size').split('x');

                // create slide object
                item = {
                    src: linkEl.getAttribute('href'),
                    w: parseInt(size[0], 10),
                    h: parseInt(size[1], 10)
                };



                if (figureEl.children.length > 1) {
                    // <figcaption> content
                    item.title = figureEl.children[1].innerHTML;
                }

                if (linkEl.children.length > 0) {
                    // <img> thumbnail element, retrieving thumbnail url
                    item.msrc = linkEl.children[0].getAttribute('src');
                }

                item.el = figureEl; // save link to element for getThumbBoundsFn
                items.push(item);
            }

            return items;
        };

        // find nearest parent element
        var closest = function closest(el, fn) {
            return el && (fn(el) ? el : closest(el.parentNode, fn));
        };

        // triggers when user clicks on thumbnail
        var onThumbnailsClick = function (e) {
            e = e || window.event;
            e.preventDefault ? e.preventDefault() : e.returnValue = false;

            var eTarget = e.target || e.srcElement;

            // find root element of slide
            var clickedListItem = closest(eTarget, function (el) {
                return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');
            });

            if (!clickedListItem) {
                return;
            }

            // find index of clicked item by looping through all child nodes
            // alternatively, you may define index via data- attribute
            var clickedGallery = clickedListItem.parentNode,
                childNodes = clickedListItem.parentNode.childNodes,
                numChildNodes = childNodes.length,
                nodeIndex = 0,
                index;

            for (var i = 0; i < numChildNodes; i++) {
                if (childNodes[i].nodeType !== 1) {
                    continue;
                }

                if (childNodes[i] === clickedListItem) {
                    index = nodeIndex;
                    break;
                }
                nodeIndex++;
            }



            if (index >= 0) {
                // open PhotoSwipe if valid index found
                openPhotoSwipe(index, clickedGallery);
            }
            return false;
        };

        // parse picture index and gallery index from URL (#&pid=1&gid=2)
        var photoswipeParseHash = function () {
            var hash = window.location.hash.substring(1),
                params = {};

            if (hash.length < 5) {
                return params;
            }

            var vars = hash.split('&');
            for (var i = 0; i < vars.length; i++) {
                if (!vars[i]) {
                    continue;
                }
                var pair = vars[i].split('=');
                if (pair.length < 2) {
                    continue;
                }
                params[pair[0]] = pair[1];
            }

            if (params.gid) {
                params.gid = parseInt(params.gid, 10);
            }

            return params;
        };

        var openPhotoSwipe = function (index, galleryElement, disableAnimation, fromURL) {
            var pswpElement = document.querySelectorAll('.pswp')[0],
                gallery,
                options,
                items;

            items = parseThumbnailElements(galleryElement);

            // define options (if needed)
            options = {

                // define gallery index (for URL)
                galleryUID: galleryElement.getAttribute('data-pswp-uid'),

                getThumbBoundsFn: function (index) {
                    // See Options -> getThumbBoundsFn section of documentation for more info
                    var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail
                        pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
                        rect = thumbnail.getBoundingClientRect();

                    return {
                        x: rect.left,
                        y: rect.top + pageYScroll,
                        w: rect.width
                    };
                }

            };

            // PhotoSwipe opened from URL
            if (fromURL) {
                if (options.galleryPIDs) {
                    // parse real index when custom PIDs are used
                    // http://photoswipe.com/documentation/faq.html#custom-pid-in-url
                    for (var j = 0; j < items.length; j++) {
                        if (items[j].pid == index) {
                            options.index = j;
                            break;
                        }
                    }
                } else {
                    // in URL indexes start from 1
                    options.index = parseInt(index, 10) - 1;
                }
            } else {
                options.index = parseInt(index, 10);
            }

            // exit if index not found
            if (isNaN(options.index)) {
                return;
            }

            if (disableAnimation) {
                options.showAnimationDuration = 0;
            }

            // Pass data to PhotoSwipe and initialize it
            gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
            gallery.init();
        };

        // loop through all gallery elements and bind events
        var galleryElements = document.querySelectorAll(gallerySelector);

        for (var i = 0, l = galleryElements.length; i < l; i++) {
            galleryElements[i].setAttribute('data-pswp-uid', i + 1);
            galleryElements[i].onclick = onThumbnailsClick;
        }

        // Parse URL and open gallery if it contains #&pid=3&gid=1
        var hashData = photoswipeParseHash();
        if (hashData.pid && hashData.gid) {
            openPhotoSwipe(hashData.pid, galleryElements[hashData.gid - 1], true, true);
        }
    };

    // execute above function
    initPhotoSwipeFromDOM('.photoswipe');
}

// 안정적인 포토스와이프 실행을 위해 img 로드 완료 상태를 체크
function easeImagesLoadcheck() {

    if (typeof requestAnimationFrame != 'function') {

        // requestAnimationFrame 을 지원하지 않을 때

        $(window).load(function () {

            photoswipe();

        });

    } else {

        // requestAnimationFrame 을 지원할 때

        var contImg = document.querySelectorAll('img');
        var contImgLen = contImg.length;

        function contImgCompleted() {

            var complete = 0;

            for (var i = 0; i < contImgLen; i++) {

                if (contImg[i].complete) {

                    complete++;
                } else {

                    continue;
                }
            }

            if (complete == contImgLen) {

                photoswipe();

                return cancelAnimationFrame(contImgCompleted);
            }

            return requestAnimationFrame(contImgCompleted);
        };

        contImgCompleted();
    }
}





// 레이어 팝업
function openLayer(selector) {

    var layer = document.querySelector(selector);
    var layerHead = layer.querySelector('.layer_head');
    var layerBody = layer.querySelector('.layer_body');

    // 알맞은 여백만큼 수기 추가
    var cnt = 150;

    function editBodyHeight() {

        // 초기화 후 계산되어야 한다
        layerBody.style.height = 'auto';

        var layerHeight = layer.clientHeight;
        var layerHeadHeight = layerHead.clientHeight;

        // 레이어 높이가 화면을 넘어가면
        if (layerHeight - cnt < document.querySelector('.layer_wrap').clientHeight) {

            layerBody.style.height = (layerHeight - layerHeadHeight - cnt) + 'px';
        }

        return 1;
    };

    $(layer).fadeIn(300, 'easeOutCubic');

    $(document).on('click', '#epeopleLayerClsoe', function (event) {

        event.preventDefault();

        $(layer).fadeOut(300, 'easeOutCubic');

        return 1;
    });

    $(selector).find('.black').on('click', function (event) {

        $(layer).fadeOut(300, 'easeOutCubic');

        return 1;
    });

    $(window).resize(function () {

        editBodyHeight();
    });

    if (typeof requestAnimationFrame != 'function') {

        // requestAnimationFrame 을 지원하지 않을 때

        $(window).load(function () {

            editBodyHeight();

            // 스크롤 추가
            $('.layer_body').mCustomScrollbar();
        });

    } else {

        // requestAnimationFrame 을 지원할 때

        var contImg = document.querySelectorAll(selector + ' img');

        var contImgLen = contImg.length;

        (function contImgCompleted() {

            var complete = 0;

            for (var i = 0; i < contImgLen; i++) {

                if (contImg[i].complete) {

                    complete++;
                } else {

                    continue;
                }
            }

            if (complete == contImgLen) {

                editBodyHeight();

                // 스크롤 추가
                $('.layer_body').mCustomScrollbar();

                return cancelAnimationFrame(contImgCompleted);
            }

            return requestAnimationFrame(contImgCompleted);
        })();
    }

    return 1;
};

// 인수로 대상 위치를 받고, Ajax 로 문서의 내용을 받아서 콜백을 실행한다
function runParse(url, element, callBack, _this) {

    removeLayer();

    if (_this != 'parent') {
        window.setParentThis = _this;
    }

    var str = '';

    var getHtml = $.get(url);
    var id = $(window.setParentThis).attr('href');

    getHtml.done(function (res) {

        var str = '\n' +
            '\n<div id="' + id.substr(1) + '" class="huyang_layer">' +
            '\n\t<!-- 레이어팝업 내용이 달라붙는 태그 -->' +
            '\n\t<div class="black"></div>' +
            '\n\t<div class="layer_wrap">\n' + res + '</div>' +
            '\n</div>';

        // 현재 클릭한 대상 레이어가 생성되어 있지 않을 때

        $(window.setParentThis).after(str);

        if (_this == 'parent') {

            window.setParentThis = undefined;
        }

        if (callBack) {

            if ($.isArray(callBack)) {

                for (var i = 0; i < callBack.length; i++) {

                    callBack[i](id);
                }
            } else {

                callBack(id);
            }
        }
    });

    return 1;
}

function activePgSlideShow(id) {

    $(id + ' .pgwSlideshow').pgwSlideshow({
        alt: false,
        description: true
    });

    // 이미지 로드체크 후 run photoswipe
    easeImagesLoadcheck();
}


$(function () {

    var btnSwitch = $('.btn_switch');

    btnSwitch.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (t.hasClass('in_active')) {

            t.removeClass('in_active');
        } else {

            t.addClass('in_active');
        }

    });

})

//파일첨부
$(document).ready(function () {
    var fileTarget = $('.filebox .upload-hidden');

    fileTarget.on('change', function () {

        if (window.FileReader) {
            var filename = $(this)[0].files[0].name;
        } else {
            var filename = $(this).val().split('/').pop().split('\\').pop();
        }

        $(this).siblings('.file_name').text(filename);
    });
});


/**********************************************************
 *
 * 통합검색 스크립트
 *
 ***********************************************************/
function rmGeneralSearch() {

    if ($(window).width() <= 1000 && $('#categoryCloseParent').length) {

        $('#categoryCloseParent').removeAttr('style');
        $('#mo_categoryCloseAction').removeAttr('style');
        $('.general_search_body .back').removeAttr('style');
    }
}

function generalSearch() {


    var searchContentParent = $('#searchContentParent');

    if (!searchContentParent.length) {

        return false;
    }

    var searchContentButton = searchContentParent.find('.item_title a');

    searchContentButton.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (t.hasClass('in_action')) {

            t.removeClass('in_action')
                .parent().next().stop(0, 1).slideUp(300, 'easeOutCubic');
        } else {

            t.addClass('in_action')
                .parent().next().stop(0, 1).slideDown(300, 'easeOutCubic');
        }
    });

    $('#mo_categoryCloseAction').on('click', function (event) {

        event.preventDefault();

        $(this).hide();

        $('.general_search_body .back').stop(0, 1).fadeIn(700, 'easeOutCubic');

        $('#categoryCloseParent').stop(0, 1).animate({
            'left': 0
        }, 700, 'easeOutCubic');

    });

    $('.general_search_body .back').on('click', function (event) {

        $('#mo_categoryCloseAction').stop(0, 1).delay(300).fadeIn(500);

        $('.general_search_body .back').stop(0, 1).fadeOut(700, 'easeOutCubic');

        $('#categoryCloseParent').stop(0, 1).animate({
            'left': '-100%'
        }, 700, 'easeOutCubic');

    });
}


function filterCategory() {
    var categoryCloseParent = $('#categoryCloseParent');

    if (!categoryCloseParent) {

        return false;
    }


    var categoryTabButton = categoryCloseParent.find('.tab_title');

    var categoryItemTitle = categoryCloseParent.find('.item_title a');

    var inActiveSldeItem = categoryCloseParent.find('.item_pt.slide');

    for (var j = 0; j < inActiveSldeItem.length; j++) {

        if (inActiveSldeItem.eq(j).find('.in_active').length) {

            inActiveSldeItem.eq(j).show();
        }
    }

    categoryItemTitle.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (t.hasClass('in_active')) {

            t.removeClass('in_active');

            t.parent().next().filter('.slide').stop(0, 1).slideUp(300, 'easeOutCubic');

        } else {

            t.addClass('in_active');

            t.parent().next().filter('.slide').stop(0, 1).slideDown(300, 'easeOutCubic');
        }

    });

    var returnThis = categoryTabButton;

    function categoryTabItem(idx) {

        var categoryTabItem = categoryCloseParent.find('.tab_body:eq(' + idx + ') .body_item');
        var categoryTabItemLen = categoryTabItem.length;

        //console.log(categoryTabItemLen);

        for (var i = 0; i < categoryTabItemLen; i++) {

            categoryTabItem.eq(i).css({

                top: -10,
                opacity: 0

            }).stop(0, 1).delay(50 * (i * 0.8)).animate({
                top: 0,
                opacity: 1
            }, 150, 'easeOutCubic');

        }

        return 1;
    }

    categoryTabButton.on('click', function (event) {

        event.preventDefault();

        var t = $(this);
        var idx = categoryTabButton.index(t);

        if (!t.hasClass('in_action')) {

            if (returnThis) {

                returnThis.removeClass('in_action').next().hide();
            }

            t.addClass('in_action').next().show();
        }

        categoryTabItem(idx);

        returnThis = t;
    });

    var saveParentWidth = categoryCloseParent.outerWidth();

    $('#categoryCloseAction').on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (t.hasClass('in_action')) {

            t.removeClass('in_action');

            categoryCloseParent.css('display', 'block')
                .stop(0, 1).animate({

                    marginLeft: 0,
                    opacity: 1

                }, 300, 'easeOutCubic')

                .next().stop(0, 1).animate({
                    paddingLeft: 40
                }, 300, 'easeOutCubic');

            t.parent().stop(0, 1).animate({
                left: 240
            }, 300, 'easeOutCubic');

        } else {

            t.addClass('in_action');

            categoryCloseParent
                .stop(0, 1).animate({

                        marginLeft: saveParentWidth * -1,
                        opacity: 0

                    }, 300, 'easeOutCubic',
                    function () {

                        $(this).css('display', 'none');

                    })

                .next().stop(0, 1).animate({
                    paddingLeft: 0
                }, 300, 'easeOutCubic');

            t.parent().stop(0, 1).animate({
                left: -60
            }, 300, 'easeOutCubic');
        }
    });


    var rtime = 0;
    var rw = document.body.clientWidth;
    $(window).resize(function () {

        if (rw != document.body.clientWidth) {

            if (rw <= 1000) {

                clearTimeout(rtime);

                rtime = setTimeout(function () {

                    $('.category_button').removeAttr('style');
                    $('#categoryCloseParent').removeAttr('style');
                    $('#searchContentParent').removeAttr('style');
                    $('#categoryCloseAction').removeClass('in_action');

                }, 100);
            }

            rw = document.body.clientWidth;
        }
    });

}


function calendarData(date) {

    if (date) {

        date = date.split('-');
        date[1] = date[1] - 1;
        date = new Date(date[0], date[1], date[2]);
    } else {

        var date = new Date();
    }
    var currentYear = date.getFullYear();
    //년도를 구함

    var currentMonth = date.getMonth() + 1;
    //연을 구함. 월은 0부터 시작하므로 +1, 12월은 11을 출력

    var currentDate = date.getDate();
    //오늘 일자.

    date.setDate(1);

    var currentDay = date.getDay();
    //이번달 1일의 요일은 출력. 0은 일요일 6은 토요일

    var lastDate = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    if ((currentYear % 4 === 0 && currentYear % 100 !== 0) || currentYear % 400 === 0) {

        lastDate[1] = 29;
    }
    //각 달의 마지막 일을 계산, 윤년의 경우 년도가 4의 배수이고 100의 배수가 아닐 때 혹은 400의 배수일 때 2월달이 29일 임.

    var currentLastDate = lastDate[currentMonth - 1];
    var week = Math.ceil((currentDay + currentLastDate) / 7);
    //총 몇 주인지 구함.

    if (currentMonth != 1) {

        var prevDate = currentYear + '-' + (currentMonth - 1) + '-' + currentDate;
    } else {

        var prevDate = (currentYear - 1) + '-' + 12 + '-' + currentDate;
    }
    //만약 이번달이 1월이라면 1년 전 12월로 출력.

    if (currentMonth != 12) {

        var nextDate = currentYear + '-' + (currentMonth + 1) + '-' + currentDate;
    } else {

        var nextDate = (currentYear + 1) + '-' + 1 + '-' + currentDate;
    }
    //만약 이번달이 12월이라면 1년 후 1월로 출력.


    if (currentMonth < 10) {

        var currentMonth = '0' + currentMonth;
    }
    //10월 이하라면 앞에 0을 붙여준다.

    return {
        prev: prevDate,
        next: nextDate,
        y: currentYear,
        m: currentMonth,
        d: currentDay,
        last: currentLastDate,
        week: week,
    };
}

function calendarString(date) {

    var data = calendarData(date);

    var calendar = '';

    var dateString = new Array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
    var dateStringKor = new Array('일', '월', '화', '수', '목', '금', '토');

    calendar += '<div class="layer_cal_head">';
    calendar += '   <a href="#" class="prev" onclick="picker(\'' + data.prev + '\', \'prev\'); return false;"><span class="hide">이전달</span></a>';
    calendar += '   <b>' + data.y + '. ' + data.m + '</b>';
    calendar += '   <a href="#" class="next" onclick="picker(\'' + data.next + '\', \'next\'); return false;"><span class="hide">다음달</span></a>';
    calendar += '</div>';

    calendar += '<table border="0" cellspacing="0" cellpadding="0">';
    calendar += '   <caption>' + data.y + '년 ' + data.m + '월 달력</caption>';
    calendar += '   <thead>';
    calendar += '        <tr>';
    calendar += '          <th class="sun" scope="row">일</th>';
    calendar += '          <th class="mon" scope="row">월</th>';
    calendar += '          <th class="tue" scope="row">화</th>';
    calendar += '          <th class="wed" scope="row">수</th>';
    calendar += '          <th class="thu" scope="row">목</th>';
    calendar += '          <th class="fri" scope="row">금</th>';
    calendar += '          <th class="sat" scope="row">토</th>';
    calendar += '        </tr>';
    calendar += '   </thead>';
    calendar += '<tbody>';

    var dateNum = 1 - data.d;

    var endCnt = 0;

    for (var i = 0; i < data.week; i++) {

        calendar += '<tr>';

        for (var j = 0; j < 7; j++, dateNum++) {

            if (dateNum < 1) {
                calendar += '<td class="not_day"><a href="#">' + (Number(calendarData(data.prev).last) + Number(dateNum)) + '</a></td>';
                continue;
            }

            if (dateNum > data.last) {
                calendar += '<td class="not_day"><a href="#">' + (((data.last + j) - data.last + 1) - (endCnt + 1)) + '</a></td>';
                continue;
            }

            calendar += '<td class="' + dateString[j] + '"><a data-date="' + data.y + '.' + data.m + '.' + (dateNum < 10 ? '0' + dateNum : dateNum) + '(' + dateStringKor[j] + ')" href="#">' + dateNum + '</a></td>';

            endCnt = j;

        }
        calendar += '</tr>';
    }

    calendar += '</tbody>';
    calendar += '</table>';

    return calendar;
}

function picker(date, dir, write) {

    var calNum = 0

    var str = '';

    while (calNum < 2) {

        str += '<div class="layer_calender ' + (calNum ? 'cal_right' : 'cal_left') + '">' + function () {

            var str = '';

            if (calNum) {

                str = calendarString(function () {

                    var str = calendarData(date).next;

                    if (dir == 'next') {

                        str = date;
                    }

                    return str;
                }());
            } else {

                str = calendarString(function () {

                    var str = date;

                    if (dir == 'next') {

                        str = calendarData(date).prev;;
                    }

                    return str;
                }());
            }

            return str;

        }() + '</div>';

        calNum++;
    }

    if (write) {

        document.write(str);
    } else {

        $('.calendar_wrap').html(str);
    }

    return 1;
}

function addPicker(_this, write) {

    if (!$('.picker_layer').length) {

        var str = '<div class="picker_layer" style="display:none"><a class="layer_close" onclick="$(\'.picker_layer\').fadeOut(300, \'easeOutCubic\'); return false;" href="#"><span class="sprity-cal sprity-cal-cal_picker_close"></span><span class="hide">달력 닫기</span></a><div class="scl"><div class="scl_wrap"><div class="calendar_wrap"></div></div></div></div>';

        $('body').append(str + '<div class="picker_back" style="z-index:101;position:fixed;top:0;left:0;width:100%;height:100%"></div>');
    }

    picker(0, 0, write);

    if (_this) {

        var t = $(_this);

        $('.picker_layer').css({
            top: t.offset().top + t.outerHeight(),
            left: t.offset().left
        }).fadeIn(300, 'easeOutCubic');

        $('.picker_back').fadeIn(300, 'easeOutCubic');
    }

    var today = new Date();

    var dateSTring = '';

    var currentDate = today.getFullYear() + '.' + (today.getMonth() + 1) + '.' + today.getDate();

    var checkerArr;

    $('.picker_back').on('click', function (event) {

        event.preventDefault();

        $('.picker_back').fadeOut(300, 'easeOutCubic');

        $('.picker_layer').fadeOut(300, 'easeOutCubic');

    });

    $(document).off('.clickPicker').on('click.clickPicker', '.picker_layer td a', function (event) {

        event.preventDefault();

        var t = $(this);

        var checker = $('.picker_layer td a');
        var idx = checker.index(t);

        var onDate = t.data('date');


        if (!onDate) {

            return alert('선택 가능 일자가 아닙니다.');
        }

        var date = new Date();

        var getDate = onDate.substr(0, onDate.lastIndexOf('('));

        var year = Number(getDate.split('.')[0]);
        var month = Number(getDate.split('.')[1]);
        var day = Number(getDate.split('.')[2]);

        date.setFullYear(year, month - 1, day);

        if (!t.hasClass('origin') && onDate) {

            if (date.getTime() < today.getTime()) {

                return alert('금일(' + currentDate + ') 포함, 이후로 선택 가능합니다.');
            }

            if (!t.parent().hasClass('not_day')) {

                if (checkerArr && checkerArr[1]) {

                    checker.eq(checkerArr[1]).removeClass('origin');
                    checker.removeClass('child');
                }

                t.addClass('origin');
            }
        } else {

            t.removeClass('origin');
            checker.removeClass('child');

            $('#cal_picker').val('');

            if (Number($('#cal_picker').prev().data('hidden'))) {

                $('#cal_picker').prev().show()
            }
        }

        var checkerLen = checker.length

        checkerArr = [];

        for (var i = 0; i < checkerLen; i++) {

            if (checker.eq(i).hasClass('origin')) {

                checkerArr.push(i);
            }
        }

        if (checkerArr.length == 2) {

            for (var j = 0; j < checkerLen; j++) {

                if (j == checkerArr[1]) {

                    break;
                }

                if (j > checkerArr[0]) {

                    if (checker.eq(j).parent().hasClass('not_day')) {

                        continue;
                    }

                    checker.eq(j).addClass('child');
                } else {

                    continue;
                }
            }

            if (Number($('#cal_picker').prev().data('hidden'))) {

                $('#cal_picker').prev().hide();
            }

            $('#cal_picker').val(checker.eq(checkerArr[0]).data('date').substr(2) + ' - ' + checker.eq(checkerArr[1]).data('date').substr(2));
        }
    });

    return false;
}

function rmPicker() {

    if ($('.picker_layer').length) {

        if (!$('#cateCalendar').length) {

            $('.picker_layer').hide();
        }
    }
}


function resDetail() {
    //예약목록 버튼 클릭시 상세 정보 show/hide
    var resBtn = $(".res_List .resL_right>ul>li>a");

    resBtn.on("click", function () {
        if ($(this).closest(".resL_li").next(".resDetail").is(":hidden")) {
            $(this).closest(".resL_li").next(".resDetail").slideDown(300, 'easeOutCubic');
        } else {
            $(this).closest(".resL_li").next(".resDetail").slideUp(300, 'easeOutCubic');
        }
        return false;
    });
}

function resPossible() {
    var resBtn = $(".resGo_btn");

    resBtn.on("click", function () {
        if ($(this).closest("div").next(".resPosBox").is(":hidden")) {
            $(this).closest("div").next(".resPosBox").slideDown(300, 'easeOutCubic');
        } else {
            $(this).closest("div").next(".resPosBox").slideUp(300, 'easeOutCubic');
        }
        return false;
    });
}

function agrCon() {
    //약관내용보기
    var agrBtn = $(".agrBtn");
    var closeBtn = $(".L_closeBtn");

    agrBtn.on("click", function () {
        if ($(this).next(".agr_cont").is(":hidden")) {
            $(this).addClass("on");
            $(this).next(".agr_cont").slideDown(300, 'easeOutCubic');
        } else {
            $(this).removeClass("on");
            $(this).next(".agr_cont").slideUp(300, 'easeOutCubic');
        }
        return false;
    });

    closeBtn.on("click", function () {
        $(this).closest(".agr_cont").slideUp(300, 'easeOutCubic');
        return false;
    });

}

function tableResponsed() {

    // 일반 표 반응형

    var parent = $('.res_bbs_wrap');
    var parentLen = parent.length;

    if (!parentLen) {

        return false;
    }

    for (var z = 0; z < parentLen; z++) {

        var theadTh = parent.eq(z).find('.tbl thead th, .tbl_board thead th');
        var theadThLen = theadTh.length;

        var tbodyTr = parent.eq(z).find('.tbl tbody tr, .tbl_board tbody tr');
        var tbodyTrLen = tbodyTr.length;

        var tiArr = [];

        var str = '';

        var useAllCheck = false;
        var useAllCheckStr = '';

        for (var i = 0; i < theadThLen; i++) {

            tiArr.push(theadTh.eq(i).html());
        }

        for (var j = 0; j < tbodyTrLen; j++) {

            var childTd = tbodyTr.eq(j).children();
            var childTdLen = childTd.length;

            var strItem = '';

            // tr
            strItem += '' +
                '\n<li class="item item_' + j + '">';

            for (var k = 0; k < childTdLen; k++) {

                // th, td

                // 전체목록 선택 삭제 용도의 선택 상자를 사용하는지
                var useCheck = childTd.eq(k).find('[type=checkbox]').length;

                if (useCheck) {

                    // 선택 상자를 사용 하는것이 판단되면 true 일때 만
                    // 화면에 전체선택상자 추가 유무를 판단하기 위함
                    useAllCheck = true;
                    // 전체 선택에 사용되는 html만 저장
                    useAllCheckStr = tiArr[k];
                }

                var strTitle = useCheck ? '' : '<b>' + tiArr[k] + '</b>';

                var sumStrings = '\n<div class="child_' + k + '">' + strTitle + (useCheck ? '<div class="use_list_checkbox">' + childTd.eq(k).html() + '</div>' : childTd.eq(k).html()) + '</div>';

                strItem += sumStrings;
            }

            strItem += '' +
                '\n</li>';

            // tr 한개에 해당하는 목록 저장
            str += strItem;
        }

        parent.eq(z).append('\n<div class="tbl_responsed">' + (useAllCheck ? '<div class="use_all_checkbox"><label for="checkAll">' + useAllCheckStr + ' 전체 선택</label></div>' : '') + '<ul>' + str + '</ul></div>');
    }

    // 전체 선택에 대한 요소가 있으면 mo/pc 간 선택 상태를 동기화 시키는 스크립트를 부른다.
    return useAllCheck ? syncCheckbox() : 1;
}

function resSch_List(id) {
    var item = $(id);

    $(".none").stop(0, 1).slideUp(300, 'easeOutCubic');

    item.slideDown(300, 'easeOutCubic', function () {
        var box_position = item.position();
        $('html, body').stop(0, 1).animate({
            scrollTop: box_position.top - 120
        }, 1000, 'easeOutExpo');
    });

    return false;
}

function placeholderLabel() {

    var inputListLabel = $('.input label');
    var inputListLabelLen = inputListLabel.length;

    // 비우기
    for (i = 0; i < inputListLabelLen; i++) {

        $(inputListLabel[i]).next().val('');
    }

    inputListLabel.on('click', function (event) {

        var t = $(this);

        var t_input = inputListLabel.next();

        t.hide();
    });

    inputListLabel.next().on('focusin focusout', function (event) {

        var t = $(this);

        if (t.attr('id') == 'cal_picker') {

            //console.log(t.attr('id'));
        }

        var t_label = t.prev();

        if (event.handleObj.type == 'focusin') {

            t_label.hide();
        }

        if (event.handleObj.type == 'focusout') {

            if (!t.val().length) {

                t_label.show();
            }
        }
    });

    return 1;
}


function fasterAptRes() {

    var parent_left = $('.fast_list .list_left');


    function addEvent() {

        parent_left.find('ul>li>a').on('click.off', function (event) {

            event.preventDefault();

            var t = $(this);

            var idx = parent_left.find('ul>li>a').index(t);

            $('.fast_list .list_right').remove();

            parent_left.find('ul>li>a').removeClass('in_active');

            t.after(window.FasterAptResString).addClass('in_active');

            var tr = $('.fast_list .list_right tbody tr');
            var trLen = tr.length;

            for (var i = 0; i < trLen; i++) {

                if (i != idx) {

                    tr.eq(i).remove();
                }
            }

        });

        return 1;
    }

    if (!window.FasterAptResString) {

        window.FasterAptResString = '<div class="list_right">' + $('.fast_list .list_right').html() + '</div>';

        $('.fast_list .list_right').remove();

        addEvent();
    }

    if (document.body.clientWidth >= 640) {

        $('.fast_list .list_right').remove();

        parent_left.after(window.FasterAptResString);

        parent_left.find('ul>li>a').off('.off');

        $('.fast_list .list_right').mCustomScrollbar({
            axis: "x" // horizontal scrollbar
        });
    } else {

        addEvent();

        $('.fast_list .list_right').remove();
    }
}

function showhide(_this, i) {

    if ($(i).css('display') == 'none') {

        $(i).slideDown(300, 'easeOutCubic');
    } else {

        $(i).slideUp(300, 'easeOutCubic');
    }


}

function linkTab() {
    var tab = $(".linkTab");
    var tabUl = tab.find(">ul");
    var tabLi = tab.find(">ul>li");
    var text = "";

    tabLi.each(function () {
        if ($(this).find("a").hasClass("on")) {
            text = $(this).find(">a>span").text();
        }
    });

    /*$(".tab-col-3 li:nth-child(3n+1) a").css({borderLeft:"1px solid #d6d6e0"});
     $(".tab-col-4 li:nth-child(4n+1) a").css({borderLeft:"1px solid #d6d6e0"});
     $(".tab-col-5 li:nth-child(5n+1) a").css({borderLeft:"1px solid #d6d6e0"});
     $(".tab-col-6 li:nth-child(6n+1) a").css({borderLeft:"1px solid #d6d6e0"});*/

    tab.prepend("<button type='button' class='mlinkTab_btn'>" + text + "</button>");

    $(document).on("click", ".mlinkTab_btn", function () {
        if ($(this).next("ul").is(":hidden")) {
            $(this).addClass("on");
            $(this).next("ul").stop().slideDown("fast");
        } else {
            $(this).removeClass("on");
            $(this).next("ul").stop().slideUp("fast");
        }
    });
}

function aT_link() {
    /* 회원가입_약관_상단탭 */

    var areaT = $(".area_wrap .areaTab");
    var aT_btn = areaT.find(">li>a");
    var aT_btnF = areaT.find(">li:first>a");
    var aT_Con = areaT.find(">li>div");
    var aT_ConF = areaT.find(">li:first>div");
    var tabH = aT_btnF.outerHeight(true) + aT_ConF.outerHeight(true);



    aT_btnF.addClass("on");
    aT_ConF.show();
    areaT.height(tabH);

    aT_btn.on("click", function () {
        aT_btn.removeClass("on");
        aT_Con.hide();

        var tabH = $(this).outerHeight(true) + $(this).next().outerHeight(true);

        $(this).addClass("on");
        $(this).next().show();
        areaT.height(tabH);

        return false;
    });

    $(window).resize(function () {
        var aT_btnOn = areaT.find(">li>a.on");
        var tabH = aT_btnOn.outerHeight(true) + aT_btnOn.next().outerHeight(true);
        areaT.height(tabH);
    });
}

function snsPop() {
    $(".util_sns").on("click", function () {
        if ($(this).next(".sns_group").is(":hidden")) {
            $(this).next(".sns_group").slideDown(300, 'easeOutCubic');
        } else {
            $(this).next(".sns_group").slideUp(300, 'easeOutCubic');
        }
        return false;
    });
    $(document).on("click", function (e) {
        if (!$(e.target).is('.sns_group, .sns_group strong, .sns_group ul, .sns_group ul li, .sns_group ul li a')) {
            $(".sns_group").slideUp(300, 'easeOutCubic');
        }
    });

    $(".snsClose").on("click", function () {
        $(this).parents(".sns_group").slideUp(300, 'easeOutCubic');
    });
}


// jquery ui 달력 한글
$.datepicker.setDefaults({
    dateFormat: 'yy-mm-dd',
    prevText: '이전 달',
    nextText: '다음 달',
    monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
    monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
    dayNames: ['일', '월', '화', '수', '목', '금', '토'],
    dayNamesShort: ['일', '월', '화', '수', '목', '금', '토'],
    dayNamesMin: ['일', '월', '화', '수', '목', '금', '토'],
    showMonthAfterYear: true,
    yearSuffix: '년',
    changeYear: true,
    changeMonth: true
});

$(function () {
    $(".datepicker").datepicker({
        beforeShow: function (input, inst) {
            setTimeout(function () {
                var offsets = $(".datepicker-wrap").offset();
                //var top = offsets.top + 25;
                inst.dpDiv.css({
                    //top: top,
                    left: offsets.left,
                });
                inst.dpDiv.outerWidth($(input).outerWidth());
            });
        }
    });
});

$(window).on('resize orientationchange', function (e) {
    if ($.datepicker._datepickerShowing) {
        var datepicker = $.datepicker._curInst;
        dpInput = datepicker.input;
        dpElem = datepicker.dpDiv;
        dpElem.position({
            my: 'left top',
            of: dpInput,
            at: 'left bottom'
        });
    }
});

//이미지 자동 위치 조정

function images() {

    var preview = $('.autosize');

    //console.log(preview.length);

    if (!preview) {

        return false;
    }

    var previewLen = preview.length;

    $(preview).attr('style', 'width:100%;height:auto;max-height:none;max-width:none;');

    function imgLoadProcess() {

        var cnt = 0;

        for (var i = 0; i < previewLen; i++) {

            var ph = $(preview[i]).parent().height();
            var pw = $(preview[i]).parent().width();

            var cssArry = {};

            if (preview[i].complete) {

                cnt++;

                if (preview[i].clientHeight > ph) {

                    cssArry.width = 'auto';
                    cssArry.height = '100%';
                    cssArry.marginTop = '0';
                }

                if (preview[i].clientHeight < ph) {

                    cssArry.width = '100%';
                    cssArry.height = 'auto';
                    cssArry.marginTop = (ph - preview[i].clientHeight) / 2;
                }

                $(preview[i]).css(cssArry);

            } else {

                continue;
            }

        }

        if (typeof cancelAnimationFrame == 'function' && cnt == previewLen) {

            return window.cancelAnimationFrame(insertAnimateFrame);
        }

        window.IMGLOADPROCESS = true;

        return 1;
    }

    if (window.IMGLOADPROCESS) {

        imgLoadProcess();
    } else {

        if (typeof requestAnimationFrame != 'function') {

            $(window).load(function () {

                imgLoadProcess();
            });
        } else {

            function insertAnimateFrame() {

                imgLoadProcess();

                return window.requestAnimationFrame(insertAnimateFrame);
            }

            window.requestAnimationFrame(insertAnimateFrame);

        }
    }
};

function fileDel() {
	//의미없는 code 삭제
}

// 검색 : 예약일 안내
function searchInfoScheduls() {

    var btn = $('.schedule_info');

    if (!btn.length) {

        return false;
    }

    var obj = $('.info_layer');

    var prevThis = btn;

    btn.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (t.hasClass('ov')) {

            t.removeClass('ov');
        } else {

            t.addClass('ov');
        }

        prevThis = t;

    });

    obj.on('mouseleave', function () {

        prevThis.removeClass('ov');
    });

    return 1;
}

function fakeSelectBox() {

    var parent = $('#fakeSelectBox');
    var btn = parent.find('.select_label a');
    var obj = parent.find('.select_option');
    var item = obj.find('li a');

    var hiddenSelect = $('#hiddenSelect');

    btn.on('click', function (event) {

        event.preventDefault();

        if (obj.css('display') == 'none') {

            obj.stop(1, 1).show();
        } else {

            obj.stop(1, 1).hide();
        }
    });

    parent.on('mouseleave', function () {

        if (obj.css('display') == 'block') {

            obj.stop(1, 1).hide();
        }

    });

    item.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        var idx = item.index(t);

        btn.text(t.text());

        hiddenSelect.children().removeAttr('checked').eq(idx).attr('checked', 1);

        obj.stop(1, 1).hide();
    });

    return 1;
}

function sitemap() { //사이트맵(전체메뉴)
    var sm_btn = $(".sitemap_btn");
    var sm = $("#siteMap");
    var speed = 300;
    var close = $(".sitemap_close");
    var dep2btn = $(".sitemap_list>li>ul>li>a");
    var dep3 = $(".sitemap_list>li>ul>li>ul");
    var dep3btn = $(".sitemap_list>li>ul>li>ul>li>a");
    // var winW = $(window).outerWidth();

    sm_btn.on("click", function () {
        if (sm.is(":hidden")) {
            sm.stop(0, 1).slideDown(speed, 'easeOutCubic');
        } else {
            sm.stop(0, 1).slideUp(speed, 'easeOutCubic');
        }
    });

    close.on("click", function () {
        sm.stop(0, 1).slideUp(speed, 'easeOutCubic');
    });

    dep3.on("mouseenter focusin", function () {
        $(this).prev("a").addClass("ov");
    });
    dep3.on("mouseleave focusout", function () {
        $(this).prev("a").removeClass("ov");
    });
    dep3btn.on("mouseenter focusin", function () {
        $(this).closest("ul").prev("a").addClass("ov");
    });


    dep2btn.on("click", function () {
        if ($(window).width() < 724) {
            if ($(this).next().is(":hidden")) {

                dep2btn.removeClass("on");
                dep3.stop(0, 1).slideUp(speed, 'easeOutCubic');
                $(this).addClass("on");
                $(this).next().stop(0, 1).slideDown(speed, 'easeOutCubic');
            } else {

                $(this).removeClass("on");
                $(this).next().stop(0, 1).slideUp(speed, 'easeOutCubic');
            }
        }

        if ($(this).next().length) {

            return false;
        }
    });

    dep2btn.each(function () {

        if (!$(this).next().length) {

            $(this).addClass("empty");
        }
    });
}


function gnb(param, obj, btn, wrap, dur, meth) {
    var param = $(param);
    var btn = param.find(btn);
    var obj = param.find(obj);
    var wrap = $(wrap);
    var data = false;
    var elem;
    var targetHeight = new Array();
    var targetHeightResult;
    var heightResult = btn.outerHeight(true);
    var allBtn = $(".allm_btn");
    var allMenu = $("#allMenu");

    function gnb_height() {
        $.each(obj, function (idx) {
            targetHeight[idx] = $(this).parent().find(obj).outerHeight(true) + 80;
        });
    }

    function _open() {
        btn.parent().find(obj).removeAttr("style");
        btn.not(elem).removeClass("current").eq(elem).addClass("current");
        obj.not(elem).hide().css({
            display: "none",
            //opacity: 0
        });
        gnb_height();
        obj.eq(elem).show().stop().animate({
            display: "block",
            opacity: 1
        }, {
            duration: 300,
            easing: 'swing'
        });
        param.stop(true, false).animate({
            "height": targetHeight[elem]
        }, {
            duration: 300,
            easing: 'swing'
        });
        param.addClass("active");
        $("#header").addClass("on");
    }

    function _close() {
        btn.removeClass("current");
        /*obj.css({
            display: "none",
            opacity: 0
        });*/
        param.stop(true, false).animate({
            "height": heightResult
        }, {
            duration: 300,
            easing: 'swing'
        });
        param.removeClass("active");
        $("#header").removeClass("on");
    }
    btn.on('mouseover focusin', function () {
        elem = $(this).parent().index();
        _open();
        allMenu.slideUp();
        $("#header").removeClass("mask");
        $("#siteMap").css('display', 'none');

    });
    obj.find("a").last().on("focusout", function () {
        _close();
        btn.removeClass("current");
        param.removeClass("active");
        wrap.removeClass("on");
    });
    wrap.on("mouseleave", function () {
        _close();
    });
    allBtn.click(function () {
        _close();
    });
}


function blind_on() { //검정색 투명 블라인드 ON
    $(".blind").css({
        display: "block"
    });
    $(".blind").stop().animate({
        opacity: 0.5
    }, 500);
}

function blind_off() { //검정색 투명 블라인드 OFF
    $(".blind").stop().animate({
        opacity: 0
    }, 500, function () {
        $(".blind").css({
            display: "none"
        });
    });
}

function mMenu() { //모바일 메뉴
    var mBtn = $(".sitemap_btn");
    var menuBox = $("#mMenu");
    var menuBoxW = $("#mMenu").width();
    var mClose = $(".mMenu_close");
    var dep1btn = $(".mMenu_list>li>a");
    var dep2con = $(".mMenu_list>li>ul");
    var dep2btn = $(".mMenu_list>li>ul>li>a");
    var dep3con = $(".mMenu_list>li>ul>li>ul");
    var dep3btn = $(".mMenu_list>li>ul>li>ul>li>a");
    var speed = 300;

    dep2btn.each(function () {
        if ($(this).hasClass("on")) {
            $(this).closest("ul").show();
            $(this).closest("ul").prev("a").addClass("on");
        }
        if (!$(this).next().length) {
            $(this).addClass("empty");
        }
    });
    dep3btn.each(function () {
        if ($(this).hasClass("on")) {
            $(this).closest("ul").show();
            $(this).closest("ul").prev("a").addClass("on");
            $(this).closest("ul").parents("ul").show();
            $(this).closest("ul").parents("ul").prev("a").addClass("on");
        }
    });

    mBtn.on("click", function () {
        blind_on();
        menuBox.css({
            display: "block"
        }).animate({
            right: "0px"
        }, speed);
        //$("body").css({overflow: "hidden", position: "fixed", width: "100%", height: "100%"});
        $("body").addClass('on');

    });

    mClose.on("click", function () {
        blind_off();
        menuBox.animate({
            right: menuBoxW * -1
        }, speed, function () {
            menuBox.css({
                display: "none"
            });
        });
        $("body").css({
            overflow: "auto",
            position: "static",
            width: "auto",
            height: "auto"
        });
        $("body").removeClass('on');

        /*dep1btn.removeClass("on");
        dep2con.slideUp(speed);*/
    });

    $(function () { //블라인드 클릭시 블라인드 및 모바일 메뉴 닫기
        $(".blind").on("click", function () {
            blind_off();
            menuBox.animate({
                right: menuBoxW * -1
            }, speed, function () {
                menuBox.css({
                    display: "none"
                });
            });
            $("body").css({
                overflow: "auto",
                position: "static",
                width: "auto",
                height: "auto"
            });
            $("body").removeClass('on');
            /*dep1btn.removeClass("on");
            dep2con.slideUp(speed);*/
        });
    });

    dep1btn.on("click", function () {
        dep2con.slideUp(speed);
        dep1btn.removeClass("on");
        if ($(this).next("ul").is(":hidden")) {
            $(this).addClass("on").next("ul").slideDown(speed);
        } else {
            $(this).removeClass("on").next("ul").slideUp(speed);
        }
        return false;
    });
    dep2btn.on("click", function () {
        dep3con.slideUp(speed);
        dep2btn.removeClass("on");
        if ($(this).next("ul").is(":hidden")) {
            $(this).addClass("on").next("ul").slideDown(speed);
        } else {
            $(this).removeClass("on").next("ul").slideUp(speed);
        }
        if ($(this).next("ul").length) {
            return false;
        }
    });
}

function mySearchOpen() {

    var parent = $('.my_search_open');

    if (!parent) {

        return false;
    }

    var btn = parent.find('>a');
    var obj = parent.find('.category_tab');

    btn.on('click', function (event) {

        event.preventDefault();

        if (obj.css('display') == 'none') {

            obj.show();
        } else {

            obj.hide();
        }

    });

    return 1;

}

function bing() {

    var btn = $('.bing');

    btn.on('click', function (event) {

        event.preventDefault();

        $('#bing').toggle();

    });

    return 1;
}

function bodoThumbFlag() {

    var flag = $('.search_content .bodo_thumb .flag>a');

    flag.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        if (t.hasClass('ov')) {

            t.removeClass('ov');

            t.next().hide();
        } else {

            t.addClass('ov');

            t.next().show();
        }

        $('body').append('<div style="position:fixed;top:0;left:0;width:100%;height:100%;" id="outBodoThumbFlag"></div>');

    });

    $(document).on('mouseenter', '#outBodoThumbFlag', function (event) {

        event.preventDefault();

        flag.removeClass('ov')

        $(this).remove();

        $('.search_content .bodo_thumb .flag ul').hide();

    })



    return 1;
}

function gradeStar() {

    if (!$('.grade').length) {

        return false;
    }

    var gradeBar = $('.grade .grade_bar');
    var gradeStar = $('.grade .grade_star a');
    var gradeHidden = $('grade .grade_hidden');

    var gradeArr = [20, 40, 60, 80, 100];

    // data-grade 로 gradeArr 을
    gradeBar.css('width', gradeArr[gradeBar.data('grade') - 1] + '%');

    // hidden input value 에 입력
    gradeHidden.val(gradeArr[gradeBar.data('grade')]);

    if (!gradeStar.length) {
        // 쓰키에서는 a 링크 활용
        // 읽기 에서는 span 활용 으로 스기와 읽기 이벤트 부여 구분
        return false;
    }

    // 클릭 이벤트
    gradeStar.on('click', function (event) {

        event.preventDefault();

        var t = $(this);
        var idx = gradeStar.index(t);

        // idx 로 gradeArr 사용
        gradeBar.css('width', gradeArr[idx] + '%');

        // idx 를 hidden input value 에 입력
        gradeHidden.val(idx + 1);

    });

    return 1;
}

function foldItemMore() {

    var parent = $('.fold_list');

    if (!parent.length) {

        return false;
    }

    var btn = parent.find('.more');

    btn.on('click', function (event) {

        event.preventDefault();

        var t = $(this);

        var obj = t.parent().next();

        if (obj.css('display') == 'none') {

            t.parent().find('.more').addClass('close');
            obj.show();
        } else {

            t.parent().find('.more').removeClass('close');
            obj.hide();
        }

    });

    return this;
}

// 실행부
$(function () {

    foldItemMore();

    gradeStar();

    bodoThumbFlag();

    bing();

    $("#wrap").prepend("<div class='blind'></div>");
    $(".blind").css({
        display: "none",
        position: "fixed",
        left: 0,
        top: 0,
        width: "100%",
        height: "100%",
        background: "#000",
        opacity: 0,
        zIndex: 998
    });

    // 레이아웃 제어
    window.Layout = new layout({

        selector: {
            head: '#header',
            nav: '#navigator',
            locate: '#navigator .location>a',
            locateDropnMenu: '#navigator .location .locate_drop_menu',
            container: '#container'
        }

    });

    window.onresize = function () {

        fasterAptRes();

        rmPicker(); // 날짜 선택 달력 삭제

        rmGeneralSearch(); // 통합검색 필더 리사이즈시 초기화

        // images(); // images autosize

        return 1;
    };

    gnb(); //GNB메뉴
    mMenu(); //모바일메뉴

    generalSearch(); // 통합검색
    filterCategory(); // 검색 필터
    mySearchOpen(); // 맞춤검색 필터

    linkTab(); // 서브페이지 상단 탭버튼 반응형
    fasterAptRes(); // 빠른예약 반응형 최적화
    placeholderLabel(); // label 을 placeholder 처럼 쓰기
    resDetail(); //예약목록 버튼클릭이벤트
    resPossible(); //예약가능조회
    agrCon(); //약관내용보기
    //tableResponsed();
    aT_link(); //회원가입_약관_상단탭
    snsPop(); //SNS공유 레이어팝업
    // 이미지 로드 체크 후 리사이징
    images(); // images autosize
    fileDel(); //파일첨부시 삭제버튼 보여주기

    searchInfoScheduls(); // 검색 결과의 선착수, 추첨 접수중 클릭시 에약일 안내 레이어

    fakeSelectBox(); // 맞춤검색 원하시는 유형 셀렉트박스

    sitemap(); //사이트맵(전체메뉴)
});






//인쇄
function printPage() {
    var printWindow = window.open('', 'print', '');
    printWindow.document.write('<html><head><title>인쇄 미리보기</title>');
    printWindow.document.write('<meta http-equiv="X-UA-Compatible" content="IE=Edge">');
    printWindow.document.write('<link href="../css/css.css" rel="stylesheet">');
    printWindow.document.write('<link href="../css/print.css" rel="stylesheet">');

    printWindow.document.write('</head>');
    printWindow.document.write('<body style="background:#fff">');
    printWindow.document.write('<button type="button" class="btn" onclick="javascript:window.print();"> 인쇄 </button>');
    //printWindow.document.write(document.getElementById("printtitle").innerHTML);
    printWindow.document.write(document.getElementById("container").innerHTML);
    printWindow.document.write('</body>');
    printWindow.document.write('</html>');
    printWindow.document.close();
    return false;
}


$(document).ready(function () {
    $('.dropdown-menu.opened').on('click', function (e) {
        e.stopPropagation();
    });
});


// 마이페이지
$(function () {

    var parent = $('#header');
    var btn = parent.find('.share');
    var listBtn = parent.find('.my_list a');

    btn.on("click",function (event) {

        $('.general_search, #siteMap').hide();

        event.preventDefault();

        var t = $(this);

        if(t.next().is(":hidden")){

            $('.my_page_wrap').find('a').removeClass("on");
            $(".close_box").parent().fadeOut(300,"easeOutCubic");
            $(".close_box").parent().prev().removeClass("on");

            t.addClass("on");
            t.next().fadeIn(300,"easeOutCubic");

        }else{

            t.removeClass("on");
            t.next().fadeOut(300,"easeOutCubic");
        }
    });

    $('.close_box').on("click",function (event) {

        event.preventDefault();

        var t = $(this);

        t.parent().fadeOut(300,"easeOutCubic");
        t.parent().prev().removeClass("on");
    });

    listBtn.on('click', function (event) {

        var t = $(this);

        if (t.next().is('ul')) {

            event.preventDefault();

            if (t.next().is(':hidden')) {

                listBtn.removeClass('ov');
                t.addClass('ov');

                t.next().stop(0, 1).slideDown(300, 'easeOutCubic');
            }
            else {

                t.removeClass('ov');

                t.next().stop(0, 1).slideUp(300, 'easeOutCubic');
            }
        }
    });
});