//banner
(function () {
    var interleaveOffset = 0.5;

    var swiperOptions = {
        loop: true,
        speed: 1000,
        grabCursor: true,
        watchSlidesProgress: true,
        mousewheelControl: true,
        keyboardControl: true,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        autoplay: {
            delay: 5000,
            stopOnLastSlide: false,
            disableOnInteraction: true,
        },
        on: {
            progress: function() {
                var swiper = this;
                for (var i = 0; i < swiper.slides.length; i++) {
                    var slideProgress = swiper.slides[i].progress;
                    var innerOffset = swiper.width * interleaveOffset;
                    var innerTranslate = slideProgress * innerOffset;
                    swiper.slides[i].querySelector(".slide-inner").style.transform =
                        "translate3d(" + innerTranslate + "px, 0, 0)";
                }
            },
            touchStart: function() {
                var swiper = this;
                for (var i = 0; i < swiper.slides.length; i++) {
                    swiper.slides[i].style.transition = "";
                }
            },
            setTransition: function(speed) {
                var swiper = this;
                for (var i = 0; i < swiper.slides.length; i++) {
                    swiper.slides[i].style.transition = speed + "ms";
                    swiper.slides[i].querySelector(".slide-inner").style.transition =
                        speed + "ms";
                }
            }
        }
    };

    var swiper = new Swiper(".swiper-container", swiperOptions);

})();

//banner图片高度自适应
function bannerH(){
    var num =1920/760;
    var winWidth=window.innerWidth;
    $(".banner").css({height:parseInt(winWidth/num)});
}
$(window).resize(function () {
    bannerH();
});
bannerH();

//  nav 导航
$(function () {
    $(".btn_i").click(function(){
        $(this).toggleClass("btn_i_click");
        $(".h-nav-g").toggleClass("translate");
        $(".ul-small").toggleClass("translate2");
    });
    $(".ul-small>ul>li").click(function () {
        $(this).find("p").slideToggle();
        $(this).find("p").end().siblings().find("p").slideUp();
        $(this).toggleClass("li_click");
        $(this).siblings().removeClass("li_click");
    });

    $(window).scroll(function () {
        var sTop=$(window).scrollTop();
        if(sTop>100){
            $(".pc-nav").addClass("pc-nav-animate")
        }else{
            $(".pc-nav").removeClass("pc-nav-animate")
        }
    })

    $(".logo p a").eq(0).on("click", function () {
        $(this).next().toggleClass("changeLag");
    })
});

//技术中心
(function () {
    $(".technology_left ul li").each(function (i) {
        $(this).hover(function () {
            $(this).addClass("technology_act").siblings().removeClass("technology_act");
            $(".technology_right ul li").eq(i).show().siblings().hide();
        })
    })
})();


// //图片懒加载
$(".lazyload").lazyload({
    placeholder : "images/grey.gif", //用图片提前占位
    // placeholder,值为某一图片路径.此图片用来占据将要加载的图片的位置,待图片加载时,占位图则会隐藏
    effect: "fadeIn", // 载入使用何种效果
    // effect(特效),值有show(直接显示),fadeIn(淡入),slideDown(下拉)等,常用fadeIn
    threshold: 200 // 提前开始加载
    // threshold,值为数字,代表页面高度.如设置为200,表示滚动条在离目标位置还有200的高度时就开始加载图片,可以做到不让用户察觉
});

//图片缩放
$('.img_wrap').viewer();


//定义变量获取屏幕视口宽度
var windowWidth = $(window).width();
if(windowWidth >= 640){
    new WOW().init();
    // $("a").each(function (i) {
    //     $(this).attr("target","_blank")
    // });

}


//sidebar
(function () {
    $("#LeftNav ul > li").each(function () {
        $(this).children("a").click(function () {
            $(this).next().slideToggle();
            $(this).parent().siblings().find("ol").slideUp();
        })
    });


    $("#LeftNav ul>li").each(function () {
        var len=$(this).find("li").length;
        var aHref=$(this).children("a").attr("ahref");
        console.log(len);
        if(len == 0){
            $(this).children("a").attr("href",aHref);
        }else{
            $(this).children("a").attr("href","javascript:void(0)");
        }
    });

    $("#LeftNav h3").click(function () {
        console.log( $(this).next());
        $(this).next().slideToggle();
    });

    var types = $("#LeftNav ul li a");
    var currentType = window.location.href;
    for(i=0; i<types.length; i++){
        if(types[i] == currentType){
            $(types[i]).addClass("current");
        }
        continue;
        i++;
    }

})();


//产品详情页切换
(function () {
    $(".product-content-tit span").each(function (i) {
        $(this).click(function () {
            $(this).addClass("span_act").siblings().removeClass("span_act");
            $(".pro_all_c>div").eq(i).show().siblings("div").hide();
        })
    })
})();



