var u = navigator.userAgent;
var sysAndroid = false;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
    sysAndroid = true;
}
if (u.match(/AppleWebKit.*Mobile.*/) || u.match(/IEMobile/) || u.match(/Windows Phone/) || u.match(/Android/) || u.match(/iPhone/) || u.match(/iPad/)) {
    //匹配手机a

    var link = document.createElement('link');
    link.setAttribute("rel", "stylesheet");
    link.setAttribute("type", "text/css");
    link.setAttribute("href", "/bazhepu/css/wap.css");
    document.head.appendChild(link)
    var isMobile = true;


}
window.onload = function () {

    //频道顶部三图 替换高清图片
    var list_toutiao = document.getElementsByClassName('list_toutiao');
    if (list_toutiao.length != 0) {
        var list_toutiao_a = list_toutiao[0].getElementsByTagName('a');
        for (var i = 0; i < list_toutiao_a.length; i++) {
            var aUrl = list_toutiao_a[i].style.backgroundImage;
            aUrl = aUrl.replace(/_S/gi, '');
            list_toutiao_a[i].style.backgroundImage = aUrl;
        }
    }

    //取随机数
    function random(start, range) {
        return parseInt(Math.random() * range + start);
    }
    if (isMobile) {
        /**导航 */
        var navIcon = document.getElementsByClassName('hongbao')[0];
        var nav = document.getElementById('nav-warp');
        navIcon.onclick = function (res) {
            nav.style.display = 'block';
            document.body.style.overflow = 'hidden';
            nav.scrollTop = 0;
            return false;
        }
        nav.onclick = function () {
            this.style.display = 'none'
            document.body.style.overflow = 'auto'
        }



    } else {
        /**导航 */
        var nav = document.getElementById('nav-warp');
        var a = nav.getElementsByTagName('a');


        if (typeof (pageType) != 'undefined' && pageType.split(':')[0] == 'nr') {


            var div = document.createElement('div');
            var content = document.getElementById('content');
            var top = content.appendChild(div);
            top.id = 'toTop'
            top.className = 'toTop';


            //返回顶部
            var toTop = document.getElementById('toTop');
            var footer = document.getElementsByTagName('footer')[0];
            var footerHeight = footer.offsetHeight;
            var scrollTop = document.body.scrollTop || document.documentElement.scrollTop




            if (scrollTop > 0) {
                toTop.style.transform = 'scale(1)';
            } else {
                toTop.style.transform = 'scale(0)';
            }
            toTop.onclick = function () {
                var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
                var top = document.documentElement.scrollTop;
                if (scrollTop != 0) {
                    var time = setInterval(function () {
                        top = top * 0.95;
                        document.body.scrollTop = document.documentElement.scrollTop = top;
                        if (top <= 1) {
                            top = 0;
                            clearInterval(time)
                        }
                    })
                }
                toTop.style.transform = 'scale(1)';
            }
            window.onscroll = function () {
                var scrollTop = document.body.scrollTop || document.documentElement.scrollTop
                if (scrollTop > 0) {
                    toTop.style.transform = 'scale(1)';
                } else {
                    toTop.style.transform = 'scale(0)';
                }
            }
        }
    }

if (isMobile) {

        window.onscroll = scrollFixed

        scrollFixed()

        function scrollFixed() {
            var screenHeight = document.documentElement.clientHeight;
            var scrollHeight = document.documentElement.scrollHeight;
            var scrollTop = document.documentElement.scrollTop;

            if ((screenHeight + scrollTop) == scrollHeight && wz_list_arr != undefined) {
                //addArt(wz_list_arr)
                if (pageType.split(':')[1] == 'index' || pageType.split(':')[1] == 'list') {
                    addArt(wz_list_arr)
                }
            }
        }

    } else {
        var nav = document.getElementById('nav-warp');
        var nav_a = nav.getElementsByTagName('a');
        var tempDiv = document.createElement('div');

        for (var i = nav_a.length - 1; i > 0; i--) {
            if (i > 8) {
                tempDiv.appendChild(nav_a[nav_a.length - 1]);
            }
        }
        var tempSpan = document.createElement('span');
        tempSpan.innerHTML = '更多>>'

        nav.appendChild(tempSpan);
        nav.appendChild(tempDiv);
        tempSpan.onmouseenter = nav_enter;
        tempSpan.onmouseleave = nav_out;
        tempDiv.onmouseenter = nav_enter;
        tempDiv.onmouseleave = nav_out;


        function nav_enter() {
            tempDiv.className = 'show';
        }

        function nav_out() {
            tempDiv.className = '';
        }



        window.onscroll = scrollFixed

        scrollFixed()

        function scrollFixed() {
            var screenHeight = document.documentElement.clientHeight;
            var scrollHeight = document.documentElement.scrollHeight;
            var scrollTop = document.documentElement.scrollTop;
            var topHeight = 106;
            var nav = document.getElementById('nav-warp');
            var aside = document.getElementsByClassName('right_list')[0];
            if (scrollTop > topHeight) {
                nav.style.position = 'relative';
                nav.style.top = scrollTop - topHeight + 10 + 'px';
                aside.style.position = 'relative';
                aside.style.top = scrollTop - topHeight + 10 + 'px';
            } else {
                nav.style.top = 0;
                aside.style.top = 0;
            }
            if ((screenHeight + scrollTop) == scrollHeight && wz_list_arr != undefined) {
                //addArt(wz_list_arr)


                if (pageType.split(':')[0] == 'nr' || pageType.split(':')[1] == 'index' || pageType.split(':')[1] == 'list') {
                    addArt(wz_list_arr)
                }


            }
        }



    }

    var artList;
    var countNum = 0;
    var wz_list = document.getElementsByClassName('wz_list')[0];
    var wz_list_arr
    //}


    var right_list = document.getElementsByClassName('rl_nr')[0];
    var right_list_arr;
    var change_jy = document.getElementsByClassName('change_jy')[0];

}





