$(function(){
	//动态加载头部和尾部
	function showNav() {
	    var urlstr = location.pathname.substr(1);
		var searchStr = location.search
		var menuKey = [
			"index",
			"device",
			"scheme",
			"project",
			"Partner",
			"aboutUs"
		]
		var index = menuKey.findIndex(key=>urlstr.indexOf(key)>-1)
		index = index >= 0 ? index : 0
		$(".header .navbar>li").eq(index).addClass('active').siblings('li').removeClass('active');
		$(".header .subnav li").each(function(){
			var href = $(this).find("a").attr("href")
			if(href == urlstr || (searchStr && href.indexOf(searchStr)>-1)){
				$(this).addClass("active")
			}else{
				$(this).removeClass("active")
			}
		})
	};
	var url = window.location.href;
	$(".header").load("header.html",function(){
		//给栏目加active
		showNav();
		//二级导航
		$(".header .navbar>li").hover(function(){
			$(this).find(".subnav").stop().slideDown();
		},function(){
			$(this).find(".subnav").stop().slideUp(100);
		});
	});
	$(".footer").load("footer.html",function(){
		//返回顶部
		var flagscroll=null;
		$(window).scroll(function(){
			$('.footer .scrolltop').stop().fadeIn();
			if(flagscroll){
				clearTimeout(flagscroll);
			}
			flagscroll=setTimeout(function(){
				$('.footer .scrolltop').stop().fadeOut();
			},2000);
		});
		$('.footer .scrolltop').hover(function(){
			if(flagscroll){
				clearTimeout(flagscroll);
			}
			$('.footer .scrolltop').stop().fadeIn();
		},function(){
			if(flagscroll){
				clearTimeout(flagscroll);
			}
			flagscroll=setTimeout(function(){
				$('.footer .scrolltop').stop().fadeOut();
			},2000);
		})
		$('.footer .scrolltop').click(function(){
			$('html,body').animate({'scrollTop':'0'});
		})
	});
})






