/**
 * Created by UICUT.com on 2016/12/31.
 * Contact QQ: 215611388
 */
// jQuery(".js_banner").slide({
//   mainCell: ".bd ul",
//   autoPlay: true
// });
 /*jQuery(".js_bannerLeft.banner41").slide({
   mainCell: ".bd ul",
   effect: "leftLoop",
     trigger: "click"
 });*/

jQuery(".js_bannerLeft.banner41").slide({mainCell:".bd ul",autoPlay:true});

jQuery(".js_slideTxtBox").slide();
jQuery(".js_picScrollLeft").slide({
  mainCell: ".bd ul",
  autoPage: true,
  effect: "left",
  autoPlay: true,
  vis: 3,
  trigger: "click"
});
$(function () {

    $('ul.menu li').hover(function(){
        $('.lidiv',this).show();
        $('.lia',this).addClass("cana");
    },function(){
        $('.lidiv',this).hide();
        $('.lia',this).removeClass("cana");
    });

    $('.sort .GetRequest').each(function () {
        var v=parseInt($(this).attr('value'));
        if(v>9){
            $(this).children("img").attr("src","/Public/Home/images/arrow-top.png");
        }else{
            $(this).children("img").attr("src","/Public/Home/images/arrow-down.png");
        }
    });

    //热销榜收缩
    var hotFlag = 0;
    $(".hotList").on("mouseenter", function(){
        console.log("鼠标移入")
        if(hotFlag == 0){
            console.log("展开")
            $(".hotList").animate({height:'669px'},300);
            hotFlag = 1;
        }

    })
    $(".hotList").on("mouseleave", function(){
        console.log("鼠标移出")

        if(hotFlag == 1){
            console.log("收缩")
            $(".hotList").animate({height:'67px'},300);
            hotFlag = 0;
        }
    })


    //规格图片放入大图

    $(".icon").click(function(){
        var imgNorm = this.src;
          $(".banner-box .bd li").eq(0).find("img").attr("src",imgNorm);
    });

    // 视频播放
    var goodVideo = document.getElementById('good-video');

    //点击小图片放入大图
    $(".banner91 .hd li").click(function(){

         //console.log($(this).index())

        if($(this).index() == 0){
            console.log("======  点击第一张")
            $(".banner-box .bd li").eq(0).show().siblings().hide();

            if($(".banner-box .bd li").eq(0).has('video').length > 0){
                console.log("======  点击第一张，且第一张是视频")
                $("#good-video").show().siblings().hide();
                goodVideo.play();
                goodVideo.setAttribute('autoplay', true);
                document.getElementById("good-video").controls = true;
                //$(".h-video-text").hide();
            }else {
                console.log("======  点击第一张，且第一张不是视频")
                var imgNorm1 = $(this).find("img")[0].src;
                console.log(imgNorm1)
                console.log(1111)
                $(".banner-box .bd li").eq($(this).index()).find("img").attr("src",imgNorm1);
            }

        }else {
            console.log("点击非第一张图片")
            $("#good-video").hide().siblings().show();
            if(goodVideo){
                goodVideo.setAttribute('autoplay', false);
                document.getElementById("good-video").controls = false;
                goodVideo.currentTime = 0;    //属性设置或返回音频/视频播放的当前位置（以秒计）。当设置该属性时，播放会跳跃到指定的位置。
                goodVideo.pause();

            }

            var imgNorm1 = $(this).find("img")[0].src;

            $(".banner-box .bd li").eq($(this).index()).show().siblings().hide();
            $(".banner-box .bd li").eq($(this).index()).find("img").attr("src",imgNorm1);
        }
    });

    //  直接点击大图播放按钮
    $(".h-video-text").click(function(){
        $(this).hide();
        document.getElementById("good-video").controls = true;
        //$(this).parents(".h-bd-videoBox").addClass("h-hover")
        goodVideo.play();

    });

    //  直接点击大图暂停按钮
    $(".h-bd-pause").click(function(){
        $(this).parents(".h-bd-videoBox").removeClass("h-hover")
        $(".h-bd-play").show();
        goodVideo.pause();

    });





  // 通用：弹框关闭
  $(document).on('click', '.alert .btn-close,.alert .over-close,.alert .js_btn-cancle', function (event) {
    event.preventDefault();
    $(this).parents(".alert").fadeOut('300', function () {
      $(this).removeClass('show');
    });
  });
  $("body").on('click', '.radio', function (event) {
    event.preventDefault();
    $(this).addClass('on').siblings().removeClass('on');
  }); // 代理版代码




  $("body").on('click', '.demoTest .filter .item', function (event) {
    event.preventDefault();

    if (!$(this).hasClass('on')) {
      $(this).addClass('on').siblings().removeClass('on');
      $('.demoTest .details .con').css({
        display: 'none'
      }).eq($(this).index()).css({
        display: 'block'
      });
    }
  });
});
$(window).resize(function () {
  // 窗口变换刷新页面
  if ($("body").hasClass('resizeFresh')) {
    location.reload();
  }
});
$(window).scroll(function (event) {
  var scrT = $(document).scrollTop();
  var winH = $(window).height();
  var fH = $("footer").height();
  var docH = $(document).height();

  if (scrT > 205 && $("g-side-menu").height() < docH - scrT - winH - fH / 3) {
    $(".g-side-menu").addClass('fixedTop');
  } else {
    $(".g-side-menu").removeClass('fixedTop');
  }
});
function checkUpScrolling() {
    if ($(window).scrollTop() + $(window).height() + 1 >= $(document).height()) {
        getListData();
    }
}
/**
 * 后台JS主入口
 */
var layer = layui.layer,
    laydate = layui.laydate,
    form = layui.form();


$(function () {

    /**
     * 通用表单提交(AJAX方式)
     */
    form.on('submit(*)', function (data) {
        $.ajax({
            url: data.form.action,
            type: data.form.method,
            data: $(data.form).serialize(),
            success: function (data) {
                if (data.status === 1) {
                    setTimeout(function () {
                        location.href = data.url;
                    }, 1500);
                }
                if(data.info){
                  layer.msg(data.info);
                }
            }
        });
        return false;
    });

    /**
     * 通用单个处理
     */
    $('.ajax-get').on('click', function () {
        var that = this;
        var _href = $(this).attr('href');
        layer.open({
            shade: false,
            content: '确定执行该操作吗？',
            btn: ['确定', '取消'],
            move: false,
            yes: function (index) {
                $.ajax({
                    url: _href,
                    type: "get",
                    success: function (data) {
                        if (data.status === 1) {
                            if(data.info){
                              layer.msg(data.info);
                            }
                            setTimeout(function () {
                                if (data.url) {
                                    location.href = data.url;
                                } else if ($(that).hasClass('no-refresh')) {

                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            if(data.info){
                              layer.msg(data.info);
                            }
                            setTimeout(function () {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }
                    }
                });
                layer.close(index);
            }
        });
        return false;
    });

     /**
     * 通用单个处理没提示
     */
    $('.ajax-mit').on('click', function () {
        var that = this;
        var _href = $(this).attr('href');
        $.ajax({
            url: _href,
            type: "get",
            success: function (data) {
                if (data.status === 1) {
                    layer.msg(data.info);
                    setTimeout(function () {
                        if (data.url) {
                            location.href = data.url;
                        } else if ($(that).hasClass('no-refresh')) {

                        } else {
                            location.reload();
                        }
                    }, 1500);
                } else {
                    layer.msg(data.info);
                    setTimeout(function () {
                        if (data.url) {
                            location.href = data.url;
                        }
                    }, 1500);
                }
            }
        });
        return false;
    });
    /**
     * 通用批量处理
     */
    $('.ajax-action').on('click', function () {
        var that = this;
        var _action = $(this).data('action');
        layer.open({
            shade: false,
            content: '确定执行此操作？',
            btn: ['确定', '取消'],
            move: false,
            yes: function (index) {
                $.ajax({
                    url: _action,
                    data: $('.ajax-form').serialize(),
                    success: function (data) {
                        if (data.status === 1) {
                            if(data.info){
                              layer.msg(data.info);
                            }
                            setTimeout(function () {
                                if (data.url) {
                                    location.href = data.url;
                                } else if ($(that).hasClass('no-refresh')) {

                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            if(data.info){
                              layer.msg(data.info);
                            }
                            setTimeout(function () {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }
                    }
                });
                layer.close(index);
            }
        });
        return false;
    });

    /**
     * 通用全选
     */
    $('.check-all').on('click', function () {
        $(this).parents('table').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
    });

    /**
     * 清除缓存
     */
    $('#clear-cache').on('click', function () {
        var _url = $(this).data('url');
        if (_url !== 'undefined') {
            $.ajax({
                url: _url,
                success: function (data) {
                    if (data.status === 1) {
                        setTimeout(function () {
                            location.href = location.pathname;
                        }, 1000);
                    }
                    layer.msg(data.info);
                }
            });
        }
        return false;
    });


});
  /**
   * 默认的cookie写入方法
   * @param name
   * @param value
   */
  function setCookie(name,value){
      var Days = 1;
      var exp = new Date();
      exp.setTime(exp.getTime() + Days*24*60*60*1000);
      document.cookie = name + "="+ encodeURI (value) + ";expires=" + exp.toGMTString()+";path=/";
  }
  /**
   * 获取Cookie中的值
   * @param objName
   * @returns
   */
  function getCookie(objName){//获取指定名称的cookie的值 
      var arrStr = document.cookie.split("; ");
      for (var i = 0; i < arrStr.length; i++) { 
          var temp = arrStr[i].split("="); 
          if (temp[0] == objName){ 
              return decodeURI(temp[1]); 
          }
      } 
  }

function jump_link(){
    var page = $('#page').val();
    if(page != ''){
        var url = $('#page').attr('url');
        url = url.replace(/%5BPAGE%5D/, page)
        location.href = url;
    }

}