var ltIE9 = (function () {
	var theUA = window.navigator.userAgent.toLowerCase();
	if (
		(theUA.match(/msie\s\d+/) && theUA.match(/msie\s\d+/)[0]) ||
		(theUA.match(/trident\s?\d+/) && theUA.match(/trident\s?\d+/)[0])
	) {
		var ieVersion =
			theUA.match(/msie\s\d+/)[0].match(/\d+/)[0] ||
			theUA.match(/trident\s?\d+/)[0];
		if (ieVersion < 9) {
			return true;
		} else {
			return false;
		}
	}
})();
ltIE9 && (window.location.href = "/ie/")

var shuwon = {
	percent: 0,
	timers: "",
	init: function (e) {
		util.backTop()
		util.isTop()
		util.toastInit()
		$('.Hamburger').click(function (e) {
			$(this).toggleClass('active')
			$('header').toggleClass('active')
		})
		$(".lazy").lazyload({
			effect: "fadeIn"
		});
		$('.btnSearch').click(function (e) {
			if (util.regNull($('.inputSearch').val())) {
				util.toast({
					string: '请填写内容',
					type: 'error',
				})
			} else {
				window.location.href = '/search.html?keywords=' + $('.inputSearch').val()
			}
		})
		$('.inputSearch').bind('keyup', function (event) {
			if (event.keyCode == "13") {
				if (util.regNull($('.inputSearch').val())) {
					util.toast({
						string: '请填写内容',
						type: 'error',
					})
				} else {
					window.location.href = '/search.html?keywords=' + $('.inputSearch').val()
				}
			}
		});
	},

	/**
	 * 页面加载完毕
	 */
	loaded: function () {

	},
	index: function () {
		var _w = $('body').width()

		var banner = new Swiper('#banner', {
			autoplay: true,
			loop: true,
			pagination: {
				el: '#banner-pagination',
				clickable: true
			},
		});
		//学校切换
		var $liobj = $(".tab_list a");

		$liobj.hover(function () {
			$liobj.removeClass("active");
			$(this).addClass("active");
			var i = $(this).index()

			$(".content ul").eq(i).addClass("active").siblings().removeClass("active");
		});
		//新闻资讯
		var newsList = new Swiper('.newsList', {
			slidesPerView: 3,
			spaceBetween: 30,
			noSwiping: true,
			breakpoints: {
				//当宽度大于等于320
				320: {
					slidesPerView: 1,
					noSwiping: false,
					pagination: {
						el: '.swiper-pagination',
					},
				},
				1024: {
					slidesPerView: 3,
				}
			}
		});
		//学校环境
		var SCHOOL = new Swiper('.SCHOOL', {
			slidesPerView: 3,
			spaceBetween: 30,
			noSwiping: true,
			breakpoints: {
				//当宽度大于等于320
				320: {
					slidesPerView: 1,
					noSwiping: false,
					pagination: {
						el: '.SCHOOL .swiper-pagination',
					},
				},
			}
		});

		shuwon.banner();
		if (_w >= 1300) {
			$(window).scroll(function () {
				var scrollTop = $(window).scrollTop();
				$(".banner").css({
					"-webkit-transform": "translateY(-" + scrollTop * 0.2 + "px)"
				})
			})
		}
	},
	banner: function () {
		var t = $(".banner ul li"),
			a = t.length,
			d = 0;

		$(".banner ul li").eq(0).addClass("active");
		$(".banner ul li").eq(0).addClass("visible");
		$(".process").addClass("on");
		var timer = setInterval(function () {
			next();
		}, 8000);

		$(".banner .btn.prev").click(function () {
			prev();
		})
		$(".banner .btn.next").click(function () {
			next();
		})

		function next() {
			d = ++d > a - 1 ? 0 : d;
			e();
		}

		function prev() {
			d = --d < 0 ? a - 1 : d;
			e();
		}

		function e() {
			clearInterval(timer);
			$(".process").removeClass("on");
			$(".banner ul li").eq(d).addClass("active").siblings().removeClass("active");
			$(".banner ul li").eq(d).addClass("visible");
			$(".banner ol li").eq(d).addClass("active").siblings().removeClass("active");
			setTimeout(function () {
				$(".banner ul li").eq(d).siblings().removeClass("visible");
				$(".process").addClass("on");
			}, 600)

			timer = setInterval(function () {
				next();
			}, 8000)
		}
	},
	about: function () {
		var _w = $('body').width()
		var teachersBox = new Swiper('.teachersBox', {
			slidesPerView: 3,
			spaceBetween: 20,
		});

		$(".ideas ul li").hover(function () {
			$(this).addClass("active").siblings().removeClass("active");
		})

		$(".master_list li").eq(0).addClass("active");
		$(".master_list li").click(function () {
			getMaster($(this).attr("data-id"), $(this).attr("data-pos"));
			$(this).addClass("active").siblings().removeClass("active");
			if (_w >= 1300) {
				$(".master_list ul").css({
					left: -185 * $(this).index()
				});
			}
		})
		getMaster($(".master_list li").eq(0).attr("data-id"), $(".master_list li").eq(0).attr("data-pos"));

		function getMaster(_id, _pos) {
			shuwon.getDataForApi('/apimaster.html', {
				id: _id
			}, function (data) {
				if (data.result) {

					console.log(data)
					$(".team_top .thum").css({
						"background-image": "url(" + data.face + ")"
					})
					$(".team_top .info .name b").html(data.name);
					$(".team_top .info .name p").html(_pos);
					$(".team_top .info .des").html(data.content);

				}
			})
		}

		if (_w <= 768) {
			//卓越师资
			var excellent = new Swiper('.excellent', {
				slidesPerView: 2,
				spaceBetween: 10,
				pagination: {
					el: '.excellent .swiper-pagination',
					clickable: true,
				},
			});
			var $textContent = $('.textContent'),
				$iconBtnOff = $('.icon_btnOff'),
				$Modal = $('.Modal'),
				$Modal_name = $('.Modal .name'),
				$Modal_position = $('.Modal .position span'),
				$Modal_text = $('.Modal .text');
			$('.teacher_list ul li').click(function (e) {
				$Modal_name.html($(this).find('.name b').html())
				$Modal_position.html($(this).find('.name p').html())
				$Modal_text.html($(this).find('.pos').html())
				$Modal.addClass('active')
			})
			$iconBtnOff.click(function (e) {
				$Modal.removeClass('active')
			})
			//文化理念
			var ideasSw = new Swiper('.ideasSw', {
				slidesPerView: 1,
				spaceBetween: 10,
				autoHeight: true,
				pagination: {
					el: '.ideasSw .swiper-pagination',
					clickable: true,
				},
			});

		}
	},
	primary: function (e) {
		var _w = $('body').width()

		if (_w <= 768) {
			//教师风采
			var $teamList = $('.team_list.ls ul li'),
				$Modal = $('.Modal'),
				$Modal_name = $('.Modal .name'),
				$iconBtnOff = $('.icon_btnOff'),
				$position = $('.position span'),
				$Modal_text = $('.Modal .text');
			$teamList.click(function (e) {
				$Modal.addClass('active')
				$Modal_name.html($(this).find('.name b').html())
				$position.html($(this).find('.name p').html())
				$Modal_text.html($(this).find('.summary').html())
			})
			$iconBtnOff.click(function (e) {
				$Modal.removeClass('active')
			})
			//学子风采
			var team_list = new Swiper('.team_list.swiper-container', {
				slidesPerView: 2,
				spaceBetween: 10,
				pagination: {
					el: '.team_list .swiper-pagination',
					clickable: true,
				},
			});
		}
	},
	join: function (e) {
		var _w = $('body').width(),
			$positionLi = $(".positionTableBox ul li"),
			$Modal = $('.Modal'),
			$Modal_name = $('.Modal .name'),
			$iconBtnOff = $('.icon_btnOff')
		$Modal_text = $('.Modal .text');
		$positionLi.click(function () {
			if (_w <= 768) {
				$Modal.addClass('active')
				$Modal_name.html($(this).find('.j_top div').eq(0).html())
				$Modal_text.html($(this).find('.j_bottom').html())
			} else {
				if ($(this).hasClass('active')) {
					$(this).removeClass("active");
				} else {
					$(this).addClass("active").siblings().removeClass("active");
				}
			}
		})
		$iconBtnOff.click(function (e) {
			$Modal.removeClass('active')
		})

	},
	Enrollment: function (e) {
		$("#distpicker").distpicker({
			province: '省份名',
			city: '城市名',
			district: '区名',
		});
		//表单
		var $submit = document.getElementsByClassName('form_submit')[0],
			$form = document.getElementById('_form')
		$submit.addEventListener('click', function (e) {
			if ($form.name.value == '') {
				new util.toast({
					string: '请填写姓名',
					type: 'warning'
				})
			} else if ($form.mobile.value == '') {
				new util.toast({
					string: '请填写手机号码',
					type: 'warning'
				})
			} else if (!util.regPhone($form.mobile.value)) {
				new util.toast({
					string: '请填写正确的号码',
					type: 'warning'
				})
			} else if ($form.address.value == '') {
				new util.toast({
					string: '请填写地址',
					type: 'warning'
				})
			} else {
				shuwon.getDataForApi('post', '/apiapply.html', {
					form_name: $form.name.value,
					form_phone: $form.mobile.value,
					form_address: $form.province.value + $form.city.value + $form.edistrictName.value + $form.address.value,
					form_grade: $form.choose.value,
					message: $form.message.value
				}, function (data) {
					if (data.result) {
						new util.toast({
							string: data.msg,
							type: 'success'
						})
						$form.reset()
					} else {
						new util.toast({
							string: data.msg,
							type: 'warning'
						})
					}
				})
			}
		})
	},
	facilities: function (e) {
		var _w = $('body').width()
		//校园设施
		var facilitiesTop = new Swiper('.AlbumSwiper', {
			spaceBetween: 20,
			slidesPerView: 'auto',
			navigation: {
				nextEl: '.swiper-button-next',
				prevEl: '.swiper-button-prev',
			},
			autoHeight: true,
			breakpoints: {
				//当宽度大于等于320
				320: {
					slidesPerView: 1,
					pagination: {
						el: '.swiper-pagination',
						clickable: true,
					},
				},
				1024: {
					slidesPerView: 'auto',
				}
			}
		});
		if (_w <= 768) {
			//家校共育
			var home_list = new Swiper('.home_list.swiper-container', {
				slidesPerView: 1,
				spaceBetween: 10,
				pagination: {
					el: '.home_list .swiper-pagination',
					clickable: true,
				},
			});
		}
	},
	/**
	 *获取数据
	 *
	 * @param {String} url 传入的数据接口
	 * @param {Object} para 传入的参数
	 * @param {Object} callback 返回
	 */
	getDataForApi: function (url, para, callback) {
		$.ajax({
			type: "post",
			data: para,
			url: url,
			dataType: 'json',
			success: function (data) {
				callback(data)
			},
			error: function (e) {
				console.log(e, "")
			}
		})
	},
}
shuwon.init()