

$(function () {

	$(".btn_menu").click(function () {
		if ($(".xs_nav").css("display") == "none") {
			$(this).addClass("on");
			$(".xs_nav").slideDown();

		}
		else {
			$(this).removeClass("on");
			$(".xs_nav").slideUp();
		}
	})

	//头部小栏目显示
	$(".xs_nav .nav-item").each(function (i, e) {
		var li_len = $(e).find("ul li").length;
		if (li_len > 0) {
			$(e).find(".title .drop-btn").show();

			$(e).find(".title a").click(function () {
				if ($(e).find("ul").is(":hidden")) {
					$(".xs_nav .nav-item").find("ul").slideUp();
					$(e).find("ul").slideDown();
					$(e).addClass("open").siblings().removeClass("open");

					return false;
				} else {
					$(e).find("ul").slideUp();
					$(e).removeClass("open")
					$(e).siblings().find("ul").slideUp();
					return false;
				}
			})

		}
		$(e).find(".drop-btn").click(function () {
			if ($(e).find("ul").is(":hidden")) {
				$(".xs_nav .nav-item").find("ul").slideUp();
				$(e).find("ul").slideDown();
				$(e).addClass("open");
				$(e).addClass("open").siblings().removeClass("open");


			} else {
				$(e).find("ul").slideUp();
				$(e).removeClass("open")
			}
		})
	})

	//显示搜索
	$(".shbox").click(function () {
		$(".sh_bkg").show();
		$(".sh_box").show();
	});
	$(".sh_box .close").click(function () {
		$(".sh_bkg").hide();
		$(".sh_box").hide();
	});
	$(".shbtn").click(function () {
		$(".sh_bkg").show();
		$(".sh_box").show();
	});


	if($("#ban_swiper").length>0){
		var ban_swiper = new Swiper('#ban_swiper',{
			//pagination: {
			//	el: '.swiper-pagination',
			//	clickable: true,
			//},
			autoplay: {
				delay: 6000,
				stopOnLastSlide: false,
				disableOnInteraction: true,
			},
			navigation: {
				nextEl: ".swiper-button-next",
				prevEl: ".swiper-button-prev",
			},
		})
	}
	
	if($("#news_swiper").length>0){
		var news_swiper = new Swiper('#news_swiper',{
			pagination: {
			    el: '.swiper-pagination',
				clickable :true,
			},
			autoplay: {
				delay: 10000,
				stopOnLastSlide: false,
				disableOnInteraction: true,
			},
			
		})
	}
	
	if($(".in_news").length>0){
		$(".in_news .title_box ul li").eq(0).addClass("on").siblings().removeClass("on");
		var more = $(".in_news .title_box ul li").eq(0).attr("more");
		$(".in_news .title_box .more").attr("href",more);
		$(".in_news .news_items .item_box").eq(0).addClass("on").siblings().removeClass("on");
		
		$(".in_news .title_box ul li").hover(function(){
			var index = $(this).index();
			var more = $(this).attr("more");
			$(".in_news .title_box .more").attr("href",more);
			$(this).addClass("on").siblings().removeClass("on");
			$(".in_news .news_items .item_box").eq(index).addClass("on").siblings().removeClass("on");
		})
	}
	
	if ($(".in_notice").length > 0) {
		$(".in_notice .items .item").eq(0).addClass("on").siblings().removeClass("on");

		$(".in_notice .items .item").hover(function(){
			$(this).addClass("on").siblings().removeClass("on");
		})
		
	}
	
	if($(".depart_ctgs").length>0){
		
		inDepartTab(1);
		$(".depart_ctgs .ctgs .ctg").click(function(){
			
			var index= $(this).index();
			inDepartTab(index);
		})
		
	}
	
	function inDepartTab(index){
		$(".depart_ctgs .ctgs .ctg").eq(index).addClass("on").siblings().removeClass("on");
		$(".depart_lists .lists").eq(index).addClass("on").siblings().removeClass("on");
		
		var update= "";
		if($(".depart_lists .lists").eq(index).hasClass("mCustomScrollbar")){
			update = "update";
		}
		$(".depart_lists .lists").eq(index).mCustomScrollbar(update);
	}
	
	if($("#expert_swiper").length>0){
		var expert_swiper = new Swiper('#expert_swiper',{
			slidesPerView :1,
			navigation: {
			  nextEl: '.in_expert .swiper-button-next',
			  prevEl: '.in_expert .swiper-button-prev',
			},
			autoplay: {
				delay: 6000,
				stopOnLastSlide: false,
				disableOnInteraction: true,
				
			},
			breakpoints: {
				320: {  
					slidesPerView: 2
				},
				640: {  
					slidesPerView: 3
				},
				1024: {  
					slidesPerView: 4
				},
				1280: {  
					slidesPerView: 5
				},
				1440: {  
					slidesPerView: 6
				}
			},

			
		})
	}
	if($("#zt_swiper").length>0){
		var zt_swiper = new Swiper('#zt_swiper',{
			slidesPerView :4,
			//direction: 'vertical',
			spaceBetween: 22,
			autoHeight: true,
			observer: true,
			observeParents: true,
			//direction: 'vertical',
			autoplay: {
				delay: 6000,
				stopOnLastSlide: false,
				disableOnInteraction: true,
				
			},
			navigation: {
				nextEl: '.in_zt_box .btn_next',
				prevEl: '.in_zt_box .btn_prev',
			},
			breakpoints: {
				0: {
					slidesPerView: 1,
					//direction: 'horizontal',
					spaceBetween: 0,
				},
				375: {
					slidesPerView: 2,
					//direction: 'horizontal',
					spaceBetween: 10,
				},
				768: {
					slidesPerView: 3,
					//direction: 'vertical',
					spaceBetween: 15,
				},
				1024: {
					slidesPerView: 4,
					//direction: 'vertical',
					spaceBetween: 22,
                },
				1440: {
					slidesPerView: 5,
					//direction: 'vertical',
					spaceBetween: 22,
				},
			},

		})
	}
	
	if($("#ctg_swiper").length>0){
		var ctg_on = $("#ctg_swiper .swiper-slide.on");
		var ctg_index = 0;
		if(ctg_on){
			ctg_index = ctg_on.index();
		}
		
		var ctg_swiper = new Swiper('#ctg_swiper',{
			slidesPerView :2,
			initialSlide: ctg_index,
			centeredSlides: true,
			centeredSlidesBounds: true,
			observer: true,
			observeParents: true,
			navigation: {
				nextEl: '.swiper-button-next',
				prevEl: '.swiper-button-prev',
			},
			breakpoints: {
				
				320: {
					slidesPerView: 3
                },
				640: {
					slidesPerView: 4
				},
				1024: {
					slidesPerView: 5
                }
			},
		})
	}
	
	if($("#ksdt_swiper").length>0){
		var ksdt_swiper = new Swiper('#ksdt_swiper',{
			slidesPerView :1,
			spaceBetween : 40,
			pagination: {
			    el: '.swiper-pagination',
				clickable :true,
				
			},

			breakpoints: {
				0: {
					spaceBetween: 0,
                },
				640: {
					slidesPerView: 2
				}
			},
		})
	}
	if($("#depart_img_swiper").length>0){
		var depart_img_swiper = new Swiper('#depart_img_swiper',{
			slidesPerView :1,
			pagination: {
			    el: '.swiper-pagination',
				clickable :true,
				
			},
		})
	}



	//导航下拉 站点切换
	if ($(".drop_box_1").length>0){
		navSiteSummaryTab(0);
		
		$(".nav_site_tab .tab").click(function(){
			var index= $(this).index();
			
			navSiteSummaryTab(index);
		})
		
	}

	
	function navSiteSummaryTab(index) {
		$(".nav_site_tab .tab").eq(index).addClass("on").siblings().removeClass("on");
		$(".nav_site_summary .summary").eq(index).addClass("on").siblings().removeClass("on");
	}



	//关于我们页站点详情切换
	if ($(".site_summary").length > 0) {
		siteSummaryTab(0);

		$(".site_summary .tab_box .tab").click(function () {
			var index = $(this).index();

			siteSummaryTab(index);
		})

	}

	function siteSummaryTab(index){
		$(".site_summary .tab_box .tab").eq(index).addClass("on").siblings().removeClass("on");
		$(".site_summary .summary_box .summary").eq(index).addClass("on").siblings().removeClass("on");
	}


	//新闻动态下拉切换
	if ($(".drop_box_2").length > 0) {

		var tab = $(".drop2_news_tab .tab");
		var cont = $(".drop2_news_lists .list");

		DefaultTab(0, ".drop2_news_tab .tab", ".drop2_news_lists .list");

		$(document).on("click", ".drop2_news_tab .tab", function () {
			var index = $(this).index();
			DefaultTab(index, ".drop2_news_tab .tab", ".drop2_news_lists .list");
		})

    }
	//健康顾问
	if ($(".drop_box_7").length > 0) {

		var tab = $(".drop7_news_tab .tab");
		var cont = $(".drop7_news_lists .list");

		DefaultTab(0, ".drop7_news_tab .tab", ".drop7_news_lists .list");

		$(document).on("click", ".drop7_news_tab .tab", function () {
			var index = $(this).index();
			DefaultTab(index, ".drop7_news_tab .tab", ".drop7_news_lists .list");
		})

	}
	if ($(".drop_box_8").length > 0) {

		DefaultTab(0, ".drop8_news_tab .tab", ".drop8_news_lists .list");

		$(document).on("click", ".drop8_news_tab .tab", function () {
			var index = $(this).index();
			DefaultTab(index, ".drop8_news_tab .tab", ".drop8_news_lists .list");
		})

	}
	if ($(".drop_box_9").length > 0) {

		DefaultTab(0, ".drop9_news_tab .tab", ".drop9_news_lists .list");

		$(document).on("click", ".drop9_news_tab .tab", function () {
			var index = $(this).index();
			DefaultTab(index, ".drop9_news_tab .tab", ".drop9_news_lists .list");
		})
	}
	if ($(".drop_box_10").length > 0) {

		

		DefaultTab(0, ".drop10_news_tab .tab", ".drop10_news_lists .list");

		$(document).on("click", ".drop10_news_tab .tab", function () {
			var index = $(this).index();
			DefaultTab(index, ".drop10_news_tab .tab", ".drop10_news_lists .list");
        })


	}
	if ($(".drop_box_11").length > 0) {

		DefaultTab(0, ".drop11_news_tab .tab", ".drop11_news_lists .list");

		$(document).on("click", ".drop11_news_tab .tab", function () {
			var index = $(this).index();
			DefaultTab(index, ".drop11_news_tab .tab", ".drop11_news_lists .list");
		})

	}


	function DefaultTab(index, tab, cont) {

		$(tab).eq(index).addClass("on").siblings().removeClass("on");
		$(cont).eq(index).addClass("on").siblings().removeClass("on");
	}


	
	if($("#hospimg_swiper").length>0){
		var hospimg_swiper = new Swiper('#hospimg_swiper',{
			slidesPerView :1,
			spaceBetween : 0,
			navigation: {
			  nextEl: '.hospimg_swiper .swiper-button-next',
			  prevEl: '.hospimg_swiper .swiper-button-prev',
			},
			autoplay: {
				delay: 6000,
				stopOnLastSlide: false,
				disableOnInteraction: true,
				
			},
			breakpoints: {
				0: {
					spaceBetween: 1,
					spaceBetween: 0,
				},
				640: {
					slidesPerView: 2,
					spaceBetween: 20,
				},
				1024: {
					slidesPerView: 3,
					spaceBetween: 20,
				}
			},
		})
	}
	if($(".zzjg_box").length>0){
		$(".zzjg_box .zzjg_btn").click(function(){
			var _this = $(this);
			if(_this.hasClass("on")){
				_this.removeClass("on");
				$(".zzjg_box .zzjg_cont").removeClass("on");
			}else{
				_this.addClass("on");
				$(".zzjg_box .zzjg_cont").addClass("on");
			}
			
			
		})
	}
	
	if($("#leader_swiper").length>0){
		var leader_swiper = new Swiper('#leader_swiper',{
			slidesPerView :1,
			spaceBetween : 40,
			navigation: {
			  nextEl: '.leader_box .swiper-button-next',
			  prevEl: '.leader_box .swiper-button-prev',
			},
			autoplay: {
				delay: 6000,
				stopOnLastSlide: false,
				disableOnInteraction: true,
				
			},
			breakpoints: {
				0: {
					slidesPerView: 1,
					spaceBetween: 0,
				},
				320: {
					slidesPerView: 2,
					spaceBetween: 0,
				},
				640: {
					slidesPerView: 1,
					spaceBetween: 0,
				},
				1024: {
					slidesPerView: 2,
					spaceBetween: 40,
				}
			},
		})
	}
	
	if($(".map_tab").length>0){
		
		mapTab(0);
		$(".map_tab .tab").click(function(){
			var index = $(this).index();
			mapTab(index);
		})
	}
	function mapTab(index){
		var tab = $(".map_tab .tab").eq(index);
		tab.addClass("on").siblings().removeClass("on");
		$(".profile_map .map_info" ).eq(index).addClass("on").siblings().removeClass("on");
		
		var lat = tab.attr("lat");
		var long = tab.attr("long");
		var lat2 = tab.attr("lat2");
		var long2 = tab.attr("long2");
		
		setMap(lat,long,lat2,long2);
		
		
	}
	
	function setMap(lat,long,lat2,long2) {
		
		var map = new BMap.Map("allmap");
		//map.addControl(new BMap.NavigationControl());
		var wzpt = new BMap.Point(parseFloat(long), parseFloat(lat));
		var wzicon = new BMap.Icon("/templates/wzhosp/images/map_mark.png", new BMap.Size(85, 84), { anchor: new BMap.Size(42, 84) });
		var markerwz = new BMap.Marker(wzpt, { icon: wzicon });
		map.addOverlay(markerwz);
		map.centerAndZoom(new BMap.Point(parseFloat(long2), parseFloat(lat2)), 17);

	}

	//跳转子栏目
	if ($(".ny_ctgs").length > 0 && false) {
		if ($(".ny_ctgs .swiper-slide").length > 0) {

			if ($(".ny_ctgs .swiper-slide").length > 0 && $(".ny_ctgs .swiper-slide.on").length == 0) {
				var link = $(".ny_ctgs .swiper-slide").eq(0).find("a").attr("href");
				console.log(link);
				if (link != "") {
					location.href = link;
				}

			}
		}

		if ($(".ny_ctgs ul li").length>0 && $(".ny_ctgs ul li.on").length == 0) {
			var link = $(".ny_ctgs ul li").eq(0).find("a").attr("href");
			
			if (link != "") {
				location.href = link;
			}

		}

    }

	
})


//头部搜索
function search(el){
	var _this = $(el);
	if (_this && _this.val() != '') {

		location.href = "/search/index.html?keys=" + _this.val();
		return true;

	}else{
		alert('请输入关键字');
		_this.focus();
		return false;
	}
	
	
}


function addEvent(obj, evtType, func, cap) {
    cap = cap || false;
    if (obj.addEventListener) {
        obj.addEventListener(evtType, func, cap);
        return true;
    } else if (obj.attachEvent) {
        if (cap) {
            obj.setCapture();
            return true;
        } else {
            return obj.attachEvent("on" + evtType, func);
        }
    } else {
        return false;
    }
}
function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageXOffset) {
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollLeft) {
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {
        xScroll = document.body.scrollLeft;
    }
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
}
function GetPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

var AdMoveConfig = new Object();
AdMoveConfig.IsInitialized = false;
AdMoveConfig.ScrollX = 0;
AdMoveConfig.ScrollY = 0;
AdMoveConfig.MoveWidth = 0;
AdMoveConfig.MoveHeight = 0;
AdMoveConfig.Resize = function () {
    var winsize = GetPageSize();
    AdMoveConfig.MoveWidth = winsize[2];
    AdMoveConfig.MoveHeight = winsize[3];
    AdMoveConfig.Scroll();
}
AdMoveConfig.Scroll = function () {
    var winscroll = getPageScroll();
    AdMoveConfig.ScrollX = winscroll[0];
    AdMoveConfig.ScrollY = winscroll[1];
}
addEvent(window, "resize", AdMoveConfig.Resize);
addEvent(window, "scroll", AdMoveConfig.Scroll);
function AdMove(id) {
    if (!AdMoveConfig.IsInitialized) {
        AdMoveConfig.Resize();
        AdMoveConfig.IsInitialized = true;
    }
    var obj = document.getElementById(id);
    obj.style.position = "absolute";
    var W = AdMoveConfig.MoveWidth - obj.offsetWidth;
    var H = AdMoveConfig.MoveHeight - obj.offsetHeight;
    var x = W * Math.random(), y = H * Math.random();
    var rad = (Math.random() + 1) * Math.PI / 6;
    var kx = Math.sin(rad), ky = Math.cos(rad);
    var dirx = (Math.random() < 0.5 ? 1 : -1), diry = (Math.random() < 0.5 ? 1 : -1);
    var step = 1;
    var interval;
    this.SetLocation = function (vx, vy) { x = vx; y = vy; }
    this.SetDirection = function (vx, vy) { dirx = vx; diry = vy; }
    obj.CustomMethod = function () {
        obj.style.left = (x + AdMoveConfig.ScrollX) + "px";
        obj.style.top = (y + AdMoveConfig.ScrollY) + "px";
        rad = (Math.random() + 1) * Math.PI / 6;
        W = AdMoveConfig.MoveWidth - obj.offsetWidth;
        H = AdMoveConfig.MoveHeight - obj.offsetHeight;
        x = x + step * kx * dirx;
        if (x < 0) { dirx = 1; x = 0; kx = Math.sin(rad); ky = Math.cos(rad); }
        if (x > W) { dirx = -1; x = W; kx = Math.sin(rad); ky = Math.cos(rad); }
        y = y + step * ky * diry;
        if (y < 0) { diry = 1; y = 0; kx = Math.sin(rad); ky = Math.cos(rad); }
        if (y > H) { diry = -1; y = H; kx = Math.sin(rad); ky = Math.cos(rad); }
    }
    this.Run = function () {
        var delay = 10;
        interval = setInterval(obj.CustomMethod, delay);
        obj.onmouseover = function () { clearInterval(interval); }
        obj.onmouseout = function () { interval = setInterval(obj.CustomMethod, delay); }
    }
}