var isTouch = Modernizr.touch,
	isMobile = false, //区分移动端与PC端
	mobile = false, //区分手机端与平板
	w_width = 0,
	w_height = 0,
	bannerImgh = 638,
	navItem = 0,
	h_height = 0,
	roll = 0,
	sTop = 150,
	produs = 0,
	ST = 0;

var _mousemove;
var _click;
var _mousedown;
var _mouseup;

//移动端事件和PC事件的切换
if (Modernizr.touch) {
	_mousemove = "touchmove";
	_click = "touchend";
	_mousedown = "touchstart";
	_mouseup = "touchend";
} else {
	_mousemove = "mousemove";
	_click = "click";
	_mousedown = "mousedown";
	_mouseup = "mouseup";
};

function pageBox() {
	w_width = jQuery(window).width();
	w_height = jQuery(window).height();


	//设置移动端参数
	if (w_width <= 1024) {
		isMobile = true;
	} else if (w_width > 1024) {
		isMobile = false;
	};
	//区分手机端和平板
	if (w_width <= 640) {
		mobile = true;
	} else if (w_width > 640) {
		mobile = false;
	};
	// var mtop = jQuery('.mtop').height();
	// $('.pbanner figure').css('height', w_height - mtop);
	// setImgMax($('.pbanner figure img'), 1920, 920, w_width, w_height - mtop);
}
pageBox();
jQuery(window).resize(function() {
	pageBox();
});


var pageFn = {
	init:function(){
		this.getLoader();
		this.getHoverNav();
	},
	getLoader: function() {
		window.onload = function() {
			const scroll = new LocomotiveScroll({
				el: document.querySelector('[data-scroll-container]'),
				smooth: !0,
				lerp: .075,
				offset: [-300, -300],
				getSpeed: false
			});

			$("html").css("overflow","visible");

			scroll.on('scroll', (args) => {
				var scrollY = Math.round(args.scroll.y);
				scrollY >= 10 ? $(".header").addClass("scroll") : $(".header").removeClass("scroll");
				jQuery('.article-block').delay(400).scrollClass();
			});
		
			$(".scolltop").click(function() {
				scroll.scrollTo(0);
			});
			$(".core-hidden,.solute-text,.about-swiper,.expert-hidden,.academician-text,.status-hidden").mouseover(function(){
				$(this).scroll(function(){
					scroll.stop();
				});
			});
			
			
			$(".core-hidden,.solute-text,.about-swiper,.expert-hidden,.academician-text,.status-hidden").mouseleave(function () { 
				scroll.start();
			});
		
			$('[data-target]').click(function(e){
				scroll.scrollTo($(this).attr("data-target"));
			});

			var hash = location.search.split("?")[1];
			if(hash){
				scroll.scrollTo('#'+hash);
			}

			$("img.lazy").lazyload({
				effect: "fadeIn",
				threshold: 50, 
				placeholder: "images/loading.gif",
			});
		}	
		if($(".ptext").length> 0){
			var s1 = new TimelineMax();
			s1.fromTo(".pabnner figure img", 6, {scale: 1.15},{scale: 1});
		}
		
		
	},
	getHoverNav: function(){
		$(".navs > li").hover(function(){
			var indexHeight = $(this).find(".navs-menu-wrap").innerHeight();
			var this_ = $(this);
			TweenMax.to(this_.find(".navs-menu"), 0.4, {height: indexHeight});
			
		},function(){
			TweenMax.to($(this).find(".navs-menu"), 0.4, {height:0});
		});

		$(".menubtn").click(function(){
			$(this).toggleClass("active");
			$(".navs__menu").toggleClass("show");
		});

		$(".navs__menu__list > li > a").click(function(){
			$(this).parents("li").find(".navs-menu-leval").slideToggle();
		});
	}
}
pageFn.init();

window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "2", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];

$(function() {
	jQuery('.article-block').delay(500).scrollClass();
});

(function(jQuery) {
	$.fn.scrollClass = function(config) {
		var defaults = {};
		var config = jQuery.extend(defaults, config);
		var target = this;

		function addAction() {
			var length = target.length;
			for (var i = 0; i < length; i++) {
				if (target.eq(i).hasClass('articleShow')) continue;

				var in_position = target.eq(i).offset().top + 100;
				var window_bottom_position = jQuery(window).scrollTop() + jQuery(window).height();
				if (in_position < window_bottom_position) {
					target.eq(i).addClass('articleShow');
				}
			}
		}
		addAction();

		jQuery(window).on('scroll', function() {
			addAction();
		});
		return target;
	};
})(jQuery);

setPopUp($('.weix'), "微信公众号");

function setPopUp(obj, title) {
	obj.click(function() {
		var str = '<div class="popUpblack"><div class="popUp"><div class="t">' + title +
			'<span class="close">关闭</span></div><div class="img"><img src="' + obj.attr("href") + '"/></div></div></div>';
		$("body").append(str);
		jQuery(".popUpblack").fadeIn();
		jQuery(".popUp").animate({
			marginTop: "-127"
		}, 400);
		$(".popUp .close").click(function() {
			$(".popUpblack").remove();
		});
		jQuery(".popUpblack").click(function() {
			$(".popUpblack").remove();
		});
		return false;
	});
};

function setImgMax(img, imgW, imgH, tW, tH) {
	var tWidth = tW || w_width;
	var tHeight = tH || w_height;
	var coe = imgH / imgW;
	var coe2 = tHeight / tWidth;
	if (coe < coe2) {
		var imgWidth = tHeight / coe;
		img.css({
			height: tHeight,
			width: imgWidth,
			left: -(imgWidth - tWidth) / 2,
			top: 0
		});
	} else {
		var imgHeight = tWidth * coe;
		img.css({
			height: imgHeight,
			width: tWidth,
			left: 0,
			top: -(imgHeight - tHeight) / 2
		});
	};

};
