$(document).ready(function () {

    /* Sliding Top Banner *********************
	*****************************************/

    $('.slideTopBnr .owl-carousel.mo .item').css({
        'height': 'auto',
        'background': 'transparent'
    });

    $("#chkboxTopBanner").change(function (event) {
        event.preventDefault();
        $('.slide-close').click();
       
    });

    $('.slide-close').click(function () {
        $('.slideTopBnr').css('border-bottom', '0');
        $('.slideTopBnr .owl-carousel img, .slideTopBnr p').css('display', 'none');
        $('.slideTopBnr').find('.none').css('display', 'block');

        if ($("#chkboxTopBanner:checked").length == 1) {
            SetCookie("CloseToday", 1, 1);
            $('.slideTopBnr').hide();
        }
    });

    $('.slideTopBnr p.none span').click(function () {
        $('.slideTopBnr .owl-carousel img, .slideTopBnr p').css('display', 'block');
        $('.slideTopBnr').find('.none').css('display', 'none');
    });

    /* PopUp + alert Event ********************
     *****************************************/
    function wrapWindowByMask() {
        var maskHeight = $(document).height();

        $(".mask").css("height", maskHeight);
        $(".mask").fadeTo("fast", 0.6);
    }

    $(".comment button.login, .event .btn.lrg, .ville-event .pop-open-btn").click(function () {
        wrapWindowByMask();
        $('.popUp').css('display', 'block');
    });
    $(".popUp .close").click(function () {
        $("body").removeClass("fixed");
        $(".mask").hide();
        $('.popUp').css('display', 'none');
    });

    //$(".apply.step6 .btn-wrap .btn").click(function () {
    //    wrapWindowByMask();
    //    $('.alert').css('display', 'block');
    //});
    $(".alert h3 a.cancel").click(function () {
        $(".mask").hide();
        $('.alert').css('display', 'none');
    });


	/* PC GNB Event **************************
	*****************************************/
    $('.sub-gnb').stop().slideUp(0);

    $('header').mouseleave(function () {
        $('.sub-gnb').slideUp(150);
    });

    /* zoe1028 수정 시작 (기존 이벤트 삭제 및 새로운 이벤트 추가) */
    var subGnbMenu = $('nav .has-subgnb');

    $('nav li').not(subGnbMenu).mouseenter(function () {
        $('.sub-gnb').hide();
        $('.sub-gnb ul').hide();
    });

    subGnbMenu.mouseenter(function () {
        var thisData = $(this).attr('data-subgnb');
        var thisSubGnb = $('.' + thisData);

        $('.sub-gnb').slideDown(150);
        $('.sub-gnb ul').hide();
        thisSubGnb.show();
    });
	/* zoe1028 수정 끝 */

    /* Mobile GNB Event **********************
	*****************************************/

    var maskHeight = $(document).height();

    // Button Event
    $('.slicknav > ul').css('height', maskHeight).stop().slideUp(0);

    $('.line-btn-wrap').click(function () {
        $(this).toggleClass('active');
        $('.slicknav > ul').slideToggle(300);
    });

    // Scroll Event
    $(window).scroll(function () {
        if ($(this).scrollTop() > 0) {
            $('.slicknav').addClass('fixed').css('border-bottom', '1px solid #ddd');
        } else {
            $('.slicknav').removeClass('fixed').css('border-bottom', '0');
        }
    });

    // Dropdown Menu Event
    $('.slicknav .dropdown ul').stop().slideUp(0);
    $('.slicknav .dropdown:first-child ul').slideDown(0);

    $('.slicknav .dropdown').click(function () {
        $('.slicknav .dropdown').not(this).children('ul').slideUp(100);
        $(this).children('ul').slideToggle(100);
    });

    /* Sub Common style **********************
	*****************************************/

    // tab-menu with border event
    $('.tab-menu.border li').click(function () {
        $(this).addClass('active');
        $('.tab-menu.border li').not(this).removeClass('active');
    });

    //sort btn event
    $('.imgList .sortBtn li').click(function () {
        $('.imgList .sortBtn li').not(this).removeClass('active');
        $(this).addClass('active');
    })


    /*Image List style ***********************
        *****************************************/
    var $window = $(window);

    function checkWidth() {
        var windowsize = $window.width();

        if (windowsize < 521) {
            $('.imgList .list li .thumb').mouseenter(function () {
                $(this).children('img').css('transform', 'scale(1, 1)');
            })
        }
    }

    checkWidth();
    $(window).resize(checkWidth);

    /* Last Campaign Tab Event ****************
*****************************************/

    $('.imgList .triple.lastCam li').click(function () {
        $('.imgList .triple.lastCam li').not(this).removeClass('active');
        $(this).addClass('active');
    });

    $('.imgList .triple.lastCam li').first().click(function () {
        $('.lastCamCat').css('display', 'none');
        $('.lastCamCat.bCat').css('display', 'block');
    });
    $('.imgList .triple.lastCam li:nth-child(2)').click(function () {
        $('.lastCamCat').css('display', 'none');
        $('.lastCamCat.sCat').css('display', 'block');
    });
    $('.imgList .triple.lastCam li').last().click(function () {
        $('.lastCamCat').css('display', 'none');
        $('.lastCamCat.lCat').css('display', 'block');
    });
    $('.lastCamCat a').click(function () {
        $('.lastCamCat a').not(this).removeClass('active');
        $(this).addClass('active');
    });

    /* Post Event ****************************
	*****************************************/

    // scroll top
    $(".fl-post .last").click(function () {
        $("html, body").animate({ scrollTop: 0 }, 350);
        return false;
    });

    //Changing floating menu position
    $(window).scroll(function () {
        if ($(window).scrollTop() + $(window).height() > $(document).height() - 145) {
            $('.fl-post').css({
                'bottom': '180px'
            });
        } else {
            $('.fl-post').css({
                'bottom': '10px'
            });
        }
    });

    /* Apply Event ***************************
	*****************************************/

    // floating menu
    var fl_menu = $(".fl-apply > a");
    var contents = $("article .grid > .applyIntro");

    fl_menu.click(function (event) {
        event.preventDefault();

        var tg = $(this);
        var i = tg.index();
        var section = contents.eq(i);
        var tt = section.offset().top;

        $("html, body").stop().animate({ scrollTop: tt });
    });
    $(window).scroll(function () {
        var sct = $(window).scrollTop();

        contents.each(function () {
            var tg = $(this);
            var i = tg.index();

            if (tg.offset().top <= sct + 350) {
                fl_menu.removeClass("active");
                fl_menu.eq(i - 1).addClass("active");
            }
        });
    });

    // slideDown box
    $('.slideDownBox').stop().slideUp(0);

    //$('.btn').click(function () {
    //    $(this).next('.slideDownBox').slideToggle(150);
    //});

    // help icon
    $('.apply .help').mouseenter(function () {
        $(this).children('.txt').addClass('active');
    });
    $('.apply .help').mouseleave(function () {
        $(this).children('.txt').removeClass('active');
    });

    // text-box action
    $('.form .input-style .active').click(function () {
        $(this).next('input').css('display', 'block');
    });

    // Story Example in Apply
    $('.apply .textEx span').click(function () {
        $(this).next('.apply .textEx p').slideToggle(100);
        $(this).parent('.textEx').toggleClass('active');

        if ($(this).text() == '닫기') {
            $(this).text('예시보기');
        } else {
            $(this).text('닫기');
        }
    });

	/* Story Tab Event ************************
	*****************************************/

    $('.imgList .quarter li').click(function () {
        $(this).addClass('active');
        $('.imgList .quarter li').not(this).removeClass('active');
    });

    /* Form Event ****************************
	*****************************************/

    // faq slideup,down event
    $(".tblForm.faq h1").next("div").stop().slideUp(0);

    $("body").on("click", ".tblForm.faq h1", function () {
        $(this).toggleClass("active");
        $(".tblForm.faq h1").not($(this)).removeClass("active");
        $(this).next("div").stop().slideToggle(150);
        $(".tblForm.faq h1").next("div").not($(this).next("div")).slideUp(150);
    });


    //chainging faq ico
    $("body").on("click", ".tblForm.faq h1", function () {
        var src = ($(this).children('img').attr("src") === "/content/images/ico-q.png")
            ? "/content/images/ico-a.png"
            : "/content/images/ico-q.png";
        $(this).children('img').attr("src", src);
        $(".tblForm.faq h1").not(this).children('img').attr("src", "/content/images/ico-q.png");
    });


    /***************************************
	YoungStartUp - MainProcess Tab Event
	****************************************/
    $('.young .mainProcess h2 p').first().click(function () {
        $('.young .mainProcess h2 p').removeClass();
        $(this).addClass('active');
        $('.young .mainProcess img').css('display', 'block');
        $('.young .mainProcess img.none').css('display', 'none');
    })

    $('.young .mainProcess h2 p').last().click(function () {
        $('.young .mainProcess h2 p').removeClass();
        $(this).addClass('active');
        $('.young .mainProcess img').css('display', 'none');
        $('.young .mainProcess img.none').css('display', 'block');
    })

    /***************************************
	YoungStratUp - giftcar tv intro Event
	****************************************/

    //cheerUCC tab event
    $('.tvIntro .mainTv ul li').click(function () {
        $('.tvIntro .mainTv ul li').removeClass();
        $(this).addClass('active');
    });

    $('.tvIntro .mainTv ul li').first().click(function () {
        $('.tvIntro .mainTv div').css('display', 'none');
        $('.tvIntro .mainTv div.first').css('display', 'block');
    });
    $('.tvIntro .mainTv ul li').last().click(function () {
        $('.tvIntro .mainTv div').css('display', 'none');
        $('.tvIntro .mainTv div.last').css('display', 'block');
    });

    /***************************************
	리뉴얼 YoungStratUp -  crew Event
	****************************************/
    //crew hero thumbnail click event
    //$('.crewEventPost .hero ul li.thumb img').click(function () {
    //    $(this).css('display', 'none');
    //    $(this).siblings('.ucc').css('display', 'block');

    //    var url = $(this).siblings('.ucc').find('iframe').attr("data-url");
    //    $(this).siblings('.ucc').find('iframe').attr('src', url);
    //});

    //crew hero join event
    //$('.crewEventPost .hero ul li.txt a, .crewEventPost .tabPost .story .float').click(function () {
    //    wrapWindowByMask();
    //    $('.popUp').css('display', 'block');
    //});
    //$('.popUp').find('.popClick').click(function () {
    //    $('.popUp').hide();
    //});

    ////crew cheer massage's animation event
    //var list = $('.crewEventPost .cheer .msg ul li').length;
    //current = 0;

    //setInterval(function () {
    //    $('.crewEventPost .cheer .msg ul li').eq(current).removeClass('animate');

    //    if (current == list - 1) {
    //        current = 0;
    //    } else {
    //        current++;
    //    }

    //    $('.crewEventPost .cheer .msg ul li').eq(current).addClass('animate');
    //}, 1500);

    //crew tabpost tab event
    $('.crewEventPost .tabPost > ul li').click(function () {
        $('.crewEventPost .tabPost > ul li').removeClass();
        $(this).addClass('active');
    });

    $('.crewEventPost .tabPost > ul li').first().click(function () {
        $('.crewEventPost .tabPost > div').css('display', 'none');
        $('.crewEventPost .tabPost .story').css('display', 'block');
    });
    $('.crewEventPost .tabPost > ul li').last().click(function () {
        $('.crewEventPost .tabPost > div').css('display', 'none');
        $('.crewEventPost .tabPost .msg').css('display', 'block');
    });

    ////crew tabpost story event
    //var crewBtn = $('.crewEventPost .tabPost .story').children('a');
    //var crewBtnTop = crewBtn.offset().top;

    //$(window).scroll(function () {
    //    var sct = $(window).scrollTop();
    //    if (crewBtnTop <= sct + 850) {
    //        $('.crewEventPost .tabPost .story').children('.more').slideDown(500);
    //        crewBtn.hide();
    //    }
    //});

    //crewBtn.click(function () {
    //    $(this).hide();
    //    $('.crewEventPost .tabPost .story').children('.more').slideDown(500);
    //});

    //crew tabpost story floating banner event
    //function checkWidth() {
    //    var windowsize = $window.width();

    //    if (windowsize > 1001) {
    //        $(window).scroll(function () {
    //            var sct = $(window).scrollTop();
    //            var newPosition = sct - 1500 + "px";

    //            if (sct >= 1760) {
    //                $('.crewEventPost .tabPost .story .float').css('top', newPosition);
    //            } else {
    //                $('.crewEventPost .tabPost .story .float').css('top', '190px');
    //            }
    //        });
    //    } else {
    //        $(window).scroll(function () {
    //            var sct = $(window).scrollTop();
    //            var tabpostsct = $('.crewEventPost .tabPost').offset().top;

    //            if (sct >= tabpostsct) {
    //                $('.crewEventPost .tabPost .story .float').css({
    //                    'position': 'fixed',
    //                    'bottom': '0'
    //                });
    //            } else {
    //                $('.crewEventPost .tabPost .story .float').css('position', 'absolute');
    //            }
    //        });
    //    }
    //}

});


wrapWindowByMask = function () {
    var maskHeight = $(document).height();

    $(".mask").css("height", maskHeight);
    $(".mask").fadeTo("fast", 0.7);
}

SetCookie = function (name, value, expiredays) {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

GetCookie = function (name) {
    var nameOfCookie = name + "=";
    var x = 0;

    while (x <= document.cookie.length) {
        var y = (x + nameOfCookie.length);

        if (document.cookie.substring(x, y) == nameOfCookie) {
            if ((endOfCookie = document.cookie.indexOf(";", y)) == -1)
                endOfCookie = document.cookie.length;

            return unescape(document.cookie.substring(y, endOfCookie));
        }

        x = document.cookie.indexOf(" ", x) + 1;
        if (x == 0) break;
    }

    return "";
}

IsMobieDevice = function () {
    var isMobile = false;

    if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(navigator.userAgent)
        || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) {
        isMobile = true;
    }

    return isMobile
}


JsOpenNewPage = function (url) {
    window.open(url);
}

JsMove = function (url) {
    location.href = url;
}