$(function () {

    //focus  border-color
    indexInput('.home-main input');

    function indexInput(sel) {
        var $input = $(sel);
        $input.focusin(function () {
            $(this).parent().css('border-color', '#00a0e9');
            $(this).parent().addClass('active');
        });
        $input.focusout(function () {
            $(this).parent().css('border-color', '');
            $(this).parent().removeClass('active');
        });
    }

    $('.home-pdemand input').keydown(function () {
        $(this).parent().find('.tink').css('display', 'none');
    });

    // banner
    var banner_swiper = new Swiper('.lsj_banner_swiper', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        nextButton: '.lsj_banner-next',
        prevButton: '.lsj_banner-prev',
        autoplay: 3000,
        loop: true,
        autoplayDisableOnInteraction: false,
        lazyLoading: true,
        lazyLoadingInPrevNext: true,
    });

    // 平台优质服务方
    var servicelist_swiper = new Swiper('.lsj-servicelist_con', {
        autoplay: 1500,
        speed: 1000,
        loop: true,
        centeredSlides: true,
        slidesPerView: 'auto',
        //数量
        loopedSlides: 13,
        slidesPerGroup: 1,
        width: 990,
        nextButton: '.lsj_servicelist-next',
        prevButton: '.lsj_servicelist-prev',
        lazyLoading: true,
        lazyLoadingInPrevNext: true,
    });

    $(".lsj-servicelist_con").mouseenter(function () { //滑过悬停
        servicelist_swiper.stopAutoplay(); //mySwiper 为上面你swiper实例化的名称
    }).mouseleave(function () { //离开开启
        servicelist_swiper.startAutoplay();
    });


    // 成功案列
    $('.home-caselist .case-btn').on('click', function () {
        var _this = $(this);
        $('.home-caselist .item-mode').css('display', 'none');
        _this.closest('.case-item').find('.item-mode').fadeIn();
    });
    $('.home-caselist .case-item').on('click', function (e) {
        e.stopPropagation();
    });
    $(document).on('click', function () {
        $('.home-caselist .item-mode').fadeOut();
    });
    $(window).on('scroll', function () {
        $('.home-caselist .item-mode').fadeOut();
    });

    // 滚动出发动画
    new WOW().init();

    var servicelist = new WOW({
        boxClass: 'lsj-servicelist_con',
        animateClass: 'animated fadeInUp3',
        offset: 300,
        mobile: true,
        live: true,
    });

    var win_height = $(window).height() / 3;
    var linkListLeft = new WOW({
        boxClass: 'link-left',
        animateClass: 'animated fadeInLeft',
        offset: 0,
        mobile: true,
        live: false
    });
    var linkListcenter = new WOW({
        boxClass: 'link-center',
        animateClass: 'animated fadeIn',
        offset: 0,
        mobile: true,
        live: true
    });
    var linkListRight = new WOW({
        boxClass: 'link-right',
        animateClass: 'animated fadeInRight',
        offset: 0,
        mobile: true,
        live: true
    });
    servicelist.init();
    linkListLeft.init();
    linkListcenter.init();
    linkListRight.init();

    // 合作模式
    $('#homeCaseList .case-item .item-main_box--btn').on('click', function (event) {
        $('#homeCaseList .case-item').removeClass('actived');
        $(this).closest('.case-item').addClass('actived');
    });
    $('#homeCaseList .case-item ').on('click', function (event) {
        event.stopPropagation();
    });
    $(document).on('click', function () {
        $('#homeCaseList .case-item').removeClass('actived');
    });
    $(document).on('scroll', function () {
        $('#homeCaseList .case-item').removeClass('actived');
    });

    // 热门案例
    $('#popularCase .lsj-hc_tab li').on('click', function (e) {
        var $this = $(this);
        var $cIndex = $this.index();
        $('#popularCase .lsj-hc_tab li').removeClass('actived');
        $('#popularCase .lsj-hc_tab li').eq($cIndex).addClass('actived');
        if ($('#popularCase .lsj-hc_main > ul').eq($cIndex)) {
            $('#popularCase .lsj-hc_main > ul').hide();
            $('#popularCase .lsj-hc_main > ul').eq($cIndex).show();
        } else {
            return false;
        }
    });

    // 服务项目
    $('.lsj_service_items_link').on('click', function () {
        var $this = $(this);
        var $obj = $this.attr('class').replace('link lsj_service_items_link ', '');
        localStorage.setItem('popularize_high', $obj);
    });

    // 合作模式
    $('.case-item_img').on('click', function (e) {
        e.stopPropagation();
        e.preventDefault();
        var $this = $(this);
        var $index = $this.closest('.case-item').index();
        $('.case-popup-item').eq($index).fadeIn();
        $('body').css('overflow', 'hidden');
        $('body').addClass('z-index-Ins');
    });

    $('.case-popup-item').on('click', function (e) {
        var $this = $(this);
        var $type = $(e.target).hasClass('case-popup-item');
        var $closed = $(e.target).hasClass('closed');
        if ($type || $closed) {
            $('.case-popup-item').fadeOut();
            $('body').css('overflow', 'auto');
            $('body').removeClass('z-index-Ins');
        }
    });

    function popular_case_show() {
        var $sTop = $(window).scrollTop();
        var $obj = $('.lsj-hot-case');
        var $popular_case_offset_top = $obj.offset().top;

        if ($popular_case_offset_top - $sTop < window.innerHeight - 400) {
            $('.lsj-hc_main').show();
        }
    }

    setTimeout(function () {
        $('.case-item_img').each(function () {
            var src = $(this).attr('data-src');
            $(this).attr('src', src);
        })
        $('#hot_case_list img').each(function () {
            var src = $(this).attr('data-src');
            $(this).attr('src', src);
        })

        $('.lsj-servicelist_item-img img').each(function () {
            var src = $(this).attr('data-src');
            if (src) {
                $(this).attr('src', src);
            }
        })

    }, 500);

    // 免费发布
    $('#indexv3-pdemandbtn').on('click', function () {
        $('body,html').animate({scrollTop: 350}, 400);
    });

    popular_case_show();

    $(window).scroll(function (e) {
        popular_case_show();
    });

    $('#serviceItemsNavs li').hover(function () {
        var $this = $(this);
        var $index = $this.index()
        var $items = $('.lsj-service-items_panel');
        var $lis = $('#serviceItemsNavs li');
        $items.removeClass('actived').eq($index).addClass('actived')
        $lis.removeClass('actived').eq($index).addClass('actived')
    });

});