/*! superSlide */
!function(e){e.fn.slide=function(t){return e.fn.slide.defaults={type:"slide",effect:"fade",autoPlay:!1,delayTime:500,interTime:2500,triggerTime:150,defaultIndex:0,titCell:".hd li",mainCell:".bd",targetCell:null,trigger:"mouseover",scroll:1,vis:1,titOnClassName:"on",autoPage:!1,prevCell:".prev",nextCell:".next",pageStateCell:".pageState",opp:!1,pnLoop:!0,easing:"swing",startFun:null,endFun:null,switchLoad:null,playStateCell:".playState",mouseOverStop:!0,defaultPlay:!0,returnDefault:!1},this.each(function(){var a,n=e.extend({},e.fn.slide.defaults,t),i=e(this),s=n.effect,r=e(n.prevCell,i),o=e(n.nextCell,i),u=e(n.pageStateCell,i),l=e(n.playStateCell,i),c=e(n.titCell,i),f=c.size(),p=e(n.mainCell,i),d=p.children().size(),h=n.switchLoad,v=e(n.targetCell,i),m=parseInt(n.defaultIndex),g=parseInt(n.delayTime),w=parseInt(n.interTime),I=(parseInt(n.triggerTime),parseInt(n.scroll)),M=parseInt(n.vis),C="false"!=n.autoPlay&&0!=n.autoPlay,y="false"!=n.opp&&0!=n.opp,x="false"!=n.autoPage&&0!=n.autoPage,O="false"!=n.pnLoop&&0!=n.pnLoop,b="false"!=n.mouseOverStop&&0!=n.mouseOverStop,q="false"!=n.defaultPlay&&0!=n.defaultPlay,k="false"!=n.returnDefault&&0!=n.returnDefault,P=0,Q=0,S=0,T=0,L=n.easing,j=null,B=null,D=null,F=n.titOnClassName,E=c.index(i.find("."+F)),W=m=-1==E?m:E,z=m,A=m,N=d>=M?d%I!=0?d%I:I:0,U="leftMarquee"==s||"topMarquee"==s,H=function(){e.isFunction(n.startFun)&&n.startFun(m,f,i,e(n.titCell,i),p,v,r,o)},$=function(){e.isFunction(n.endFun)&&n.endFun(m,f,i,e(n.titCell,i),p,v,r,o)},G=function(){c.removeClass(F),q&&c.eq(z).addClass(F)};if("menu"==n.type)return q&&c.removeClass(F).eq(m).addClass(F),c.hover(function(){a=e(this).find(n.targetCell);var t=c.index(e(this));B=setTimeout(function(){switch(m=t,c.removeClass(F).eq(m).addClass(F),H(),s){case"fade":a.stop(!0,!0).animate({opacity:"show"},g,L,$);break;case"slideDown":a.stop(!0,!0).animate({height:"show"},g,L,$)}},n.triggerTime)},function(){switch(clearTimeout(B),s){case"fade":a.animate({opacity:"hide"},g,L);break;case"slideDown":a.animate({height:"hide"},g,L)}}),void(k&&i.hover(function(){clearTimeout(D)},function(){D=setTimeout(G,g)}));if(0==f&&(f=d),U&&(f=2),x){if(d>=M)if("leftLoop"==s||"topLoop"==s)f=d%I!=0?1+(d/I^0):d/I;else{var J=d-M;f=1+parseInt(J%I!=0?J/I+1:J/I),f<=0&&(f=1)}else f=1;c.html("");var K="";if(1==n.autoPage||"true"==n.autoPage)for(var R=0;R<f;R++)K+="<li>"+(R+1)+"</li>";else for(var R=0;R<f;R++)K+=n.autoPage.replace("$",R+1);c.html(K);var c=c.children()}if(d>=M){p.children().each(function(){e(this).width()>S&&(S=e(this).width(),Q=e(this).outerWidth(!0)),e(this).height()>T&&(T=e(this).height(),P=e(this).outerHeight(!0))});var V=p.children(),X=function(){for(var e=0;e<M;e++)V.eq(e).clone().addClass("clone").appendTo(p);for(var e=0;e<N;e++)V.eq(d-e-1).clone().addClass("clone").prependTo(p)};switch(s){case"fold":p.css({position:"relative",width:Q,height:P}).children().css({position:"absolute",width:S,left:0,top:0,display:"none"});break;case"top":p.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; height:'+M*P+'px"></div>').css({top:-m*I*P,position:"relative",padding:"0",margin:"0"}).children().css({height:T});break;case"left":p.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; width:'+M*Q+'px"></div>').css({width:d*Q,left:-m*I*Q,position:"relative",overflow:"hidden",padding:"0",margin:"0"}).children().css({float:"left",width:S});break;case"leftLoop":case"leftMarquee":X(),p.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; width:'+M*Q+'px"></div>').css({width:(d+M+N)*Q,position:"relative",overflow:"hidden",padding:"0",margin:"0",left:-(N+m*I)*Q}).children().css({float:"left",width:S});break;case"topLoop":case"topMarquee":X(),p.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; height:'+M*P+'px"></div>').css({height:(d+M+N)*P,position:"relative",padding:"0",margin:"0",top:-(N+m*I)*P}).children().css({height:T})}}var Y=function(e){var t=e*I;return e==f?t=d:-1==e&&d%I!=0&&(t=-d%I),t},Z=function(t){var a=function(a){for(var n=a;n<M+a;n++)t.eq(n).find("img["+h+"]").each(function(){var t=e(this);if(t.attr("src",t.attr(h)).removeAttr(h),p.find(".clone")[0])for(var a=p.children(),n=0;n<a.size();n++)a.eq(n).find("img["+h+"]").each(function(){e(this).attr(h)==t.attr("src")&&e(this).attr("src",e(this).attr(h)).removeAttr(h)})})};switch(s){case"fade":case"fold":case"top":case"left":case"slideDown":a(m*I);break;case"leftLoop":case"topLoop":a(N+Y(A));break;case"leftMarquee":case"topMarquee":var n="leftMarquee"==s?p.css("left").replace("px",""):p.css("top").replace("px",""),i="leftMarquee"==s?Q:P,r=N;if(n%i!=0){var o=Math.abs(n/i^0);r=1==m?N+o:N+o-1}a(r)}},_=function(e){if(!q||W!=m||e||U){if(U?m>=1?m=1:m<=0&&(m=0):(A=m,m>=f?m=0:m<0&&(m=f-1)),H(),null!=h&&Z(p.children()),v[0]&&(a=v.eq(m),null!=h&&Z(v),"slideDown"==s?(v.not(a).stop(!0,!0).slideUp(g),a.slideDown(g,L,function(){p[0]||$()})):(v.not(a).stop(!0,!0).hide(),a.animate({opacity:"show"},g,function(){p[0]||$()}))),d>=M)switch(s){case"fade":p.children().stop(!0,!0).eq(m).animate({opacity:"show"},g,L,function(){$()}).siblings().hide();break;case"fold":p.children().stop(!0,!0).eq(m).animate({opacity:"show"},g,L,function(){$()}).siblings().animate({opacity:"hide"},g,L);break;case"top":p.stop(!0,!1).animate({top:-m*I*P},g,L,function(){$()});break;case"left":p.stop(!0,!1).animate({left:-m*I*Q},g,L,function(){$()});break;case"leftLoop":var t=A;p.stop(!0,!0).animate({left:-(Y(A)+N)*Q},g,L,function(){t<=-1?p.css("left",-(N+(f-1)*I)*Q):t>=f&&p.css("left",-N*Q),$()});break;case"topLoop":var t=A;p.stop(!0,!0).animate({top:-(Y(A)+N)*P},g,L,function(){t<=-1?p.css("top",-(N+(f-1)*I)*P):t>=f&&p.css("top",-N*P),$()});break;case"leftMarquee":var n=p.css("left").replace("px","");0==m?p.animate({left:++n},0,function(){p.css("left").replace("px","")>=0&&p.css("left",-d*Q)}):p.animate({left:--n},0,function(){p.css("left").replace("px","")<=-(d+N)*Q&&p.css("left",-N*Q)});break;case"topMarquee":var i=p.css("top").replace("px","");0==m?p.animate({top:++i},0,function(){p.css("top").replace("px","")>=0&&p.css("top",-d*P)}):p.animate({top:--i},0,function(){p.css("top").replace("px","")<=-(d+N)*P&&p.css("top",-N*P)})}c.removeClass(F).eq(m).addClass(F),W=m,O||(o.removeClass("nextStop"),r.removeClass("prevStop"),0==m&&r.addClass("prevStop"),m==f-1&&o.addClass("nextStop")),u.html("<span>"+(m+1)+"</span>/"+f)}};q&&_(!0),k&&i.hover(function(){clearTimeout(D)},function(){D=setTimeout(function(){m=z,q?_():"slideDown"==s?a.slideUp(g,G):a.animate({opacity:"hide"},g,G),W=m},300)});var ee=function(e){j=setInterval(function(){if(i.hasClass("pause"))return!1;y?m--:m++,_()},e||w)},te=function(e){j=setInterval(_,e||w)},ae=function(){b||(clearInterval(j),ee())},ne=function(){(O||m!=f-1)&&(m++,_(),U||ae())},ie=function(){(O||0!=m)&&(m--,_(),U||ae())},se=function(){clearInterval(j),U?te():ee(),l.removeClass("pauseState")},re=function(){clearInterval(j),l.addClass("pauseState")};if(C?U?(y?m--:m++,te(),b&&p.hover(re,se)):(ee(),b&&i.hover(re,se)):(U&&(y?m--:m++),l.addClass("pauseState")),l.click(function(){l.hasClass("pauseState")?se():re()}),"mouseover"==n.trigger?c.hover(function(){var e=c.index(this);B=setTimeout(function(){m=e,_(),ae()},n.triggerTime)},function(){clearTimeout(B)}):c.click(function(){m=c.index(this),_(),ae()}),U){if(o.mousedown(ne),r.mousedown(ie),O){var oe,ue=function(){oe=setTimeout(function(){clearInterval(j),te(w/10^0)},150)},le=function(){clearTimeout(oe),clearInterval(j),te()};o.mousedown(ue),o.mouseup(le),r.mousedown(ue),r.mouseup(le)}"mouseover"==n.trigger&&(o.hover(ne,function(){}),r.hover(ie,function(){}))}else o.click(ne),r.click(ie)})}}(jQuery),jQuery.easing.jswing=jQuery.easing.swing,jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,t,a,n,i){return jQuery.easing[jQuery.easing.def](e,t,a,n,i)},easeInQuad:function(e,t,a,n,i){return n*(t/=i)*t+a},easeOutQuad:function(e,t,a,n,i){return-n*(t/=i)*(t-2)+a},easeInOutQuad:function(e,t,a,n,i){return(t/=i/2)<1?n/2*t*t+a:-n/2*(--t*(t-2)-1)+a},easeInCubic:function(e,t,a,n,i){return n*(t/=i)*t*t+a},easeOutCubic:function(e,t,a,n,i){return n*((t=t/i-1)*t*t+1)+a},easeInOutCubic:function(e,t,a,n,i){return(t/=i/2)<1?n/2*t*t*t+a:n/2*((t-=2)*t*t+2)+a},easeInQuart:function(e,t,a,n,i){return n*(t/=i)*t*t*t+a},easeOutQuart:function(e,t,a,n,i){return-n*((t=t/i-1)*t*t*t-1)+a},easeInOutQuart:function(e,t,a,n,i){return(t/=i/2)<1?n/2*t*t*t*t+a:-n/2*((t-=2)*t*t*t-2)+a},easeInQuint:function(e,t,a,n,i){return n*(t/=i)*t*t*t*t+a},easeOutQuint:function(e,t,a,n,i){return n*((t=t/i-1)*t*t*t*t+1)+a},easeInOutQuint:function(e,t,a,n,i){return(t/=i/2)<1?n/2*t*t*t*t*t+a:n/2*((t-=2)*t*t*t*t+2)+a},easeInSine:function(e,t,a,n,i){return-n*Math.cos(t/i*(Math.PI/2))+n+a},easeOutSine:function(e,t,a,n,i){return n*Math.sin(t/i*(Math.PI/2))+a},easeInOutSine:function(e,t,a,n,i){return-n/2*(Math.cos(Math.PI*t/i)-1)+a},easeInExpo:function(e,t,a,n,i){return 0==t?a:n*Math.pow(2,10*(t/i-1))+a},easeOutExpo:function(e,t,a,n,i){return t==i?a+n:n*(1-Math.pow(2,-10*t/i))+a},easeInOutExpo:function(e,t,a,n,i){return 0==t?a:t==i?a+n:(t/=i/2)<1?n/2*Math.pow(2,10*(t-1))+a:n/2*(2-Math.pow(2,-10*--t))+a},easeInCirc:function(e,t,a,n,i){return-n*(Math.sqrt(1-(t/=i)*t)-1)+a},easeOutCirc:function(e,t,a,n,i){return n*Math.sqrt(1-(t=t/i-1)*t)+a},easeInOutCirc:function(e,t,a,n,i){return(t/=i/2)<1?-n/2*(Math.sqrt(1-t*t)-1)+a:n/2*(Math.sqrt(1-(t-=2)*t)+1)+a},easeInElastic:function(e,t,a,n,i){var s=1.70158,r=0,o=n;if(0==t)return a;if(1==(t/=i))return a+n;if(r||(r=.3*i),o<Math.abs(n)){o=n;var s=r/4}else var s=r/(2*Math.PI)*Math.asin(n/o);return-o*Math.pow(2,10*(t-=1))*Math.sin((t*i-s)*(2*Math.PI)/r)+a},easeOutElastic:function(e,t,a,n,i){var s=1.70158,r=0,o=n;if(0==t)return a;if(1==(t/=i))return a+n;if(r||(r=.3*i),o<Math.abs(n)){o=n;var s=r/4}else var s=r/(2*Math.PI)*Math.asin(n/o);return o*Math.pow(2,-10*t)*Math.sin((t*i-s)*(2*Math.PI)/r)+n+a},easeInOutElastic:function(e,t,a,n,i){var s=1.70158,r=0,o=n;if(0==t)return a;if(2==(t/=i/2))return a+n;if(r||(r=i*(.3*1.5)),o<Math.abs(n)){o=n;var s=r/4}else var s=r/(2*Math.PI)*Math.asin(n/o);return t<1?o*Math.pow(2,10*(t-=1))*Math.sin((t*i-s)*(2*Math.PI)/r)*-.5+a:o*Math.pow(2,-10*(t-=1))*Math.sin((t*i-s)*(2*Math.PI)/r)*.5+n+a},easeInBack:function(e,t,a,n,i,s){return void 0==s&&(s=1.70158),n*(t/=i)*t*((s+1)*t-s)+a},easeOutBack:function(e,t,a,n,i,s){return void 0==s&&(s=1.70158),n*((t=t/i-1)*t*((s+1)*t+s)+1)+a},easeInOutBack:function(e,t,a,n,i,s){return void 0==s&&(s=1.70158),(t/=i/2)<1?n/2*(t*t*((1+(s*=1.525))*t-s))+a:n/2*((t-=2)*t*((1+(s*=1.525))*t+s)+2)+a},easeInBounce:function(e,t,a,n,i){return n-jQuery.easing.easeOutBounce(e,i-t,0,n,i)+a},easeOutBounce:function(e,t,a,n,i){return(t/=i)<1/2.75?n*(7.5625*t*t)+a:t<2/2.75?n*(7.5625*(t-=1.5/2.75)*t+.75)+a:t<2.5/2.75?n*(7.5625*(t-=2.25/2.75)*t+.9375)+a:n*(7.5625*(t-=2.625/2.75)*t+.984375)+a},easeInOutBounce:function(e,t,a,n,i){return t<i/2?.5*jQuery.easing.easeInBounce(e,2*t,0,n,i)+a:.5*jQuery.easing.easeOutBounce(e,2*t-i,0,n,i)+.5*n+a}});

// flexible.js
var uAgent = window.navigator.userAgent
  , isIOS = uAgent.match(/iphone/i)
  , isYIXIN = uAgent.match(/yixin/i)
  , is2345 = uAgent.match(/Mb2345/i)
  , ishaosou = uAgent.match(/mso_app/i)
  , isSogou = uAgent.match(/sogoumobilebrowser/gi)
  , isLiebao = uAgent.match(/liebaofast/i)
  , isGnbr = uAgent.match(/GNBR/i)
  , $fixed = document.getElementById("fixed");
function resizeRoot() {
    var e, i = screen.width > 0 && (window.innerWidth >= screen.width || 0 == window.innerWidth) ? screen.width : window.innerWidth, n = screen.height > 0 && (window.innerHeight >= screen.height || 0 == window.innerHeight) ? screen.height : window.innerHeight;
    window.devicePixelRatio && window.devicePixelRatio,
    isIOS && (i = screen.width,
    n = screen.height),
    i > n && (i = n),
    (e = (e = i > 1080 ? 144 : i / 7.5) > 32 ? e : 32) > 100 && (e = 100),
    window.screenWidth_ = i,
    isYIXIN || is2345 || ishaosou || isSogou || isLiebao || isGnbr ? setTimeout(function() {
        i = 0 < screen.width && (window.innerWidth >= screen.width || 0 == window.innerWidth) ? screen.width : window.innerWidth,
        n = 0 < screen.height && (window.innerHeight >= screen.height || 0 == window.innerHeight) ? screen.height : window.innerHeight,
        e = 32 < (e = 1080 < i ? 144 : i / 7.5) ? e : 32,
        document.getElementsByTagName("html")[0].style.fontSize = e + "px",
        $fixed && ($fixed.style.display = "none")
    }, 500) : (document.getElementsByTagName("html")[0].style.fontSize = e + "px",
    $fixed && ($fixed.style.display = "none"))
}

resizeRoot();
window.onresize = function() {
    resizeRoot();
}

// PC滚动定位
function HomeScroll(a, b, width) {
	var height = $(".header_template").height();
    function g() {
        var g = $(window).scrollLeft(), h = $(window).scrollTop(), i = $(document).height(), j = $(window).height(),
            k = c.height(), l = d.height(), m = k > l ? f : e, n = k > l ? d : c,
            o = k > l ? (c.offset().left + c.outerWidth(!0) - g) + width : (d.offset().left - c.outerWidth(!0) - g) - width,
            p = k > l ? l : k, q = k > l ? k : l, r = parseInt(q - j) - parseInt(p - j);
            console.log(o);
        $(a + "," + b).removeAttr("style"), j > i || p > q || m > h || p - j + m >= h ? n.removeAttr("style") : j > p && h - m >= r || p > j && h - m >= q - j ? n.attr("style", "margin-top:" + r + "px;") : n.attr("style", "_margin-top:" + (h - m) + "px;position:fixed;left:" + o + "px;" + (j > p ? "top" : "bottom") + ":"+height+"px;")
    }

    if ($(a).length > 0 && $(b).length > 0) {
        var c = $(a), d = $(b), e = c.offset().top, f = d.offset().top;
        $(window).resize(g).scroll(g).trigger("resize")
    }
}

function switchClass(clickElem,switchElem,flag){
    $(clickElem).click(function(){
        var className = $(this).attr("class");
        if(className && className.indexOf("active") > -1) return false
        $(this).addClass("active").siblings().removeClass("active");
        var index = $(this).index();
        if(flag){
            if(index == 0){
                $(switchElem).show();
            }else{
                $(switchElem).eq(index).show().siblings().hide();
            }
        }else{
            $(switchElem).eq(index).addClass("active").siblings().removeClass("active");
        }
    })
}

function initMethod(){}
initMethod.prototype.common = function(){
	var screenW = $(window).width();
	if(screenW <= 999){
		$(".mobile_menu").click(function(){
			$(".menu_box").addClass("active");
			$(".bg_tempalte").addClass("active");
			$(".language_select_template").addClass("open");
		})
		$(".nav_menu_item .item").click(function(){
			$(this).toggleClass("active").siblings().removeClass("active");
		})
		$(".menu_close,.menu_bg").click(function(){
			$(".menu_box").removeClass("active");
			$(".bg_tempalte").removeClass("active");
			$(".language_select_template").removeClass("open");
		})
		// 搜索
		$(".search_icon").click(function(){
			$(".search_modal_template").toggleClass("active");
			stopScroll(true);
		});
		$(".search_modal_template .btn_close").click(function(){
			$(".search_modal_template").removeClass("active");
			stopScroll(false);
		});
	}
	$(".language_select_template").click(function(event){
		event.stopPropagation();
		$(this).toggleClass("active");
		if($(this).attr("class").indexOf("active") > -1){
			if(screenW <= 999){
				//$(".drop_menu_arrow_icon span").text("返回菜单");
			}
		}else{
			//$(".drop_menu_arrow_icon span").text("语言选择");
		}
	});
	document.addEventListener('click', function(event) {
		let popup = document.getElementById("language_select_template");
		// 检查点击事件的目标是否为弹窗及其子元素之外
		if (popup && event.target !== popup && !popup.contains(event.target)) {
			$(".language_select_template").removeClass("active");
			//$(".drop_menu_arrow_icon span").text("语言选择");
		}
		// 没有标识
		let className = $(event.target).attr("class");
		let iscmt = className && className.indexOf("mt_parent") < 0;
		if(iscmt){
			$(".cmt_parent").removeClass("show");
		}
		
	});
}
initMethod.prototype.initCollapseEvent = function(){
	$(".more_version_btn").click(function(){
		var className = $(this).prev().attr("class");
		if(className && className.indexOf("active") > -1) {
			$(this).text($(this).data("more"));
		}else{
			$(this).text($(this).data("less"));
		}
		$(this).prev().toggleClass("active");
	})
}
// 首页
initMethod.prototype.index = function(){
    var mySwiper = new Swiper('.swiper_banner', {
        loop: true, // 循环模式选项
        speed: 500,
        navigation: {
            nextEl: '.swiper_banner .swiper-button-next',
            prevEl: '.swiper_banner .swiper-button-prev',
        },
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },
    })
}

initMethod.prototype.pageSwiper = function(num){
    var mySwiper = new Swiper('.swiper_xw',{
        slidesPerView: num,
        spaceBetween: num == 1?0:10,
        grid: {
            fill: 'column',
            rows: 1,
        },
		loop: true,
		autoplay: {
			delay: 2000
		},
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        pagination: {
            el: '.swiper-pagination',
        },
    })
}
// 下载页
initMethod.prototype.download = function(num){
	if(document.body.clientWidth >= 999) {
	    commonMethod.pageSwiper("auto");
	    HomeScroll(".xzld_html .main_box .left_box",".xzld_html .main_box .right_box",20);
	}else{
	    commonMethod.pageSwiper("auto");
	}
	this.initCollapseEvent();
	$(".cmt_parent").on("click",function(){
		$(".cmt_parent").removeClass("show");
		$(this).toggleClass("show");
	})
}
// 下载落地页
initMethod.prototype.downloadList = function(num){
	commonMethod.pageSwiper("auto");
	this.initCollapseEvent();
}
// 文章落地页
initMethod.prototype.article = function(num){
	if(document.body.clientWidth >= 999) {
	    commonMethod.pageSwiper(4);
	}
	$(".collapse_page_template .text").click(function() {
		$(this).find(".collapse_span").toggleClass("active");
		$(this).parents(".collapse_page_template").toggleClass("active");
	});
	$("#backtop").click(function(){
		$('body,html').animate({scrollTop:0},300);
	})
}

// 文章列表页
initMethod.prototype.articleList = function(){
	this.pageSwiper("auto");
	this.initCollapseEvent();
}

// 排行榜
initMethod.prototype.ranking = function(){
	var menuSwiper = new Swiper('.scroll_menu_list', {
	    slidesPerView: "auto",
	});
	commonMethod.downloadList();
	$(".more_ranking").click(function(){
		$(".right_box").addClass("fixed");
	})
	$(".right_box").click(function(){
		$(".right_box").removeClass("fixed");
	})
	$(".ranking_close").click(function(){
		event.stopPropagation();
		$(".right_box").removeClass("fixed");
	})
}

initMethod.prototype.comment = function(){
	
	$("#theme_remark").click(function(){
		// 假设你想滚动到Element 2
		var targetOffset = $('#form_default').offset().top - 300;
		 
		$('html, body').animate({
		  scrollTop: targetOffset
		}, 1000); // 动画时长1000ms
	})
	
	$(".cmt_parent").on("click",function(){
		$(".cmt_parent").removeClass("show");
		$(this).toggleClass("show");
	})
	
	$("#collapse_comment").click(function(){
		var className = $(this).prev().attr("class");
		if(className && className.indexOf("active") > -1) {
			$(this).find("span").text($(this).data("more"));
		}else{
			$(this).find("span").text($(this).data("less"));
		}
		$(this).prev().toggleClass("active");
	})
	
	// 新建评论
	window.startComment = function(_this) {
		var id = $(_this).parent().data("id");
		var $parent = $(_this).parents(".time").parent();
		if($parent.find("#form_"+id).length > 0){
			$parent.find("#form_"+id).remove();
		}else{
			var textareaHtml = `<div class="comment_form" id="form_${id}">
									<form onsubmit="return submitForm(this)">
										<input type="hidden" name="id" value="form_${id}"/>
										<textarea name="content" oninput="autoResizeTextarea(this)" placeholder="理性发言,友善互动"></textarea>
										<div class="comment_btn">
											<button type="button" class="comment_release">发布</button>
										</div>
									</form>
								</div>`;
			$(_this).parents(".time").after(textareaHtml);
		}
		event.stopPropagation();
	}
	// 转换json
	function convertUrlToJson(url) {
	  // 将参数字符串以'&'分割，并转换为数组
	  const params = url.split('&');
	  // 将参数数组转换为对象
	  const paramsObj = params.reduce((obj, pair) => {
	    const [key, value] = pair.split('=');
	    obj[key] = decodeURIComponent(value || '');
	    return obj;
	  }, {});
	  return paramsObj;
	}
	function ajaxAddHtml (){
		commentHtml = `<div class="comment_list">
							<div class="user_img">
								<img src="${item}" alt="">
							</div>
							<div class="content">
								<div class="user_name">
									<span class="name">${item}</span>
									<span class="name superior">${item}</span>
								</div>
								<p class="info">${item}</p>
								<div class="time">
									<span class="user">珍, 2024/2/21</span>
									<div class="stats" data-id="456">
										<span class="remark"  onclick="startComment(this)">回复</span>
										<span class="like" data-type="good" onclick="reqEvaluate(this)">${item}</span>
										<span class="dislike" data-type="fail" onclick="reqEvaluate(this)">${item}</span>
									</div>
								</div>
							</div>
						</div>`;
	}
	window.submitForm = function(_this) {
		event.preventDefault(); // 阻止表单的默认提交行为
		
		var serializedData = $(_this).serialize();
		var jsonData = convertUrlToJson(serializedData);
		// action="http://app.jieji.net/api/product"
		$.ajax({
		    url: "", // 你要请求的 URL
		    type: "post",
			data :jsonData,
		    dataType: "json", // 指定为 jsonp 类型
			beforeSend:function(){
				$("#spinning").show();
			},
		    success: function(response) {
				if(response.status == 1){
					ajaxAddHtml(response.data);
					showMessage("评论成功",1);
				}else{
					showMessage(response.msg,2);
				}
				$("#spinning").hide();
		    },
		    error: function(jqXHR, textStatus, errorThrown) {
		        console.log('JSONP request failed: ' + textStatus);
		    },
			complete:function(){
				$("#spinning").hide();
			}
		});
	}
	
	// 高度自适应
	window.autoResizeTextarea = function(_this) {
	  _this.style.height = 'inherit'; // 重置高度以获取内容的正确高度
	  _this.style.height = _this.scrollHeight + 'px'; // 设置实际高度
	  if(_this.value.length > 0){
		  if($(_this).parent().find("button").prop("type") == "submit") return;
		  $(_this).parent().find("button").prop("type","submit");
	  }else{
		  $(_this).parent().find("button").prop("type","button");
	  }
	}
	
	function showMessage(text, type) {
		if ($('#alert_message').length <= 0) {
			let styleCss = `<style>
					.alert_message{position: fixed;pointer-events: none;top: 8px;width: 100%;z-index: 1010;text-align: center;}
					.alert_message .text{
						position: relative;top: 0px;display: inline-block;color: #000;font-size: 16px;font-weight: 500;padding: 10px 15px;border-radius: 3px;background-color: #fff;border: 1px solid #eee;opacity: 0;
						transition: opacity 0.3s, transform 0.3s, visibility 0.3s;visibility: hidden;
					}
					.alert_message.success .text{color: #6ADC98;border: 1px solid #9AD766;}
					.alert_message.error .text{color: #e4393c;}
					.alert_message.show .text{opacity: 1;visibility: visible;transform: translateY(80px);}
					.alert_message.hide .text{opacity: 0; visibility: hidden;transform: translateY(10px);}
					</style>`
			$("body").append(`${styleCss}<div id="alert_message" class="alert_message">
													<div class="text"></div>
												</div>
												<div class="spinning" id="spinning">
													<span class="spin_box">
														<i class="spin_item"></i>
														<i class="spin_item"></i>
														<i class="spin_item"></i>
														<i class="spin_item"></i>
													</span>
												</div>`);
		}
		var className = type == 1 ? "alert_message show success" : "alert_message show error";
		$('#alert_message').attr("class", className).find(".text").text(text);
	
		// 3秒后隐藏消息
		setTimeout(function() {
			$('#alert_message').addClass('hide').removeClass('show');
		}, 3000);
	}
	
	function loading (type) {
		if ($('#spinning').length <= 0) {
			let styleCss = `<style>
				 	.spinning{display: none;position: fixed;background-color: rgba(0,0,0,.5);z-index: 1000;left: 0;top: 0;right: 0;bottom: 0;}.spinning .spin_box{left: 50%;margin: -10px;position: absolute;top: 50%;animation: antRotate 1.2s linear infinite;transform: rotate(0deg);}.spinning .spin_box .spin_item{background-color: #ff5151;border-radius: 100%;display: block;width: 12px;height: 12px;opacity: .3;position: absolute;transform: scale(.75);transform-origin: 50% 50%;margin: 0;animation: antSpinMove 1s linear infinite alternate;}.spinning .spin_box .spin_item:nth-child(1){left: 0;top: 0;}.spinning .spin_box .spin_item:nth-child(2){animation-delay: .4s;right: 0;top: 0;}.spinning .spin_box .spin_item:nth-child(3){animation-delay: .8s;bottom: 0;right: 0;}.spinning .spin_box .spin_item:nth-child(4){animation-delay: 1.2s;bottom: 0;left: 0;}@keyframes antRotate {to {transform: rotate(360deg)}}@keyframes antSpinMove {to {opacity: 1}}
				 	</style>`
			$("body").append(`${styleCss}
					<div class="spinning" id="spinning">
						<span class="spin_box">
							<i class="spin_item"></i>
							<i class="spin_item"></i>
							<i class="spin_item"></i>
							<i class="spin_item"></i>
						</span>
						<div style="left: 50%;position: absolute;top: 51%;font-size: 16px;transform: translateX(-50%);color: #fff;" class="loading-text"></div>
					</div>`);
		}
		if (type == "show") {
			$("#spinning").show();
		} else {
			$("#spinning").hide();
		}
	}
	function loadingUpdateText(text) {
		$("#spinning .loading-text").text(text);
	}
	// 喜欢like 不喜欢dislike
	function reqEvaluate(_this) {
		$(_this).toggleClass("active");
		var id = $(_this).parent().data("id");
		var type = $(_this).data("type");
		// type good/fail
		var url = type == "like" ? "":"";
		$.ajax({
			url: "127.0.01?type="+url, // 你要请求的 URL
			type: "post",
			data: {
				id: id
			},
			beforeSend: function() {
				loading("show");
			},
			success: function(response) {
				// 提交成功
				if (response.code == 1) {
					// 隐藏loading
					loading("hide");
				} else {
					showMessage(response.msg, 2);
					$(_this).toggleClass("active");
				}
			},
			error: function(jqXHR, textStatus, errorThrown) {
				showMessage(errorThrown, 2);
				loading("hide");
				$(_this).toggleClass("active");
			},
			complete: function() {
			}
		});
	}
	
	// 组装html
	function mergeCommentHtml(data){
		var statusHtml = '<span class="remark"  onclick="startComment(this)">回复</span>';
		var commentHtml = "";
		for (var i=0; i<data.length;i++) {
			var item = data[i];
			if(i == 0){
				statusHtml = '';
			}
			commentHtml += `<div class="comment_list">
								<div class="user_img">
									<img src="${item}" alt="">
								</div>
								<div class="content">
									<div class="user_name">
										<span class="name">${item}</span>
										<span class="name superior">${item}</span>
									</div>
									<p class="info">${item}</p>
									<div class="time">
										<span class="user">珍, 2024/2/21</span>
										<div class="stats" data-id="456">
											<span class="dislike" data-type="fail" onclick="reqEvaluate(this)">${item}</span>
											${statusHtml}
										</div>
									</div>
								</div>
							</div>`;
		}
		return commentHtml;
		
	}
	
	// 加载数据
	function reqCommentById(id){
		$.ajax({
			url: "127.0.01?type=", // 你要请求的 URL
			type: "post",
			data: {
				id: id
			},
			dataType:"json",
			beforeSend: function() {
				loading("show");
			},
			success: function(response) {
				// 提交成功
				if (response.code == 1) {
					
					$(".comment_list_template").html(mergeCommentHtml(response.data));
					$("body").toggleClass("active");
					// 隐藏loading
					loading("hide");
				} else {
					showMessage(response.msg, 2);
				}
			},
			error: function(jqXHR, textStatus, errorThrown) {
				showMessage(errorThrown, 2);
				loading("hide");
			},
			complete: function() {
			}
		});
	}
}

// 底部模块位置设置
var $footer = $(".footer_template");
$footer.after("<div id='location_ele'></div>");
initMethod.prototype.footerPosition = function(){
    var screenH = $(window).height();
    var footerT = $("#location_ele").offset().top;
    if(footerT < screenH){
        $footer.addClass("sticky");
    }else{
        $footer.removeClass("sticky");
    }
}

var commonMethod = new initMethod()
commonMethod.common();
commonMethod.footerPosition();
$(window).resize(function(){
    commonMethod.footerPosition();
})