function preloadimages(obj, complete_cb, progress_cb) {
    var loaded = 0;
    var toload = 0;
    var images = obj instanceof Array ? [] : {};
    toload = obj.length;
    for (var i = 0; i < obj.length; i++) {
        images[i] = new Image();
        images[i].src = obj[i];
        console.log(obj[i]);
        images[i].onload = load;
        images[i].setAttribute('crossOrigin', 'anonymous');
        images[i].onerror = load;
        images[i].onabort = load;
    }
    if (obj.length == 0) {
        complete_cb(images);
    }

    function load() {
        ++loaded;
        if (progress_cb) {
            progress_cb(loaded / toload);
        }
        if (loaded >= toload) {
            complete_cb(images);
        }
    }
}

var picUrl = window.base_resource_url + '/image2/';

var preloadImageList = [
    picUrl + 'share.jpg',
];
if ($('div').length > 0) {
    $.each($('div'), function (index, val) {
        var img = $(val).css('background-image').replace(/^url\((['"]?)(.*)\1\)$/, '$2');
        img = $.trim(img);
        if (img && img.match(/[^/]+(jpg|png|gif)$/)) {
            preloadImageList.push(img);
        }
    });
}

const linkAddress = {
    //了解更多请点击
    'link0': 'https://mp.weixin.qq.com/mp/homepage?__biz=MjM5ODA1NzAyMA==&hid=11&sn=54f0bdb2d5bc4a953ac4733e9bd1611a&scene=18',
    //马明哲部署平安集团开年四件大事：加强党建、抗击疫情、决胜脱贫、科技创新
    'link1': 'https://mp.weixin.qq.com/s/7hfzV8z2SaaKtZMQay8Mvw',
    //进展更新 | 总保额1万亿 平安人寿全国送1000万份"E路平安"抗"疫"
    'link2': 'https://mp.weixin.qq.com/s/RjDYhpIKn3PjKeoMwB_x8Q',
    // 新华社：平安医保科技：共抗疫情，打好科技战“疫”组合拳
    'link3': 'https://t.xinhuaapp.com/rR154rZ',
    // 和讯：平安战“疫”打出游击术 医疗科技“侦察兵”助力临床诊断
    'link4': 'https://m.hexun.com/news/2020-02-13/200283704.html?from=groupmessage&isappinstalled=0',
    // 秦朔朋友圈：智慧抗疫：挺进疫区中心的民营健康“黑马”
    'link5': 'https://mp.weixin.qq.com/s/ZfOQsQ37f-NRiT85drgzZw',
    // 新华网：专业抗疫 | 驰援新冠病毒核酸检验，平安旗下医学实验室整装备战！
    'link6': 'http://www.xinhuanet.com/money/2020-02/04/c_1125529659.htm',
    // 中华网：武汉平安好医医学检验实验室正式承接新冠病毒核酸检测服务
    'link7': 'https://m.tech.china.com/redian/2020/0204/459904.html',
    // 搜狐健康：武汉新型肺炎 | 武汉平安好医医学检验实验室承接武汉市新冠病毒核酸检测工作
    'link8': 'https://m.sohu.com/a/370546276_359980/?pvid=000115_3w_a&from=groupmessage&isappinstalled=0',
    // 人民日报：助力早发现，来自上海的移动CT影像车驰援湖北
    'link9': 'https://wap.peopleapp.com/article/5091672/4987004?from=groupmessage&isappinstalled=0',
    // 新华网：奔赴前线 | 平安移动CT影像车驰援武汉，专业医护团队展开多城救援
    'link10': 'http://www.xinhuanet.com/money/2020-02/03/c_1125527240.htm',
    // 健康时报：诊断力不够？移动CT影像车助力新型冠状病毒感染的肺炎诊断
    'link11': 'http://www.jksb.com.cn/index.php?m=wap&a=show&catid=583&id=158821',
    // 中国日报：免费阅片！平安健康（检测）中心70余位专家远程支援新型肺炎影像诊断
    'link12': 'https://cn.chinadaily.com.cn/a/202002/05/WS5e3a63cba3107bb6b579d579.html',
    // 健康报：“平安好影像”助力阻击疫情 科技抗“疫”见成效
    'link13': 'http://www.jkb.com.cn/yzyd/2020/0211/470330.html',
    // 第一财经：科技战疫丨千里之外 我也能为你日夜读片
    'link14': 'https://m.yicai.com/news/100503814.html?from=groupmessage&isappinstalled=0',
    // 新华社：共抗疫情|平安医保科技助力国家卫健委继教中心建设线上教学系统 
    'link15': 'https://t.xinhuaapp.com/rQg80Ss',
    // 健康报：基层疫情防控培训课程上线
    'link16': 'http://share.591adb.com/sharearticle/article/article_id/2977545/app_key/e70891ddafa5e012828c143390cdad9e',
    // 上海证券报：平安医保科技助力国家卫生健康委继教中心建设线上教学系统
    'link17': 'http://news.cnstock.com/news,jg-202002-4488234.htm',
    // 新华社：平安医保科技助力青岛市医保局打造“掌上办”服务 高频事项“不见面办”更方便！
    'link18': 'https://t.xinhuaapp.com/rPHzNGB',
    // 新华网：中国平安联合日本最大医疗检测公司捐赠防疫物资全部配送完毕
    'link19': 'http://www.xinhuanet.com/money/2020-02/03/c_1125527413.htm',
    // 了解更多请点击
    'link20': 'https://mp.weixin.qq.com/mp/homepage?__biz=MzU4OTQ0ODQ5OQ==&hid=7&sn=259750919ccdb2b34a17e2e64d3fb8ea&scene=1&devicetype=iOS12.3.1&version=1700092d&lang=zh_CN&nettype=3G+&ascene=7&session_us=gh_a1afb9b2b88b&fontScale=100&wx_header=1'
};

var readingJson = {};

let play = 'music';
let musicStatus = true;

$('.video1').append('<video controls poster="/Public/static/image2/video1.jpg" webkit-playsinline="webkit-playsinline" playsinline="playsinline" x5-playsinline="x5-playsinline" x-webkit-airplay="allow" src="/Public/static/media/video1.mp4" id="video1"></video>');
$('.video2').append('<video controls poster="/Public/static/image2/video2.jpg" webkit-playsinline="webkit-playsinline" playsinline="playsinline" x5-playsinline="x5-playsinline" x-webkit-airplay="allow" src="/Public/static/media/video2.mp4" id="video2"></video>');
$('.video3').append('<video controls poster="/Public/static/image2/video3.jpg" webkit-playsinline="webkit-playsinline" playsinline="playsinline" x5-playsinline="x5-playsinline" x-webkit-airplay="allow" src="/Public/static/media/video3.mp4" id="video3"></video>');
const video1 = document.getElementById("video1");
const video2 = document.getElementById("video2");
const video3 = document.getElementById("video3");
$('.page1').show();
preloadimages(preloadImageList, function () {}, function (progress) {});





$(document).ready(function () {

    // var EventUtil = {
    //     addHandler: function (element, type, handler) {
    //         if (element.addEventListener) {
    //             element.addEventListener(type, handler, false);
    //         } else if (element.attachEvent) {
    //             element.attachEvent("on" + type, handler);
    //         } else {
    //             element["on" + type] = handler;
    //         }
    //     }
    // };
    // (function () {
    //     EventUtil.addHandler(window, "pageshow", function (event) {
    //         try {
    //             $('#music')[0].play();
    //         } catch (error) {
    //             alert(error)
    //         }
    //     });
    // })();
    for (let i = 0; i < 21; i++) {
        $('.read' + i).hide();
    }
    // reading = getCookie('reading');
    // if (reading != null) {
    //     readingJson = JSON.parse(reading);
    //     for (let key in readingJson) {
    //         $('.read' + key.replace(/link/, "")).show();
    //     }
    // }


    $('.music').click(function () {
        if ($('#music')[0].paused) {
            $('#music')[0].play();
            $('.music.stop').hide();
            $('.music.play').show();
            musicStatus = true;
        } else {
            $('#music')[0].pause();
            $('.music.play').hide();
            $('.music.stop').show();
            musicStatus = false;
        }
    });

    video1.addEventListener('pause', function () {
        if (video1.paused && video2.paused && video3.paused) {
            if (musicStatus) {
                $('#music')[0].play();
            }
        }
    });

    video2.addEventListener('pause', function () {
        if (video1.paused && video2.paused && video3.paused) {
            if (musicStatus) {
                $('#music')[0].play();
            }
        }
    });

    video3.addEventListener('pause', function () {
        if (video1.paused && video2.paused && video3.paused) {
            if (musicStatus) {
                $('#music')[0].play();
            }
        }
    });

    video1.addEventListener('play', function () {
        play = 'video1';
        $('#music')[0].pause();
        musicStatus = false;
        video2.pause();
        videoBreak = true;
        video3.pause();

    });

    video2.addEventListener('play', function () {
        play = 'video2';
        $('#music')[0].pause();
        musicStatus = false;
        video1.pause();
        videoBreak = true;
        video3.pause();
    });

    video3.addEventListener('play', function () {
        play = 'video3';
        $('#music')[0].pause();
        musicStatus = false;
        video1.pause();
        videoBreak = true;
        video2.pause();
    });

    // $('.btn-clear').on('click', function () {
    //     setCookie('reading', '{}');
    // });

    $('.link0').on('click', {
        link: linkAddress.link0,
        index: 0
    }, jumpTolink);

    $('.link1').on('click', {
        link: linkAddress.link1,
        index: 1
    }, jumpTolink);
    $('.link2').on('click', {
        link: linkAddress.link2,
        index: 2
    }, jumpTolink);
    $('.link3').on('click', {
        link: linkAddress.link3,
        index: 3
    }, jumpTolink);
    $('.link4').on('click', {
        link: linkAddress.link4,
        index: 4
    }, jumpTolink);
    $('.link5').on('click', {
        link: linkAddress.link5,
        index: 5
    }, jumpTolink);
    $('.link6').on('click', {
        link: linkAddress.link6,
        index: 6
    }, jumpTolink);
    $('.link7').on('click', {
        link: linkAddress.link7,
        index: 7
    }, jumpTolink);
    $('.link8').on('click', {
        link: linkAddress.link8,
        index: 8
    }, jumpTolink);
    $('.link9').on('click', {
        link: linkAddress.link9,
        index: 9
    }, jumpTolink);
    $('.link10').on('click', {
        link: linkAddress.link10,
        index: 10
    }, jumpTolink);
    $('.link11').on('click', {
        link: linkAddress.link11,
        index: 11
    }, jumpTolink);
    $('.link12').on('click', {
        link: linkAddress.link12,
        index: 12
    }, jumpTolink);
    $('.link13').on('click', {
        link: linkAddress.link13,
        index: 13
    }, jumpTolink);
    $('.link14').on('click', {
        link: linkAddress.link14,
        index: 14
    }, jumpTolink);
    $('.link15').on('click', {
        link: linkAddress.link15,
        index: 15
    }, jumpTolink);
    $('.link16').on('click', {
        link: linkAddress.link16,
        index: 16
    }, jumpTolink);
    $('.link17').on('click', {
        link: linkAddress.link17,
        index: 17
    }, jumpTolink);
    $('.link18').on('click', {
        link: linkAddress.link18,
        index: 18
    }, jumpTolink);
    $('.link19').on('click', {
        link: linkAddress.link19,
        index: 19
    }, jumpTolink);
    $('.link20').on('click', {
        link: linkAddress.link20,
        index: 20
    }, jumpTolink);




    // $('.link0').on('touchstart', {
    //     index: 0
    // }, showRead);

    // $('.link1').on('touchstart', {
    //     index: 1
    // }, showRead);
    // $('.link2').on('touchstart', {
    //     index: 2
    // }, showRead);
    // $('.link3').on('touchstart', {
    //     index: 3
    // }, showRead);
    // $('.link4').on('touchstart', {
    //     index: 4
    // }, showRead);
    // $('.link5').on('touchstart', {
    //     index: 5
    // }, showRead);
    // $('.link6').on('touchstart', {
    //     index: 6
    // }, showRead);
    // $('.link7').on('touchstart', {
    //     index: 7
    // }, showRead);
    // $('.link8').on('touchstart', {
    //     index: 8
    // }, showRead);
    // $('.link9').on('touchstart', {
    //     index: 9
    // }, showRead);
    // $('.link10').on('touchstart', {
    //     index: 10
    // }, showRead);
    // $('.link11').on('touchstart', {
    //     index: 11
    // }, showRead);
    // $('.link12').on('touchstart', {
    //     index: 12
    // }, showRead);
    // $('.link13').on('touchstart', {
    //     index: 13
    // }, showRead);
    // $('.link14').on('touchstart', {
    //     index: 14
    // }, showRead);
    // $('.link15').on('touchstart', {
    //     index: 15
    // }, showRead);
    // $('.link16').on('touchstart', {
    //     index: 16
    // }, showRead);
    // $('.link17').on('touchstart', {
    //     index: 17
    // }, showRead);
    // $('.link18').on('touchstart', {
    //     index: 18
    // }, showRead);
    // $('.link19').on('touchstart', {
    //     index: 19
    // }, showRead);
    // $('.link20').on('touchstart', {
    //     index: 20
    // }, showRead);
});

function jumpTolink(event) {
    const link = event.data.link;
    if (event.data.index || event.data.index == 0) {
        const index = event.data.index;
        // readingJson['link' + index] = 1;
        // setCookie('reading', JSON.stringify(readingJson));
        $('.read' + index).show();
        setTimeout(function () {
            $('.read' + index).hide();
        }, 300);

    }
    setTimeout(function () {
        window.location.href = link;
    }, 100);

}

function showRead(event) {
    const index = event.data.index;
    $('.read' + index).show();
}


function getTranslateDistance(cardinal = 0, abs = false) {
    var wrapInnerTransform = $('.wrap-inner').css('transform');
    var wrapInnertop = parseFloat($('.wrap-inner').css('top'));
    wrapInnerTransform = wrapInnerTransform.match(/^matrix\(1,\s0,\s0,\s1,\s0,\s\-?(\d+)/);
    wrapInnerTransform = parseFloat(wrapInnerTransform[1]);
    if (abs) {
        var wrapInnerjl = Math.abs(wrapInnertop - wrapInnerTransform);
    } else {
        var wrapInnerjl = wrapInnertop - wrapInnerTransform;
    }

    return wrapInnerjl + cardinal + 'px';
}

//获取随机数方法
//min 最小值
//max 最大值
function RandomNumBoth(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}

//写cookies

function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//读取cookies
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}