//电话转接
var $body = $("#body");
var zj_tel = $body.data("zjtel");
var main_zj_tel = $body.data("mainzjtel");
if(zj_tel != "" && zj_tel != "0"){
    $("#head_nav_tel").html(main_zj_tel+"<img src=\"/coco/img/tel_right_line.png\" />");
    var $head_tel_box_c = ' <div class="tel_zj">转&nbsp;<span class="z2" id="zj_code">'+zj_tel+'</span></div>' +
        '        <div class="tel_zi">该机构培训老师接听</div>';
    $("#head_tel_box").html($head_tel_box_c);
    $("#head_tel_box").css("display","block");

    $("#bottom_show_tel").html(main_zj_tel+'&nbsp;&nbsp;转'+'&nbsp;&nbsp;'+zj_tel);
}

if($(".swiper-container .swiper-wrapper").length > 1){
    var mySwiper = new Swiper('.swiper-container', {
        autoplay: 10000,//可选选项，自动滑动
        loop: true,//可选选项，开启循环
        speed: 2000,//滑动速度，即slider自动滑动开始到结束的时间（单位ms）
        pagination: '.pagination',
        paginationClickable: true,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    })
}else{
    $(".swiper-wrapper").css("height",'100%');
    $(".swiper-wrapper .swiper-slide").css("height",'100%');
    $(".swiper-wrapper .swiper-slide img").css("height",'100%');
}



/*鼠标移入停止轮播，鼠标离开 继续轮播*/
var comtainer = document.getElementById('swiper_container');
// comtainer.onmouseenter = function () {
//     mySwiper.stopAutoplay();
// };
// comtainer.onmouseleave = function () {
//     mySwiper.startAutoplay();
// }
//有1轮播
var viewSwiperC = new Swiper('.view .swiper-containerC', {})
$('.view .arrow-left').on('click', function (e) {
    e.preventDefault()
    if (viewSwiperC.activeIndex == 0) {
        viewSwiperC.swipeTo(viewSwiperC.slides.length - 1, 1000);
        return;
    }
    viewSwiperC.swipePrev()
})
$('.view .arrow-right').on('click', function (e) {
    e.preventDefault()
    if (viewSwiperC.activeIndex == viewSwiperC.slides.length - 1) {
        viewSwiperC.swipeTo(0, 1000);
        return;
    }
    viewSwiperC.swipeNext()
})
//banner
var viewSwiper = new Swiper('.view .swiper-container', {
    onSlideChangeStart: function () {
        updateNavPosition()
    }
})
$('.view .arrow-left,.preview .arrow-left').on('click', function (e) {
    e.preventDefault();
    if (viewSwiper.activeIndex == 0) {
        viewSwiper.swipeTo(viewSwiper.slides.length - 1, 1000);
        return;
    }
    viewSwiper.swipePrev()
})
$('.view .arrow-right,.preview .arrow-right').on('click', function (e) {
    e.preventDefault()
    if (viewSwiper.activeIndex == viewSwiper.slides.lenght - 1) {
        viewSwiper.swipeTo(0, 1000);
        return;
    }
    viewSwiper.swipeNext()
})
var previewSwiper = new Swiper('.preview .swiper-container', {
    visibilityFullFit: true,
    slidesPerView: 'auto',
    onlyExternal: true,
    onSlideClick: function () {
        viewSwiper.swipeTo(previewSwiper.clickedSlideIndex)
    }
})

function updateNavPosition() {
    $('.preview .active-nav').removeClass('active-nav')
    var activeNav = $('.preview .swiper-slide').eq(viewSwiper.activeIndex).addClass('active-nav')
    if (!activeNav.hasClass('swiper-slide-visible')) {
        if (activeNav.index() > previewSwiper.activeIndex) {
            var thumbsPerNav = Math.floor(previewSwiper.width / activeNav.width()) - 1
            previewSwiper.swipeTo(activeNav.index() - thumbsPerNav)
        } else {
            previewSwiper.swipeTo(activeNav.index())
        }
    }
}
$(function(){
    //访客数+1
    var cid = $body.data("cid");
    var uid = $body.data("uid");
    $.post('/Visitor/courseViewPlus', {'id': cid}, function (res) {
        var old_num = $("#click_num").html();
        $("#click_num").html(parseInt(old_num) + 1);
    });

    //点赞
    $(".com_minfos_dz").click(function () {
        $.post('/visitor/comClickPlus', {'mid': uid}, function (res) {
            var res_status = res.status;
            if (res_status == 200) {
                var $dz_item = $(".com_minfos_dz span");
                var old_z = $dz_item.html();
                $dz_item.html(parseInt(old_z) + 1);
            } else {
                layer.msg(res.msg);
            }
        });

    });
    $("#course_dianzan_btn").click(function(){
        $.post('/visitor/courseClickPlus', {'cid': cid}, function (res) {
            var res_status = res.status;
            if (res_status == 200) {
                var $dz_item = $("#course_dianzan_btn span");
                var old_z = $dz_item.html();
                $dz_item.html(parseInt(old_z) + 1);
            } else {
                layer.msg(res.msg);
            }
        });
    });
});