
// 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();
}

// 转换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 stopScroll(flag){
	if(flag){
		$("body").css("overflow","hidden");
	}else{
		$("body").css("overflow","initial");
	}
}
function backtop(scrollTop){
	var $sticky = $(".back_box");
	if (scrollTop >= 100) {
		if ($sticky.attr("class").indexOf("active") < 0) {
			$sticky.toggleClass("active");
		}
	} else {
		if ($sticky.attr("class").indexOf("active") > -1) {
			$sticky.toggleClass("active");
		}
	}
}
function getConfig (){
	return {
		screenW : $(window).width(),
		screenH : $(window).height(),
		footer : $(".footer_template").offset(),
		headerH : $(".header_template").height(),
		// 
		contentW : $(".sticky_box").width(),
		item : $(".sticky_box").offset(),
		// 
		rightH : $(".sticky_box .right_box").height()
	}
}

function scrollElem(){
	let config = getConfig();
	if(config.screenW > 1000){
		window.onscroll = function(){
			config = getConfig();
			var scrollTop = $(window).scrollTop();
			if(scrollTop >= config.item.top){
				let top = config.screenH - config.rightH;
				$(".sticky_box .right_box").css({"top":config.headerH + "px","right":(config.screenW - config.contentW)/2 + "px"}).addClass("fixed");
				if((config.screenH + scrollTop) > parseInt(config.footer.top) - 276){
					let newTop = parseInt(config.footer.top) - (config.screenH + scrollTop) + top - 276 ;
					$(".sticky_box .right_box").css({"top":newTop + "px"});
				}
			}else{
				$(".sticky_box .right_box").removeClass("fixed");
			}
		}
		
	}
	$(window).resize(function(){
		let config = getConfig();
	    if($(window).width() < 1001){
			$(".sticky_box .right_box").removeClass("fixed");
		}else{
			let top = config.screenH - config.rightH;
			$(".sticky_box .right_box").css({"top":top + "px","right":(config.screenW - config.contentW)/2 + "px"});
		}
	})
}
function initMethod(){}
initMethod.prototype.common = function(){
	var screenW = $(window).width();
	if(screenW < 1000){
		// 打开菜单
		$(".menu_icon").click(function(){
			$(".menu_box").addClass("active");
			stopScroll(true);
		})
		// 菜单关闭
		$(".menu_close").click(function(){
			$(".menu_box").removeClass("active");
			stopScroll(false);
		})
		// 查看下一级
		$(".nav_menu_item").on("click",".arrow",function(e){
			e.preventDefault();
			$(this).parents(".item").find(".drop_menu_box").addClass("active");
		});
		// 返回上一级
		$(".nav_menu_item").on("click",".back_menu",function(e){
			e.preventDefault();
			$(this).parent().removeClass("active");
		})
	}
	$(".router_submenu,.router_modal_template .btn_close").click(function(){
		$(".router_modal_template").toggleClass("active");
	})
	$("#language_select_template p.text").click(function(e){
		e.preventDefault();
		$(".language_select_template").addClass("active");
		// stopScroll(true);
	})
	$(".language_close").click(function(e){
		e.preventDefault();
		$(".language_select_template").removeClass("active");
		// stopScroll(false);
	})
	// 搜索
	$(".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);
	});
	// 昼夜切换
	// $(".day_icon").click(function(){
	// 	$(this).toggleClass("active");
	// 	$("body").toggleClass("active");
	// });
	// 
	$("body").append(`<div class="back_box">
		<ul id="back_tab">
			<li>
				<i class="iconfont icon-ArrowUp-1
"></i>
			</li>
		</ul>
	</div>`);
	$("#back_tab li").click(function(){
	    $("html,body").stop().animate({scrollTop:0},300);
	});
	// 
	// $(".language_select_template").click(function(event){
	// 	event.stopPropagation();
	// 	$(this).toggleClass("active");
	// });
	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");
		}
	});
	window.onscroll = function(){
		var scrollTop = $(window).scrollTop();
		backtop(scrollTop);
	}
}
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(){
	
}
initMethod.prototype.help = function(){
	$(".question_template .item .title").click(function(){
		if($(this).parent().attr("class").indexOf("active") > -1){
			$(this).parent().removeClass("active");
		}else{
			$(this).parent().addClass("active").siblings().removeClass("active");
		}
	});
}

initMethod.prototype.detail = function(){
	var mySwiper = new Swiper('.swiper_xw',{
		observer: true, 
		slidesPerView: "auto",
		spaceBetween: 20,
		grid: {
			fill: 'column',
			rows: 1,
		},
		loop: false,
		autoplay: {
			delay: 2000
		},
		navigation: {
			nextEl: '.swiper-button-next',
			prevEl: '.swiper-button-prev',
		},
		pagination: {
			el: '.swiper-pagination',
		}
	})
	$('.swiper_xw').viewer({
		zoomRatio: 0.8
	});
	this.initCollapseEvent();
	this.help();
	scrollElem();
}


// 底部模块位置设置
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();
// })