$(function () {
    //定位当前页面在导航上的位置
    $('.nav > li').hover(function () {
        $(this).siblings().removeClass('active')
        $(this).addClass('active')
    }, function () {
        $(this).parent().find('li').removeClass('active')
        $('.nav > li > a[href="' + location.href + '"]').parent().addClass('active')
    })
    $('.nav > li > a[href="' + location.href + '"]').parent().addClass('active')


    //顶部新闻滚动
    $(".font_inner li:eq(0)").clone(true).appendTo($(".font_inner"));//克隆第一个放到最后(实现无缝滚动)
    var liHeight = $(".swiper_wrap").height();//一个li的高度
    //获取li的总高度再减去一个li的高度(再减一个Li是因为克隆了多出了一个Li的高度)
    var totalHeight = ($(".font_inner li").length * $(".font_inner li").eq(0).height()) - liHeight;
    $(".font_inner").height(totalHeight);//给ul赋值高度
    var index = 0;
    var autoTimer = 0;//全局变量目的实现左右点击同步
    var clickEndFlag = true; //设置每张走完才能再点击

    function tab() {
        $(".font_inner").stop().animate({
            top: -index * liHeight
        }, 400, function () {
            clickEndFlag = true;//图片走完才会true
            if (index == $(".font_inner li").length - 1) {
                $(".font_inner").css({ top: 0 });
                index = 0;
            }
        })
    }

    function next() {
        index++;
        if (index > $(".font_inner li").length - 1) {//判断index为最后一个Li时index为0
            index = 0;
        }
        tab();
    }

    function prev() {
        index--;
        if (index < 0) {
            index = $(".font_inner li").size() - 2;//因为index的0 == 第一个Li，减二是因为一开始就克隆了一个LI在尾部也就是多出了一个Li，减二也就是_index = Li的长度减二
            $(".font_inner").css("top", -($(".font_inner li").size() - 1) * liHeight);//当_index为-1时执行这条，也就是走到li的最后一个
        }
        tab();
    }

    //切换到下一张
    $(".swiper_wrap .gt").on("click", function () {
        if (clickEndFlag) {
            next();
            clickEndFlag = false;
        }
    });
    //切换到上一张
    $(".swiper_wrap .lt").on("click", function () {
        if (clickEndFlag) {
            prev();
            clickEndFlag = false;
        }
    });
    //自动轮播
    autoTimer = setInterval(next, 3000);
    $(".font_inner a").hover(function () {
        clearInterval(autoTimer);
    }, function () {
        autoTimer = setInterval(next, 3000);
    })

    //鼠标放到左右方向时关闭定时器
    $(".swiper_wrap .lt,.swiper_wrap .gt").hover(function () {
        clearInterval(autoTimer);
    }, function () {
        autoTimer = setInterval(next, 3000);
    })
    //1文字轮播(2-5页中间)结束


    //banner滚动
    $('.banner').bxSlider({
        mode: 'fade',
        slideWidth: 1920,
        slideMargin: 10,
        auto: true,
        controls: false
    });

    //产品滚动
    $('.product-scroll').bxSlider({
        slideWidth: 220,
        minSlides: 2,
        maxSlides: 4,
        moveSlides: 1,
        slideMargin: 10,
        auto: true,
        pager: false,
        controls: false
    });

    //案例滚动
    $('.case-scroll').bxSlider({
        slideWidth: 180,
        minSlides: 2,
        maxSlides: 6,
        moveSlides: 3,
        slideMargin: 10,
        auto: true,
        pager: false,
        controls: false
    });

    //案例滚动
    $('.info-product-image').bxSlider({
        mode: 'fade',
        slideWidth: 1920,
        slideMargin: 10,
        auto: true,
        controls: false
    });
    $('#nav .nav li.list').hover(function () {
        $(this).find('.list_ul').show();
        $('.fullscreen_list_div').hide();
    }, function () {
        $(this).find('.list_ul').hide();
    })


    $('.nav > li.list .list_ul > li').hover(function () {
        $(this).find('ul.list_children').show();
    }, function () {
        $(this).find('ul.list_children').hide();
    })
})
