
$(function(){
	$(window).scroll(function(){
		if( $(window).scrollTop() > 50 ){
			$(".hbg").addClass("bg");
		}else{
			$(".hbg").removeClass("bg");
		}
	});	
});

$(function(){
	$(window).scroll(function(){
		if( $(window).scrollTop() > 0 ){
			$(".hbg .product_son").stop(false, false).animate({ top: "70"}, 300);
		}else{
			$(".hbg .product_son").stop(false, false).animate({ top: "90"}, 300);
		}
	});	
});

$(function(){
	$(".hbg .nav ul li:nth-child(3), .hbg .product_son").hover(function(){
	   $(".hbg .product_son").stop(false, false).animate({ top: "90", opacity: "show" }, 300);
	},function(){
	   $(".hbg .product_son").stop(false, false).animate({ top: "90", opacity: "hide" }, 300);
	});
});

$(document).ready(function(){


	$(".hrt a").hover(function(){
		$(this).find(".ewm").stop(true,false).fadeToggle();
	  },function(){
		 $(this).find(".ewm").stop(true,false).fadeToggle();
	  });
  
  });
  
  
var isIEVersion = IEVersion();
$(function(){
    if($(window).scrollTop()==0){
        $("#backTop").hide();
    }
    $(window).scroll(function(){
        if($(window).scrollTop()>0){
            $("#backTop").show();
        }else{
            $("#backTop").hide();
        }
    });
    $("#backTop a").click(function(event) {
        /* Act on the event */
        $("html,body").animate({scrollTop:"0"},666);
        return false;
    });
    $(".page-hd li").on("click",function(){
        var index = $(this).index();
        $(".page-hd li").removeClass("on");
        $(this).addClass("on");
        $(".page-bd .current-list").removeClass("on");
        $(".page-bd .current-list").eq(index).addClass("on");
    });
    $(".total-page").on("click",function(){
        $(".all-page").slideToggle();
    });
    $(".page-tab .close").on("click",function(){
        $(".all-page").slideUp();
    });
    // 判断浏览器是否兼容placeholder属性，不兼容则优雅降级处理
    if(!isSupportPlaceholder()) {
        // 遍历所有input对象, 除了密码框
        $('input').not("input[type='password']").each(
            function() {
                var self = $(this);
                var val = self.attr("placeholder");
                input(self, val);
            }
        );
        $('textarea').each(
            function() {
                var self = $(this);
                var val = self.attr("placeholder");
                input(self, val);
            }
        );
    }
    // 判断浏览器是否支持video标签，不支持，则提示用户下载并使用谷歌浏览器
    isIE8();
    // 判断浏览器是否是ie浏览器，是ie浏览器则分别为
    if(isIEVersion>0){
        $("body").addClass("ie-hack");
        if(isIEVersion <= 10){// 是ie浏览器
            $("body").addClass("ie10-hack");
            if(isIEVersion<=9){
                $("body").addClass("ie9-hack");
                if(isIEVersion<9){
                    $("body").addClass("ie8-hack");
                }
            }
        }
    }
    $(".swiper-tab .swiper-item").on("click",function(){
        var index = $(this).index();
        $(this).addClass("swiper-item-active").siblings().removeClass("swiper-item-active");
        $(".swiper-tab .swiper-slide").eq(index).addClass("swiper-slide-active").siblings().removeClass("swiper-slide-active");
    });
});

function setTab(name,cursel,n){
    for(i=1;i<=n;i++){
     var menu=document.getElementById(name+i);
     var con=document.getElementById("con_"+name+"_"+i);
     menu.className=i==cursel?"hover":"";
       con.style.display=i==cursel?"block":"none";
    }
}

function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 7) {
            return 7;
        } else if(fIEVersion == 8) {
            return 8;
        } else if(fIEVersion == 9) {
            return 9;
        } else if(fIEVersion == 10) {
            return 10;
        } else {
            return 6;//IE版本<=7
        }   
    } else if(isEdge) {
        return 12;//edge
    } else if(isIE11) {
        return 11; //IE11  
    }else{
        return -1;//不是ie浏览器
    }
}

// 判断浏览器是否支持placeholder属性
function isSupportPlaceholder() {
    var input = document.createElement('input');
    return 'placeholder' in input;
}
// jQuery替换placeholder的处理
function input(obj, val) {
    var $input = obj;
    var val = val;
    $input.attr({value:val});
    $input.focus(function() {
        if ($input.val() == val) {
            $(this).attr({value:""});
        }
    }).blur(function() {
        if ($input.val() == "") {
            $(this).attr({value:val});
        }
    });
}

function isIE8() {
    var ie8Html = '<p class="is-ie8"><span><i></i>您的浏览器版本过低，视频无法播放，建议您使用</span><a href="https://www.google.cn/chrome/" target="_blank" title="谷歌浏览器">谷歌浏览器</a></p>';
    if (document.documentMode <= 8) {
        $("video").parent().html(ie8Html);
    }
}
