$(function () {
  // 首页篮球视频 足球视频切换
  if ($(".video-nav").length) {
    $(".video-nav li").click(function () {
      var oIndex = $(this).index();
      $(this).addClass("active").siblings("li").removeClass("active");
      $(".video-cont")
        .eq(oIndex)
        .addClass("show")
        .siblings(".video-cont")
        .removeClass("show");
    });
  }
  // 首页轮播
  if ($(".index-swiper").length) {
    mySwipersyfl = new Swiper(".swiper-container_syfl", {
      autoHeight: true,
      on: {
        slideChangeTransitionStart: function () {
          $(".tabs .default").removeClass("default");
          $(".tabs li").eq(this.activeIndex).addClass("default");
        },
      },
    });
    $(".tabs li").on("click", function (e) {
      e.preventDefault();
      $(".tabs .default").removeClass("default");
      $(this).addClass("default");
      var synum = $(this).index();
      mySwipersyfl.slideTo(synum, 1000, false);
    });
    $(".tabs li").click(function (e) {
      e.preventDefault();
    });
  }

  $(".tip").click(function () {
    $(this).parent().hide();
  });
  if ($(".event-box .event-type").length && $(".top-date").length) {
    // 首页分类吸顶
    $(document).on("scroll", function () {
      var oTop = $(this).scrollTop() - $(".event-cont").eq(0).offset().top;
      if (oTop >= 0) {
        $(".top-box").show();
      } else {
        $(".top-box").hide();
      }
    });
    // 首页筛选
    $(".event-type li").click(function () {
      var oIndex = $(this).index();
      $(".top-box .top-event-type li")
        .eq(oIndex)
        .addClass("active")
        .siblings("li")
        .removeClass("active");
      $(".event-box .event-type li")
        .eq(oIndex)
        .addClass("active")
        .siblings("li")
        .removeClass("active");
      var oType = $(this).attr("data-type");
      $(".event-box").attr("data-type", oType);
      if (oType == 0) {
        $(".event-cont dd").show();
        $(".event-cont dd.datedd").show();
      } else if (oType > 0) {
        $(".event-cont dd.datedd").hide();
        $(".event-cont dd").each(function (i) {
          if ($(".event-cont dd").eq(i).attr("class_one") == oType) {
            $(".event-cont dd").eq(i).show();
            $(".event-cont dd").eq(i).prevAll(".datedd").eq(0).show();
          } else {
            $(".event-cont dd").eq(i).hide();
          }
        });
      } else if (oType < 0) {
        $(".event-cont dd").each(function (i) {
          if ($(".event-cont dd").eq(i).attr("is_important") == 1) {
            $(".event-cont dd").eq(i).show();
            $(".event-cont dd").eq(i).prevAll(".datedd").eq(0).show();
          } else {
            $(".event-cont dd").eq(i).hide();
          }
        });
      }
      if ($(".event-cont .event_cont_dd_new:visible").length <= 0) {
        if ($(".end_ye:visible")) {
          $(".end_ye").hide();
          $(".end_ye").attr("sh", 1);
        }
        $(".nocontent-p").show();
      } else {
        if ($(".end_ye:hidden")) {
          if ($(".end_ye").attr("sh") == 1) {
            $(".end_ye").show();
          }
        }
        $(".nocontent-p").hide();
      }
    });
  }
});
function eventPin(class_one, name_pinyin) {
  if (class_one == 1) {
    return "/zq/zb/" + name_pinyin;
  } else if (class_one == 2) {
    return "/lq/zb/" + name_pinyin;
  } else if (class_one == 3) {
    return "/tiyu/zb/" + name_pinyin;
  }
}
function teamVs(class_one, id) {
  if (class_one == 1) {
    return "/zq/zb/" + id;
  } else if (class_one == 2) {
    return "/lq/zb/" + id;
  } else if (class_one == 3) {
    return "/ty/zb/" + id;
  }
}
function type(oType, eleType, oimport) {
  if (oType == 0) {
    return "block";
  } else if (oType > 0) {
    if (eleType == oType) {
      return "block";
    } else {
      return "none";
    }
  } else if (oType == "-1") {
    if (oimport == 1) {
      return "block";
    } else {
      return "none";
    }
  }
}

// 首页点击加载一天数据
if ($(".more-live-btn").length) {
  $(".more-live-btn").click(function () {
    var d_new;
    var day = $(this).attr("data-day");
    var classid = $(this).attr("data-classid");
    var oType = $(".event-box").attr("data-type");
    var classone = $(this).attr("data-classone");
    var data = {};
    if ($(this).attr("data-classone")) {
      //足篮球
      data = { day: day, class_id: classid, class_one: classone };
    } else {
      //综合
      data = { day: day, class_id: classid };
    }
    if (day != "") {
      $.ajax({
        url: "",
        type: "POST",
        cache: false,
        dataType: "json",
        data: data,
        async: false,
        success: function (res) {
          if (res.code == 0) {
            d_new = res.data.day;
            // $('.event-cont').eq(day).append("<dt>"+res.data.j_date+" "+res.data.week+"</dt>");
            var oArr = res.data.data;
            // if(oArr && oArr.length){
            if (oArr != "") {
              $.each(oArr, function (i) {
                var oDtHtml =
                  "<dd class='clearfix event_cont_dd_new' style='display:" +
                  type(oType, oArr[i].class_one, oArr[i].is_important) +
                  "'  is_important='" +
                  oArr[i].is_important +
                  "' class_one='" +
                  oArr[i].class_one +
                  "' data-mdata='" +
                  oArr[i].match_date +
                  "'><div class='time fl'>" +
                  oArr[i].j_date +
                  "</div><div class='fl right-cont'><div class='cont-t " +
                  (oArr[i].is_important == 0 ? "" : "blodword") +
                  "'><i class='" +
                  (oArr[i].is_important == 0 ? "hide" : "showt") +
                  "'></i><a href='javascript:;'>" +
                  oArr[i].class_id_name +
                  "</a><a href='javascript:;'>" +
                  oArr[i].title_part +
                  "</a></div><div class='cont-b'><a href='" +
                  teamVs(oArr[i].class_one, oArr[i].id) +
                  "'><span class='video'>高清直播</span></a></div></div></dd>";
                // $('.event-cont').eq(day).append(oDtHtml);
                $(".event-cont:last").append(oDtHtml);
              });
              indexDateFn();
            } else {
              $(".event-cont:last").append(
                "<dd>当天暂无<span>" +
                  ($(".breadnav li").eq(1).find("a").html() || "综合体育") +
                  "</span>相关直播</dd>"
              );
              $(".more-live-btn").hide();
            }
          }
        },
      });
      $(this).attr("data-day", d_new);
      /* if(day==6){
              $(this).hide();
          }
          day++;
          $(this).attr('data-day',day); */
    }
  });
}
var arrnewn = [];
function indexDateFn() {
  $(".event-cont .datedd").remove();
  if ($(".event_cont_dd_new").length > 1) {
    $(".event_cont_dd_new").each(function (i, n) {
      arrnewn.push($(n).attr("data-mdata").substring(0, 10));
    });
  }
  arrnewn = arrnewn.deleteEle();

  for (i = -1; i < arrnewn.length; i++) {
    if ($(".event-cont dd[data-mdata^=" + arrnewn[i] + "]").length > 0) {
      var oDHtml =
        "<dd class='datedd'>" +
        arrnewn[i] +
        " " +
        getWeek(arrnewn[i]) +
        "  <div class='zbxhafter'><div class='oneall'></div><div class='twoall'></div><div class='threeall'></div><div class='swiperall'><div class='swiper-container zbxhrswiper'><div class='swiper-wrapper'></div><div class='swiper-pagination'></div></div></div> </div></div></dd>";
      $(".event-cont dd[data-mdata^=" + arrnewn[i] + "]")
        .eq(0)
        .before(oDHtml);
    }
  }
  if ($(".event-cont .event_cont_dd_new:visible").length <= 0) {
    $(".event-cont dd.datedd").hide();
    if ($(".end_ye:visible")) {
      $(".end_ye").hide();
      $(".end_ye").attr("sh", 1);
    }
    $(".nocontent-p").show();
  } else {
    $(".nocontent-p").hide();
    var oTypesh = $(".townavflex_new").find(".active").attr("data-type");
    if (oTypesh > 0) {
      $(".event-cont dd.datedd").hide();
      $(".event-cont .event_cont_dd_new").each(function (i) {
        if (
          $(".event-cont .event_cont_dd_new").eq(i).attr("class_one") == oTypesh
        ) {
          $(".event-cont .event_cont_dd_new")
            .eq(i)
            .prevAll(".datedd")
            .eq(0)
            .show();
        }
      });
    } else if (oTypesh < 0) {
      $(".event-cont dd.datedd").hide();
      $(".event-cont .event_cont_dd_new").each(function (i) {
        if (
          $(".event-cont .event_cont_dd_new").eq(i).attr("is_important") == 1
        ) {
          $(".event-cont .event_cont_dd_new")
            .eq(i)
            .prevAll(".datedd")
            .eq(0)
            .show();
        }
      });
    }
  }
}
function getWeek(dateString) {
  var day = new Date(Date.parse(dateString));
  var today = new Array(
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  );
  var week = today[day.getDay()];
  return week;
}
function searchLink(oVa) {
  var oDress = "http://" + window.location.host + "/bq/ss";
  $.ajax({
    url: oDress,
    type: "POST",
    cache: false,
    dataType: "json",
    data: { name: oVa, action: "2" },
    success: function (r) {
      if (r.code == 0 && r.data) {
        window.location.href =
          "http://" + window.location.host + "/bq/" + r.data.id;
      } else {
        $(".index-box").hide();
        $(".noresul-box").fadeIn();
        setTimeout(function () {
          $(".noresul-box").fadeOut();
        }, 5000);
      }
    },
  });
}
if ($(".search-box").length) {
  $(".searchBtn").click(function () {
    var oVa = $(".searchCont").val();
    searchLink(oVa);
  });
  $(".searchCont").bind("input keyup", function (event) {
    if (event.keyCode == 13) {
      var oVa = $(".searchCont").val();
      searchLink(oVa);
    } else {
      var oVa = $(".searchCont").val();
      var oDress = "http://" + window.location.host + "/bq/ss";
      $.ajax({
        url: oDress,
        type: "POST",
        cache: false,
        dataType: "json",
        data: { name: oVa, action: "1" },
        success: function (r) {
          $(".index-box").html("");
          var dataArr = r.data;
          if (dataArr && dataArr.length) {
            for (i = 0; i < dataArr.length; i++) {
              var oHtml =
                "<li><a href='http://" +
                window.location.host +
                "/bq/" +
                dataArr[i].id +
                "'>" +
                dataArr[i].name +
                "</a></li>";
              $(".index-box").append(oHtml);
            }
            $(".index-box").show();
          } else {
            $(".index-box").hide();
          }
        },
      });
    }
  });
  $(".searchCont").blur(function () {
    setTimeout(function () {
      $(".index-box").hide();
    }, 1000);
  });
}
$(document).scroll(function () {
  if ($(this).scrollTop() >= 300) {
    $(".top-all").show();
  } else {
    $(".top-all").hide();
  }
});
if ($(".nogame").length && $(".time").length) {
  var oTime = $(".nogame div").attr("time") * 1000;
  var oPerTime = new Date().getTime();
  if (oTime - oPerTime > 0) {
    $(".gameover").hide();
    // 未开赛
    setTimeout(function () {
      var oneLoat_n = $(".live-link p").eq(0).attr("data-isonelocal");
      if (oneLoat_n == 1) {
        $(".video-div").show();
        $(".nogame").hide();
        var oHtml =
          "<iframe src='" +
          $(".signal-div p").eq(0).find(".window_local").attr("data-link-url") +
          "' scrolling='no' height='100%' frameborder=0  webkitallowfullscreen=&quot;&quot; mozallowfullscreen=&quot;&quot; allowfullscreen=&quot;&quot; style='width: 1px; min-width: 100%; *width: 100%;'></iframe>";
        $(".iframe-div").append(oHtml);
        $(".iframe-div").css("height", "26rem");
      } else if (oneLoat_n == 0) {
        $(".video-div").show();
        $(".nogame").hide();
        var oHtml =
          "<a href='" +
          $(".live-link p").eq(0).find("a").attr("href") +
          "' target='_blank'><div style='height:100%; background:#2b2b2b; padding:5px; position:relative'><span style='color:#999999;margin-top: .4rem;display: inline-block;'>外部站点赛事，点击跳出按钮观看</span><p style='text-align:center; display: flex; align-items: center; justify-content: center; height:1.9rem; width:11.9rem; color:#fff;-moz-border-radius:1rem;-webkit-border-radius:1rem;border-radius:1rem; position:absolute;top:50%; left:50%;transform: translate(-50%, -50%); background:#de1e30'>点击跳出</p></div></a>";
        $(".iframe-div").append(oHtml);
        $(".iframe-div").css("height", "13rem");
      } else {
        var oHtml =
          "<div style='width: 100%; height: 100%; position: relative'><p><img src='/~static/wap/img/video.png' style='width: 3rem; height: 3rem; position: absolute; left: 50%;top: 50%;transform: translate(-50%,-50%);'></p></div>";
        $(".nogame").append(oHtml);
      }
    }, 200);
  } else if (oTime - oPerTime < 0 && oTime - oPerTime > -10800000) {
    // 已开赛
    $(".nogame").hide();
    $(".gameover").hide();
  } else {
    // 已结束
    $(".nogame").hide();
    $(".gameover").show();
    /* $('.wait_p_no').html('本场直播已结束，信号已失效，请点击查看本 场直播相关资源');
      $('.wait_p_no').parent().css('max-width','70%');
      $('.wait_p_no').css('color','#f46060'); */
    $(".signal_div_con_new").html(
      '<span class="wait-p" style="color:#f46060;display:inline-block;margin-top: .4rem;">本场直播已结束，信号已失效，请点击查看本 场直播相关资源</span>'
    );
    $(".signal_div_con_new").css("max-width", "70%");
  }
}
$(".video_live_relatedAll_new").on("click", "li", function () {
  var oIndex = $(this).index();
  $(".video_live_relatedAll>li").removeClass("active");
  $(".video_live_relatedAll>li").eq(oIndex).addClass("active");
  $(".videocont-div .cont-li").eq(oIndex).show().siblings().hide();
});
Array.prototype.deleteEle = function () {
  var newArr = this;
  for (var i = newArr.length - 1; i >= 0; i--) {
    var targetNode = newArr[i];
    for (var j = 0; j < i; j++) {
      // if(targetNode.attr('data-rowdate') == newArr[j].attr('data-rowdate')){
      if (targetNode == newArr[j]) {
        newArr.splice(i, 1);
        break;
      }
    }
  }
  return newArr;
};
var arrnew = [];
// 首页日期
function indexDateF() {
  $(".event-cont .datedd").remove();
  if ($(".event_cont_dd_new").length > 1) {
    $(".event_cont_dd_new").each(function (i, n) {
      arrnew.push($(n).attr("data-mdata").substring(0, 10));
    });
  }
  arrnew = arrnew.deleteEle();

  for (i = -1; i < arrnew.length; i++) {
    if ($(".event-cont dd[data-mdata^=" + arrnew[i] + "]").length > 0) {
      var oDHtml =
        "<dd class='datedd'>" +
        arrnew[i] +
        "日  直播节目表  <div class='zbxhafter'><div class='oneall'></div><div class='twoall'></div><div class='threeall'></div><div class='swiperall'><div class='swiper-container zbxhrswiper'><div class='swiper-wrapper'></div><div class='swiper-pagination'></div></div></div> </div></div></dd>";
      $(".event-cont dd[data-mdata^=" + arrnew[i] + "]")
        .eq(0)
        .before(oDHtml);
    }
  }
}
if ($(".end_ye").length) {
  indexDateFn();

  var maxnum = 100;
  var dqyeurl = window.location.href;
  var page = 2,
    off_on = false;
  //加载数据
  var matcheListArr = [];
  var classArr = {};
  var teamArr = {};
  function pingjie(data) {
    $(".jiazai_gif").hide();
    matcheListArr = data.matcheDateListArr;
    classArr = data.classArr;
    teamArr = data.teamArr;
    if (teamArr == null && page == 2) {
      maxnum = page;
    }
    if (teamArr == null && page > 2) {
      if ($(".event-cont dd:visible").length <= 0) {
        $(".end_ye").hide();
      } else {
        $(".end_ye").show();
      }
      maxnum = page;
    }

    if (teamArr != null || teamArr != "") {
      off_on = true;
      var dom = "";
      var oTypee = $(".event-type .active").attr("data-type");
      for (var i = 0; i < matcheListArr.length; i++) {
        var impor = classArr[matcheListArr[i].class_id].is_important;
        dom +=
          "<dd class='clearfix event_cont_dd_new' is_important='" +
          impor +
          "' class_one='" +
          matcheListArr[i].class_one +
          "' data-mdata='" +
          matcheListArr[i].match_date.substring(0, 10) +
          "' data-datatime='" +
          matcheListArr[i].match_date +
          "' style='display:" +
          type(oTypee, matcheListArr[i].class_one, impor) +
          "'><div class='time fl'>" +
          matcheListArr[i].match_date.substring(11, 16) +
          "</div><div class='fl right-cont'><div class='cont-t " +
          (impor == 1 ? "blodword" : "") +
          "'>" +
          (impor == 1 ? "<i></i>" : "") +
          "<a href='javascript:;'>" +
          (classArr[matcheListArr[i].class_id].name
            ? classArr[matcheListArr[i].class_id].name
            : classArr[matcheListArr[i].class_id].name_full) +
          "</a><a href='javascript:;'>" +
          matcheListArr[i].title_part +
          "</a></div><div class='cont-b'><a href='" +
          teamVs(matcheListArr[i].class_one, matcheListArr[i].id) +
          "'><span class='video'>高清直播</span></a></div></div><div class='ggone'></div></dd>";
      }
      $(".event-cont").append(dom);
      indexDateFn();
    }
  }
  function LoadingDataFn(ye) {
    $.ajax({
      url: dqyeurl,
      type: "post",
      dataType: "json",
      data: { page: ye },
      success: function (res) {
        pingjie(res);
        // wordIndexWapGg();
      },
      error: function (e) {},
    });
  }

  //初始化， 第一次加载
  $(document).ready(function () {
    LoadingDataFn(page);
  });
  var range = 50;
  var totalheight = 0;
  $(window).scroll(function () {
    var srollPos = $(window).scrollTop();
    totalheight = parseFloat($(window).height()) + parseFloat(srollPos);
    /* if (($(document).height() - range-$('.video-box').height()-$('.pd-box').height()-$('footer').height()) <= totalheight && page != maxnum) { */
    if (
      $(document).height() -
        range -
        $(".video-box").height() -
        $("footer").height() <=
        totalheight &&
      page != maxnum
    ) {
      if (off_on) {
        off_on = false;
        page++;
        $(".jiazai_gif").show();
        LoadingDataFn(page);
      }
    }
  });
}

//首页变色
function tDou(n) {
  return n > 9 ? n : "0" + n;
}
function GetDateStr(AddDayCount) {
  var dd = new Date();
  dd.setDate(dd.getDate() + AddDayCount);
  var y = dd.getFullYear();
  var m = tDou(dd.getMonth() + 1);
  var d = tDou(dd.getDate());
  return [y + "-" + m + "-" + d, m, d];
}
$.extend({
  myTime: {
    CurTime: function () {
      return Date.parse(new Date()) / 1000;
    },
    DateToUnix: function (string) {
      var f = string.split(" ", 2);
      var d = (f[0] ? f[0] : "").split("-", 3);
      var t = (f[1] ? f[1] : "").split(":", 3);
      return (
        new Date(
          parseInt(d[0], 10) || null,
          (parseInt(d[1], 10) || 1) - 1,
          parseInt(d[2], 10) || null,
          parseInt(t[0], 10) || null,
          parseInt(t[1], 10) || null,
          parseInt(t[2], 10) || null
        ).getTime() / 1000
      );
    },
    UnixToDate: function (unixTime, isFull, timeZone) {
      if (typeof timeZone == "number") {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
      }
      var time = new Date(unixTime * 1000);
      var ymdhis = "";
      ymdhis += time.getUTCFullYear() + "-";
      ymdhis += time.getUTCMonth() + 1 + "-";
      ymdhis += time.getUTCDate();
      if (isFull === true) {
        ymdhis += "" + time.getUTCHours() + ":";
        ymdhis += time.getUTCMinutes() + ":";
        ymdhis += time.getUTCSeconds();
      }
      return ymdhis;
    },
  },
});

function zhuangtai() {
  var timestamp = new Date().getTime();
  var divArr = $(".event-cont .event_cont_dd_new");
  $.each(divArr, function (i, n) {
    var bitime = new Date(
      $(n).attr("data-datatime").replace(/-/g, "/")
    ).getTime();
    if (bitime <= timestamp) {
      $(n).find(".video").addClass("zb_red");
    }
  });
}
zhuangtai();
$(document).ready(function () {
  setInterval(zhuangtai, 60000);
});

//战报  上一条下一条检测
if ($(".tb-box").length) {
  var last = $(".tb-box p").eq(0).find("a").html();
  var next = $(".tb-box p").eq(1).find("a").html();
  if (last == "") {
    $(".tb-box p").eq(0).hide();
  }
  if (next == "") {
    $(".tb-box p").eq(1).hide();
  }
}
//检测列表是否为空
if ($("#shipinlist").length) {
  var listnum = $("#shipinlist li").length;
  if (listnum == 1) {
    if ($("#shipinlist li").eq(0).find("a").html() == "") {
      $("#shipinlist").html("<p class='nocontent-p'>当天暂无相关信息</p>");
    }
  }
}
$(".shaixuan_wrap").click(function () {
  $(".mark_wrap").show();
  $("body").css("overflow", "hidden");
  $("body").css("position", "fixed");
});
$(".sx_con_wrap_cos").click(function () {
  $(".mark_wrap").hide();
  $("body").css("overflow", "auto");
  $("body").css("position", "static");
});

function setCookie(name, value) {
  //cookies设置
  var argv = setCookie.arguments;
  var argc = setCookie.arguments.length;
  var expires = argc > 2 ? argv[2] : null;
  if (expires != null) {
    var LargeExpDate = new Date();
    LargeExpDate.setTime(LargeExpDate.getTime() + expires * 1000 * 3600 * 24);
  }
  document.cookie =
    name +
    "=" +
    escape(value) +
    (expires == null ? "" : "; expires=" + LargeExpDate.toGMTString());
}

function getCookie(Name) {
  //cookies读取
  var search = Name + "=";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
    } else return "";
  }
}

var StranLink_Obj = document.getElementById("StranLink");
if (StranLink_Obj) {
  var JF_cn = "ft" + self.location.hostname.toString().replace(/\./g, "");
  var BodyIsFt = getCookie(JF_cn);
  if (BodyIsFt != "1") BodyIsFt = Default_isFT;
  with (StranLink_Obj) {
    if (typeof document.all != "object") {
      //非IE浏览器
      href = "javascript:StranBody()";
    } else {
      href = "javascript:;";
      onclick = new Function("StranBody();return false");
    }
    title = StranText("点击以繁体中文方式浏览", 1, 1);
    innerHTML = StranText(innerHTML, 1, 1);
  }
  if (BodyIsFt == "1") {
    setTimeout("StranBody()", StranIt_Delay);
  }
}

$(function () {
  var wxSwiper = new Swiper(".wuxingss", {
    freeMode: true,
    slidesPerView: "auto",
    freeModeSticky: true,
  });
});
