(function($){
    $.fn.numberRock=function(options){
        var defaults={
            lastNumber:100,
            duration:3000,
            easing:'swing'  //swing(默认 : 缓冲 : 慢快慢)  linear(匀速的)
        };
        var opts=$.extend({}, defaults, options);

        $(this).animate({
            num : "numberRock",

        },{
            duration : opts.duration,
            easing : opts.easing,
            complete : function(){
                // console.log("success");
            },
            step : function(a,b){

                $(this).html(parseInt(b.pos * opts.lastNumber));
            }
        });
    }


})(jQuery);


$(document).ready(function(){

    function loadVideo(){
        if($(".indexShowVideo").length > 0){
            var indexPlayer = videojs('indexVideo');
            videojs("indexVideo").ready(function () {
                var indexPlayer = this;
                indexPlayer.play();
            });
        }
    }
    loadVideo();


    // videoSize();
    // scaleWindow();
    indexFullPage();
    indexBanner();
    videoSwiper();
    indexBannerSize();
    noticeSlide();
    groupSlide();
    linkConWidth();
    gtBrowser();



    if($(".index-banner").length > 0){
        var _src = $(".index-banner .swiper-slide-active").find("img").attr('src');
        $(".left-nav").css({'background':'url('+_src+') no-repeat'})

        function videoSize(){
            // var winWidth = $(window).width()+200;			//浏览器宽度
            // var winHeight = $(window).height()+200;			//浏览器高度
            var _W = $(".indexShowVideo-con").find(".opcity").width()+100;
            var _h = $(".indexShowVideo-con").find(".opcity").height()+100;
            $(".indexShowVideo").find("video").css({'width':_W,'height':_h});
            $("#indexVideo").css({'width':_W,'height':_h,'margin-top':-_h/2,'margin-left':-_W/2});
        }
        videoSize();
        $(window).resize(function(){
            videoSize();
        })

    }

    if($(".videoCenter").length > 0){
        var indexPlayer = videojs('video1');
        videojs("video1").ready(function () {
            var indexPlayer = this;
            // this.play();
        });

        $(".v-wrap").click(function(){
            $(".indexShowVideo").fadeOut();
        })
    }


});

$(window).resize(function(){

    indexBannerSize();
    linkConWidth();

});



//fullpage
function indexFullPage(){
    $("#fullpage").fullpage({
        anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'fifthPage','sixPage','seventhPage','eighthPage'],
        menu: '#menu',
        scrollingSpeed:400,
        navigation:true,
        navigationPosition:'right',
        css3:true,
        fitToSection: true,
        resize : false,
        verticalCentered:false,
        onLeave: function(anchorLink, index){

            $(".nav-goTop .redLine").height(15*index+'px');

            if(index === 1){
                $(".nav-goTop .redLine").height(0);
                $(".headerCon").addClass("animation");
                $("#fullpage .section#section1").css('overflow','inherit')
            }else if(index === 6){
                var _txt1 = $(".counter1").attr('data-val');
                var _txt2 = $(".counter2").attr('data-val');
                var _txt3 = $(".counter3").attr('data-val');
                var _txt4 = $(".counter4").attr('data-val');
                var _txt5 = $(".counter5").attr('data-val');
                $(".counter1").numberRock({
                    lastNumber:_txt1,
                    duration:2000,
                    easing:'swing',
                });
                $(".counter2").numberRock({
                    lastNumber:_txt2,
                    duration:2000,
                    easing:'swing',
                });
                $(".counter3").numberRock({
                    lastNumber:_txt3,
                    duration:2000,
                    easing:'swing',
                });
                $(".counter4").numberRock({
                    lastNumber:_txt4,
                    duration:2000,
                    easing:'swing',
                });
                $(".counter5").numberRock({
                    lastNumber:_txt5,
                    duration:2000,
                    easing:'swing',
                });


            }else{
                $(".headerCon").removeClass("animation");
            }
            if(index>1){
                $(".left-nav").addClass("fixed");
            }else{
                $(".left-nav").removeClass("fixed");
            }
        },
        afterLoad: function(anchorLink, index){
            if(index === 1){
                $(".headerCon").addClass("animation");
            }else{
                $(".headerCon").removeClass("animation");
                $("#fullpage .section#section1").css('overflow','hidden')
            }
        }
    });
}

function num(){
    $(".counter").each(function(){
        $(this).prop('counter',0).animate({
            Crs:$(this).text()
        },{
            duration:2000,
            easing:'swing',
            step:function(now){
                console.log(now)
                $(this).text(Math.ceil(now));
            }
        })
    })
}

//首页banner
function indexBanner(){
    if($(".index-banner").length > 0){
        var swiper = new Swiper ('.index-banner .swiper-container', {
            pagination: '.index-banner .pagination',
            // nextButton: '.index-banner .arrow-right',
            // prevButton: '.index-banner .arrow-left',
            paginationClickable :true,
            autoHeight: true,
            autoplay:5000,
            noSwiping : true,
            speed:800,
            autoplayDisableOnInteraction : false,
            loop : true,
            onSlideChangeStart: function(swiper){
                var _src = $(".index-banner .swiper-slide-active").find("img").attr('src');
                // $("body").css('background','rgba(0, 0, 0, 0.6)'+_src);
                $(".left-nav").css('background','url('+_src+')')
            }
        })
        $(".index-banner .pagination").find("span").each(function(){
            var _index = $(this).index();
            $(this).html(_index + 1)
        })
        $('.index-banner .arrow-left').on('click', function(e){
            e.preventDefault()
            swiper.swipePrev()
        })
        $('.index-banner .arrow-right').on('click', function(e){
            e.preventDefault()
            swiper.swipeNext()
        })
    }
}

function videoSwiper(){
    if($(".videoCenter").length > 0){
        // var swiperVideo = new Swiper ('.videoCenter .swiper-container', {
        //     pagination: '.videoCenter .pagination',
        //     paginationClickable :true,
        //     effect : 'cube',
        //     autoHeight: true,
        //     noSwiping : true,
        //     noSwipingClass : 'stop-swiping',
        //     speed:800,
        //     paginationBulletRender: function (swiper, index, className) {
        //         console.log(swiper)
        //         return '<span class="' + className + '"><i></i>0'  + (index + 1) + '</span>';
        //     },
        //     onSlideChangeEnd:function(swiper){
        //         $(".videoCenter .swiper-slide").each(function(e){
        //             var v_len = $(this).find("video").length;
        //             for(var i = 0;i<v_len;i++){
        //                 $(this).find("video").get(i).pause(); //把所有停止
        //             }
        //             var _video = $(this).find("video.video-js");
        //             _video.attr('src','');
        //             $(this).removeClass('active');
        //
        //         })
        //
        //     }
        // })
        // $(".videoCenter .pagination").find("span").each(function(){
        //     var _index = $(this).index();
        //     $(this).html(_index + 1)
        // })
        // $('.videoCenter .arrow-left').on('click', function(e){
        //     e.preventDefault()
        //     swiperVideo.swipePrev()
        // })
        // $('.videoCenter .arrow-right').on('click', function(e){
        //     e.preventDefault()
        //     swiperVideo.swipeNext()
        // })


        $(".videoCenter .videoCon").each(function(){
            var _video = $(this).find("video.video-js");
            $(this).find(".v-playBtn").click(function(){
                $(this).hide();
                $(this).siblings(".video-js").addClass("active");
                var _src = $(this).attr('data-src');
                _video.attr('autoplay','autoplay');
                _video.attr('src',_src);
                _video.addClass('vjs-playing');
            })
        })

    }

}

function indexBannerSize(){

    var bannerImgObj = $(".dw-cont>img,.indexShowVideo-con>img");		//图片对象
    var winWidth = $(window).width();			//浏览器宽度
    var winHeight = $(window).height();			//浏览器高度

    bannerImgObj.each(function(){
        var _this = $(this);
        //_this.css({"width":"100%","left":"50%"});
        _this.css({"width":"100%"});
        getImageSize(_this.attr("src"),function(w,h){

            var ratio = w/h;					//图片比例
            var showH = winWidth/ratio;			//图片显示高度
            var newW;							//新设置的图片宽度

            if(showH < winHeight){				//图片显示高度小于窗口高度
                newW = winHeight*ratio;
                _this.css({"height":"100%","width":newW});
            }else{
                newW = winWidth;
                _this.css({"width":"100%","height":"auto"});
            }
            //_this.css({"margin-left":"-"+newW/2+"px"});

        })

    });
}

//获取图片尺寸
function getImageSize(url,callback){
    var img = new Image();
    img.src = url;

    // 如果图片被缓存，则直接返回缓存数据
    if(img.complete){
        callback(img.width, img.height);
    }else{
        // 完全加载完毕的事件
        img.onload = function(){
            callback(img.width, img.height);
        }
    }

}

function noticeSlide(){
    $(".txtScroll-top").slide({titCell:".hd ul",mainCell:".bd ul",autoPage:true,effect:"top",autoPlay:true,vis:1});
}
function groupSlide(){
    $(".picMarquee-left1,.picMarquee-left2").slide(
        {
            mainCell:".bd ul",
            autoPlay:true,
            effect:"leftMarquee",
            easing:"swing",
            vis:10,
            interTime:30
        }
    );
    $(".picMarquee-right1").slide(
        {
            mainCell:".bd ul",
            autoPlay:true,
            effect:"leftMarquee",
            easing:"swing",
            vis:10,
            opp:true,
            interTime:30
        }
    );
    imgScroll.rolling({
        name:'g1',
        width:'293px',
        height:'168px',
        direction:'left',
        speed:30,
        addcss:true
    });

    // $(".tempWrap").each(function(){
    //     $(this).find("li").hover(function(){
    //         $(this).find("span").hide();
    //         $(this).find("img").css('z-index','9')
    //     },function(){
    //         $(this).find("span").show();
    //         $(this).find("img").css('z-index','0')
    //     })
    // })
}

function linkConWidth(){
    // var viewWidth=$(window).width();
    $(".nav-link").on('mouseenter',function(){
        var _width = $(".s1-con").width();
        $(".link-slideCon-wrap").width(_width);
    })
    $(".nav-link").on('mouseleave',function(){
        // var _width = $(".s1-con").width();
        $(".link-slideCon-wrap").width(0);
    })

}


function gtBrowser(){
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 7) {
            console.log(fIEVersion)
        } else if(fIEVersion == 8) {
            console.log(fIEVersion)
        } else if(fIEVersion == 9) {
            console.log(fIEVersion)
        } else if(fIEVersion == 10) {
            console.log(fIEVersion)
        } else {
            console.log(fIEVersion)//IE版本<=7
        }
    } else if(isEdge) {
        console.log(isEdge)//edge
    } else if(isIE11) {
        console.log(isIE11) //IE11
    }else{
        // videoSwiper();
        // console.log("不是ie浏览器")//不是ie浏览器
    }
}












