require(["./logRegPop", "./shareWx", "./swiper.min"], function (logRegPop, shareWx) {

    shareWx({
        title: "逛CJ领好礼  超霸伐木累福利大放送",
        desc: "邓超送了我一份大礼，你们也想要吗？",
        picUrl: "http://huodong.37.com/mir/20160722/static/images/css/images/share_logo.png",
        url: "huodong.37.com/dist/mir/20160722/"
    });

    var login = logRegPop({
        // bg: "rgba(0,0,0,.2)", 
        // isBindPhone: true, //默认true;      
        game_id: 275,
        gameName: "传奇霸业",
        giftName: "传奇霸业",
        gameUrl: "http://www.37.com/xylz/", // 游戏官网链接;         
        giftUrl: "http://hdapi.37.com/?c=auto_get_gift&a=get_gift&alias_info=cqbycjh520160723",
        alias: "cqbycjh520160723",
        lr: function (u) {
            //console.log(u)
        } // 登录注册后的回调; 
    });

    var main = {
        init: function () {
            this._imgLoad();
            this.evt();
        },
        fullpage: function () {
            $("#topBar").show();

            var ts = this,
                $direction = $("#direction"),
                pagecount = $(".section").length - 1;
            $("#loading-box").fadeOut("slow", function () {
                $("#container").show();
                var swiper = new Swiper('.swiper-box', {
                    pagination: '.swiper-pagination',
                    slidesPerView: 3,
                    paginationClickable: true,
                    grabCursor: true,
                    spaceBetween: 0,
                    loop: true,
                    onSlideChangeEnd: function (swiper) {
                        var index = +$(".swiper-slide").eq(swiper.activeIndex).next().data("swiper-slide-index");
                        index++;
                        $(".slide-tip .img").removeClass().addClass("img img" + index);
                    }
                });
                $("#fullWrap").fullpage({
                    continuousVertical: false,
                    controlArrowColor: "#E45E40",
                    slidesNavPosition: "bottom",
                    onLeave: function (index, nextindex, direction) {
                        if (index === pagecount && direction === "down") {
                            $direction.hide();
                        } else {
                            $direction.show();
                        }
                    }
                });
            });
        },
        evt: function () {
            $(".get-gift").on("click", function (e) {
                e.preventDefault();
                login.show();
            });
            var $vbox = $(".video-box"),
                $ly = $(".layout").height($(window).height()),
                v_html = '<video height="100%" width="100%" src="http://video.37wanimg.com/mir/20160726/zt-20160726.mp4" controls="true"></video>';
            $vbox.on("click", "i", function (e) {
                e.preventDefault();
                $vbox.html(v_html);
                $ly.show();
            });
            $ly.on("touchstart", function () {
                $(this).hide();
                $vbox.html('<i class="bg"></i>');
            });
        },
        /**
         * 图片加载器
         * @return {[type]} [description]
         */
        _imgLoad: function () {
            var that = this,
                $loadText = $("#loading-text"),
                $loadBox = $("#line-box"),
                imgList = [
                    __uri("../css/images/bg.jpg"),
                    __uri("../css/images/bg_1.jpg"),
                    __uri("../css/images/getGift_b.png"),
                    __uri("../css/images/getGift.png"),
                    __uri("../css/images/text_1.png"),
                    __uri("../css/images/text_2.png"),
                    __uri("../css/images/text_3.png"),
                    __uri("../css/images/text_4.png"),
                    __uri("../css/images/text_5.png"),
                    __uri("../css/images/role_1.jpg"),
                    __uri("../css/images/role_2.jpg"),
                    __uri("../css/images/role_3.jpg"),
                    __uri("../css/images/role_4.jpg"),
                    __uri("../css/images/role_5.jpg")
                ],
                loadedCount = 0,
                len = imgList.length,
                doLoad = function (url) {
                    var img = new Image();
                    img.onload = function () {
                        ++loadedCount;
                        $loadText.text(parseInt((loadedCount / len) * 100) + "%");
                        $loadBox.width(parseInt((loadedCount / len) * 160));
                        //图片加载完成
                        if (loadedCount === (len - 1)) {
                            that.fullpage();
                        }
                    };
                    img.src = url;
                };

            imgList.forEach(function (item) {
                doLoad(item);
            });

        }
    };

    main.init();
});