
var pagew = $(document).outerWidth(true) + (window.innerWidth - document.body.clientWidth);
var pageh = $(window).innerHeight();

$(window).on("resizeEnd", function (event) {

    repage();
});


try {
    var loadImg = imagesLoaded("#container");
    loadImg.on("done", function () {

    });

}
catch (e) { }

try {
    $(".topfr .top_user").each(function () {
        $(this).hover(
            function () {
                $(this).find(".top_u_c").stop(true, true).velocity("transition.slideUpIn", { duration: 650 });
            },
            function () {
                $(this).find(".top_u_c").stop(true, true).css({ "display": "none" });
            }
        );
    });
}
catch (e) { }

try {
    var _vstop = $(document).scrollTop();
    var _p1 = $(".page1").offset().top;
    var _p1_h = _p1 + $(".page1").innerHeight();

    var _p2 = $(".page2").offset().top;
    var _p2_h = _p2 + $(".page2").innerHeight();

    var _p3 = $(".page3").offset().top;
    var _p3_h = _p3 + $(".page3").innerHeight();

    $(window).scroll(function () {
        _vstop = $(document).scrollTop();
        animate_fun(_vstop);
        var _left = $(document).scrollLeft()
        $(".wrap").css({ left: -_left })
    })
    animate_fun(_vstop);



}
catch (e) { console.log(e); }




//fupage();


repage();


//
var currPage = -1;
var isshow;
function fupage() {
    try {
        var contNum = $("#container .section").length;
        $("#container").fullpage({
            verticalCentered: false,
            navigation: false,
            autoScrolling: true,
            scrollOverflow: true,
            css3: true,
            easing: 'easeInOutCubic',
            easingcss3: 'ease',
            /* anchors: ['d0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8'],*/
            afterRender: function () {


            },
            afterLoad: function (a, i) {
                currPage = i;
                console.log("b:" + currPage);


                if (currPage == 1) {
                    const p1c_1 = new Letterize({
                        targets: ".p1_c .fl .p1"
                    });

                    var an_01 = anime.timeline({
                        targets: p1c_1.listAll,
                        delay: anime.stagger(50),
                        loop: false
                    });

                    an_01.add({ translateY: -40 });

                    $(".page1 .p1_c p.p2 label").addClass("on");
                    $(".page1 .p1_c p.p3 a").addClass("on");
                    $(".page1 .p1r_c a").each(function (i, e) {
                        var that = $(this);
                        setTimeout(function () {
                            that.addClass("on");
                        }, i * 200);
                    });
                }
                else {
                    $(".page1 .p1_c p.p1 span").css({ "transform": "translateY(0px)" });
                    $(".page1 .p1_c p.p2 label").removeClass("on");
                    $(".page1 .p1_c p.p3 a").removeClass("on");
                    $(".page1 .p1r_c a").removeClass("on");
                }

                if (currPage == 2) {
                    $(".p2c_l p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
                    setTimeout(function () {
                        $(".p2c_l p.p2").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
                    }, 300);

                    $(".p2c_r").addClass("on");

                    $(".p2c_c .p2cc_c ul li label span.sp1").each(function () {
                        countup($(this));
                    });

                    $(".p2ccr_c p.p3 a").addClass("on");

                    $(".p2ccr_c p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
                    $(".p2ccr_c p.p2").stop(true, true).velocity("transition.slideUpIn", { duration: 650 });


                }
                else {
                    $(".p2c_l p.p1").stop(true, true).css({ "opacity": "0" });
                    $(".p2c_l p.p2").stop(true, true).css({ "opacity": "0" });
                    $(".p2c_c .p2cc_c ul li label span.sp1").each(function () {
                        $(this).html("0");
                    });

                    $(".p2c_r").removeClass("on");

                    $(".p2ccr_c p.p3 a").removeClass("on");

                    $(".p2ccr_c p.p1").stop(true, true).css({ "opacity": "0" });
                    $(".p2ccr_c p.p2").stop(true, true).css({ "opacity": "0" });
                }

                if (currPage == 3) {
                    $(".p3c_l p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
                    setTimeout(function () {
                        $(".p3c_l p.p2").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
                    }, 300);
                }
                else {
                    $(".p3c_l p.p1").stop(true, true).css({ "opacity": "0" });
                    $(".p3c_l p.p2").stop(true, true).css({ "opacity": "0" });
                }




            },
            onLeave: function (a, i) {
                currPage = i;
                console.log("a:" + currPage);

            }
        });
    }
    catch (e) { }



}

function repage() {
    pagew = $(document).outerWidth(true) + (window.innerWidth - document.body.clientWidth);
    pageh = $(window).innerHeight();
    document.title = pagew + " * " + pageh;
}



function animate_fun(_vstop) {
    console.log(_vstop + "===" + _p1 + "====" + _p2 + "====" + _p3 + "====" + pageh);
    console.log(_p1_h + "====" + _p2_h + "====" + _p3_h + "====" + pageh + '111');
    _vstop = _vstop + pageh;
    // console.log(_vstop <= _p1_h, _vstop, _p1_h, "_vstop >= 0 && _vstop <= _p1_h")
    if (_vstop >= 0 && _vstop <= _p1_h) {
        if ($(".page1").attr("is") != "1") {
            const p1c_1 = new Letterize({
                targets: ".p1_c .fl .p1"
            });
            var an_01 = anime.timeline({
                targets: p1c_1.listAll,
                delay: anime.stagger(50),
                loop: false
            });
            an_01.add({ translateY: -40 });
            $(".page1 .p1_c p.p2 label").addClass("on");
            $(".page1 .p1_c p.p3 a").addClass("on");
            $(".page1 .p1r_c a").each(function (i, e) {
                var that = $(this);
                setTimeout(function () {
                    that.addClass("on");
                }, i * 200);
            });
            $(".page1").attr({ "is": "1" });
        }
    }

    if (_vstop >= _p2/4 && _vstop <= _p2_h) {
        if ($(".page2").attr("is") != "1") {

            $(".p2c_l p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            setTimeout(function () {
                $(".p2c_l p.p2").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            }, 300);

            $(".p2c_r").addClass("on");

            $(".p2c_c .p2cc_c ul li label span.sp1").each(function () {
                countup($(this));
            });

            $(".p2ccr_c p.p3 a").addClass("on");

            $(".p2ccr_c p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            $(".p2ccr_c p.p2").stop(true, true).velocity("transition.slideUpIn", { duration: 650 });


            $(".page2").attr({ "is": "1" });
        }
    }


    if (_vstop >= _p3/4 && _vstop <= _p3_h) {
        if ($(".page3").attr("is") != "1") {
            $(".p3c_l p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            setTimeout(function () {
                $(".p3c_l p.p2").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            }, 300);
            $(".page3").attr({ "is": "1" });
        }
    }

    if (isMobile() || $(".page1").height() < pageh) {
        if ($(".page1").attr("is") != "1") {
            const p1c_1 = new Letterize({
                targets: ".p1_c .fl .p1"
            });
            var an_01 = anime.timeline({
                targets: p1c_1.listAll,
                delay: anime.stagger(50),
                loop: false
            });
            an_01.add({ translateY: -40 });
            $(".page1 .p1_c p.p2 label").addClass("on");
            $(".page1 .p1_c p.p3 a").addClass("on");
            $(".page1 .p1r_c a").each(function (i, e) {
                var that = $(this);
                setTimeout(function () {
                    that.addClass("on");
                }, i * 200);
            });
            $(".page1").attr({ "is": "1" });
        }

        if ($(".page2").attr("is") != "1") {

            $(".p2c_l p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            setTimeout(function () {
                $(".p2c_l p.p2").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            }, 300);

            $(".p2c_r").addClass("on");

            $(".p2c_c .p2cc_c ul li label span.sp1").each(function () {
                countup($(this));
            });

            $(".p2ccr_c p.p3 a").addClass("on");

            $(".p2ccr_c p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            $(".p2ccr_c p.p2").stop(true, true).velocity("transition.slideUpIn", { duration: 650 });


            $(".page2").attr({ "is": "1" });
        }

        if ($(".page3").attr("is") != "1") {
            $(".p3c_l p.p1").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            setTimeout(function () {
                $(".p3c_l p.p2").stop(true, true).velocity("transition.slideLeftIn", { duration: 650 });
            }, 300);
            $(".page3").attr({ "is": "1" });
        }
    }

}


function isMobile() {
    let userAgentInfo = navigator.userAgent;
    let Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
    let getArr = Agents.filter(i => userAgentInfo.includes(i));
    return getArr.length ? true : false;
}


function countup(_obj) {
    try {
        var settings = {
            'time': 800,
            'delay': 10
        };

        var $this = _obj;
        var $settings = settings;
        if ($this.attr("data-num") != "") {
            $this.data('counterupTo', $this.attr("data-num"));
        }
        if (!$this.data('counterupTo')) {
            $this.data('counterupTo', $this.text());
        }
        var time = parseInt($this.data("counter-time")) > 0 ? parseInt($this.data("counter-time")) : $settings.time;
        var delay = parseInt($this.data("counter-delay")) > 0 ? parseInt($this.data("counter-delay")) : $settings.delay;
        var divisions = time / delay;
        var num = $this.data('counterupTo');
        var nums = [num];
        var isComma = /[0-9]+,[0-9]+/.test(num);
        num = num.replace(/,/g, '');
        var isInt = /^[0-9]+$/.test(num);
        var isFloat = /^[0-9]+\.[0-9]+$/.test(num);
        var decimalPlaces = isFloat ? (num.split('.')[1] || []).length : 0;

        for (var i = divisions; i >= 1; i--) {

            var newNum = parseInt(Math.round(num / divisions * i));

            if (isFloat) {
                newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces);
            }
            if (isComma) {
                while (/(\d+)(\d{3})/.test(newNum.toString())) {
                    newNum = newNum.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
                }
            }

            nums.unshift(newNum);
        }

        $this.data('counterup-nums', nums);
        $this.text('0');

        var f = function () {
            try {
                if ($this.data('counterup-nums') != "") {
                    $this.text($this.data('counterup-nums').shift());
                }

                if ($this.data('counterup-nums').length) {
                    setTimeout($this.data('counterup-func'), delay);
                } else {
                    delete $this.data('counterup-nums');
                    $this.data('counterup-nums', null);
                    $this.data('counterup-func', null);
                }
            }
            catch (e) { }
        };
        $this.data('counterup-func', f);

        setTimeout($this.data('counterup-func'), delay);
    }
    catch (e) { }
}