//tab选项卡点击
$(function(){
	$(".substance-box .substance").eq(0).show().siblings().hide();
	$(".introduce-tag p span").click(function(){  //标题点击
	    var index=$(this).index();  //获得当前点击标题的下标
	    $(this).addClass("active").siblings().removeClass("active"); //给当前选项添加选中，其他移除选中
	    $(".substance-box .substance").eq(index).show().siblings().hide();  //对应下标的内容框显示，其他隐藏
    });

    //立即报名调转到理解报名标签下
    $(".jsbtnbox .ljbm").click(function(){
        $(".introduce-tag span").eq(3).addClass("active").siblings().removeClass("active");
	    $(".substance-box .substance").eq(3).show().siblings().hide();
        var boxht = $(".source-introduce").offset().top;
        console.log(boxht)
        $('html,body').animate({scrollTop:boxht});
    })
});




//点击立即报名展示网上报名
$(".wbyh-btn").click(function(){
	$(".introduce-tag p span:last").addClass("active").siblings().removeClass("active");
	$(".substance-box .substance:last").show().siblings().hide();
})
$(function(){
    //友情链接和全国分站
    $('.friendly-link').find('ul').eq(0).addClass("show");
    $('.friendly-link .title-box h2').hover(function(){
        $(this).addClass('cur').siblings().removeClass('cur')
        $(this).parents('.friendly-link').find('ul').removeClass('show').eq($(this).index()).addClass('show')
    })
    //课程列表的推荐标签
    $(".curriculum-newlist li").each(function(){
        if($(this).hasClass("tj")){
            $(this).append('<span class="tjicon"></span>')
        }
    })
    
    //新闻轮播
    var dotUl=$(".dotcontent"),
        imgLi=$(".newnewsul>li"),
        str="",
        imgNumber=imgLi.length;
    //根据图片的个数设置小圆圈的个数
    for(var i=0;i<imgNumber;i++){
        str+="<li></li>";
    }
    dotUl.html(str).children(":first").addClass("actives");//设置默认第一个li为hover
    var dotLi= $(".dotcontent>li");
    var imgUl=$(".newnewsul"),
        imgWidth=$(".newnewsul li img").width(),
        wait=3000,  //轮播的时间
        speed=500,//每次轮播的时间
        timer=null,//保存一次性定时器的序号
        iNow = 1;//首先显示第一张图
    imgUl.css("width",(imgNumber+2)*imgWidth);//ul的长度
    //在ul后面加第一个li
    imgLi.first().clone().appendTo(imgUl);
    //在ul前面加最后一个li
    imgLi.last().clone().prependTo(imgUl);
    //由于现在第一张图是最后一张，要把第一张图前移
    imgUl.css("left",-imgWidth*iNow);
    function animate() {
        imgUl.animate({
            left : -imgWidth*iNow
        },speed,function () {
            if(iNow===imgNumber+1){
                iNow=1;
                imgUl.css("left",-imgWidth*iNow);//重置
            }
            dotUl.children(":eq("+(iNow-1)+")").addClass("actives").siblings().removeClass("actives");//小圆点也一起轮播
        });
    }
    //定时器
    function move() {
        timer=setInterval(function () {
            iNow++;
            animate();
        },wait);
    }
    move();
    //点击小圆点
    dotLi.on("click", function () {
        if (!$(this).hasClass("actives")) {
            $(this).addClass("actives").siblings().removeClass("actives");
        }
        iNow = $(this).index()+1;//获取被点击按钮的下标
        //图片过渡效果
        imgUl.animate({
            left:-imgWidth * iNow
        }, speed);
    });
    //鼠标移入圆点暂停定时器
    dotLi.mouseenter(function () {
        clearTimeout(timer);
    });
    //鼠标移出圆点开始轮播
    dotLi.mouseleave(function () {
        iNow=$(this).index()+1;
        move();
    });
    //点击左按钮
    $(".prev").click(function () {
        clearTimeout(timer);
        iNow=dotLi.index($(".actives"));
        imgUl.animate({
            left : -imgWidth*iNow
        },speed,function () {
            if(iNow===0){
                iNow=imgNumber;
                imgUl.css("left",-imgWidth*iNow);//重置
            }
            dotUl.children(":eq("+(iNow-1)+")").addClass("actives").siblings().removeClass("actives");//小圆点也一起轮播
        });
        move();
    });
    //点击右按钮
    $(".next").click(function () {
        clearTimeout(timer);
        iNow=dotLi.index($(".actives"))+2;
        animate();
        move();
    });
})

$(function(){
	$(".header .content2 ul li").eq(0).addClass("active");
	$(".header .content2 ul li").click(function(){
			var $index=$(this).index();
			$(this).addClass("active").siblings().removeClass("active"); //给当前选项添加选中，其他移除选中
			if($index==0){
				$("#searchtype").val("information");
			}else if($index==1){
				$("#searchtype").val("school");
			}else{
				$("#searchtype").val("teacher");
			}
    })
})

$(document).ready(function() {
  $('.webcity').hover(function(){
      $('.webcity2').show();
  }, function(){
      $('.webcity2').hide();
  });
  
   $('.webcity2').hover(function(){
      $(this).show();
  }, function(){
      $(this).hide();
  });
});

$(document).ready(function() {
	function movedome(){
		var margintop=0;
		var stop=false;
		setInterval(function(){
			if(stop==true){
				return;
			}
			$(".Registration ul").children("li").first().animate({"margin-top":margintop--},0,function(){
				var $li=$(this);
				if(!$li.is(":animated")){//第一个li的动画结束时
				if(-margintop>$li.height()){
					$li.css("margin-top","0px").appendTo($(".Registration ul"));
					margintop=0;
				}
			}
		});
	},100);

	}
	movedome();
}); 

function left(that) {
	// 取得当前轮播图对象
	var objLunbo = $(that).find(".lunbo-ul");

	// 取得当前触发的是第几个轮播图
	var lunboIndex = objLunbo.attr("lunboIndex") * 1.0;

	if(indexArr[lunboIndex][0] == 0 && indexArr[lunboIndex][1] == 1) {
		// 第一次点击赋值一次
		indexArr[lunboIndex][0] = objLunbo.find(".cur").length - 2;
		indexArr[lunboIndex][1] = objLunbo.find(".cur").length - 1;
	} else {
		indexArr[lunboIndex][0] = indexArr[lunboIndex][1] - 3;
		indexArr[lunboIndex][1] = indexArr[lunboIndex][0] + 1;
	}

	// 取得当前轮播图内容长度
	var contextLength = objLunbo.find("li").length;
	// 取得当前轮播图下一轮索引

	// 索引越界重新计算
	if(indexArr[lunboIndex][0] <= 0) {
		// 求出未越界部分
		var CrossingLength = indexArr[lunboIndex].length + indexArr[lunboIndex][0];

		// 求出未越界部分 索引
		var noCrossingIndex = indexArr[lunboIndex][1];

		// 最后一条插入到列表前
		var endItem = objLunbo.find(".cur").eq(4);
		objLunbo.find(".cur").eq(0).before(endItem);

		// 索引重置为初始
		indexArr[lunboIndex][0] = 0;
		indexArr[lunboIndex][1] = 1;
		
	}
	show(that);
	
}

/**
 * 右箭头点击操作
 * @param {Object} that 轮播图对象
 */
function rigth(that) {
	// 取得当前轮播图对象
	var objLunbo = $(that).find(".lunbo-ul");

	// 取得当前触发的是第几个轮播图
	var lunboIndex = objLunbo.attr("lunboIndex") * 1.0;

	indexArr[lunboIndex][0] = indexArr[lunboIndex][1] + 1;
	indexArr[lunboIndex][1] = indexArr[lunboIndex][0] + 1;

	// 取得当前轮播图内容长度
	var contextLength = objLunbo.find("li").length;

	// 取得当前轮播图下一轮索引

	// 索引越界重新计算
	if(indexArr[lunboIndex][1] > contextLength - 1) {
		// 求出未越界部分
		var CrossingLength = Math.abs(contextLength - (indexArr[lunboIndex][1] + 1));

		// 求出未越界部分 索引
		var noCrossingIndex = indexArr[lunboIndex][1] - CrossingLength;

		// 未越界部分插入到列表前面
		var noCrossing = objLunbo.find(".cur").eq(objLunbo.find(".cur").length - 1);
		objLunbo.find(".cur").eq(0).before(noCrossing);

		// 索引重置为初始
		indexArr[lunboIndex][0] = 0;
		indexArr[lunboIndex][1] = 1;
	}
	// 刷新轮播图
	show(that);
}

function getNav(){
  $.ajax({
        url:'/catNav.php?citydomain='+citydomain,
        type:'get',
        dataType : "html",
        success:function($data){
          $("#nav").html($data);
          
$(function(){
// function shownav(){
    
// 导航菜单
    // 判断导航菜单是否隐藏
    $('.menu-btn').hover(function(){
        var $this = $(this);
        if ($('.menu',$this).size()>=1 && $('.menu',$this).hasClass('hide')) {
            $('.menu',$this).show();
        }
    },function(){
        var $this = $(this);
        if ($('.menu',$this).size()>=1 && $('.menu',$this).hasClass('hide')) {
            $('.menu',$this).hide();
        }
    })
    $('.menu>ul>li').hover(function(){
        var $this = $(this);
        $this.addClass('cur');
        if ($('ul',$this).size()>=1) {
            $('ul',$this).show();
        }
    },function(){
        var $this = $(this);
        $this.removeClass('cur');
        if ($('ul',$this).size()>=1) {
            $('ul',$this).hide();
        }
    })
    
});
          
        },
        error:function(err){
          // alert(id);
          
        }
   });

}
/**
 * 重新展示轮播图
 * @param {Object} that 轮播图对象
 */
function show(that) {
	// 取得当前轮播图对象
	var objLunbo = $(that).find(".lunbo-ul");

	// 取得当前触发的是第几个轮播图
	var lunboIndex = objLunbo.attr("lunboIndex") * 1.0;

	// 取得当前轮播图下面所有 li 元素
	var curs = $(objLunbo).find(".cur");
	$(curs).css({
		display: 'list-item'
	});
	curs.removeClass("lunbo-active-frist");
	$.each(curs, function(i, item) {
		if(i == indexArr[lunboIndex][0]) {
			$(item).addClass("lunbo-active-frist");
		}
		if(i != indexArr[lunboIndex][0] && i != indexArr[lunboIndex][1]) {
			$(item).css({
				display: 'none'
			});
		}
	});
}
$(function() {
	$(".lunbo-li #btnl").on("click", function() {
		left($(this).parents(".lunbo-li"));
	});

	$(".lunbo-li #btnr").on("click", function() {
		rigth($(this).parents(".lunbo-li"));
	});
});


//banner轮播
$(function(){
    var i = 0;
        var clone = $(".banner-list li").first().clone();//克隆第一张图片
        $(".banner-list").append(clone);                //复制到列表最后
        var size = $(".banner-list li").size();         //返回匹配元素的数量

		$(".banner-list").width(1920*size+"px");
        console.log(size);
        /*循环图片容器的数量，并且向点点按钮的大容器添加几个子节点作为点点按钮*/
        for (var j = 0; j < size-1; j++) {
            $(".J_banner .pointer").append("<li></li>");
        }
         $(".J_banner .pointer li").eq(0).addClass("now").siblings().removeClass("now");
        /*自动轮播*/
        var t = setInterval(function () {
            i++;
            move();
            },3000);
        /*鼠标悬停事件*/
        $(".J_banner").hover(function () {
            clearInterval(t);//鼠标悬停时清除定时器
        }, function () {
            t = setInterval(function () {
                i++;
                move();
                }, 3000); //鼠标移出时开始定时器
        });
        /*鼠标滑入原点事件*/
        $(".J_banner .pointer li").hover(function () {
            var index = $(this).index();//获取当前索引值
        	console.log(index)
            i = index;
            $(".J_banner .banner-list").stop().animate({ left: -index * 1920 }, 800);
            $(this).addClass("now").siblings().removeClass("now");
        });
        /*移动事件*/
        function move() {
            if (i == size) {
                $(".J_banner .banner-list").css({ left: 0 });
                i = 1;
            }
            if (i == -1) {
                $(".J_banner .banner-list").css({ left: -(size - 1) * 1920 });
                i = size - 2;
            }
            $(".J_banner .banner-list").stop().animate({ left: -i * 1920 }, 800);

            if (i == size - 1) {
                $(".J_banner .pointer li").eq(0).addClass("now").siblings().removeClass("now");
            } else {
                $(".J_banner .pointer li").eq(i).addClass("now").siblings().removeClass("now");
            }
        }
});


// shownav();
$(function(){
// function shownav(){
	
// 导航菜单
    // 判断导航菜单是否隐藏
    $('.menu-btn').hover(function(){
        var $this = $(this);
        if ($('.menu',$this).size()>=1 && $('.menu',$this).hasClass('hide')) {
            $('.menu',$this).show();
        }
    },function(){
        var $this = $(this);
        if ($('.menu',$this).size()>=1 && $('.menu',$this).hasClass('hide')) {
            $('.menu',$this).hide();
        }
    })
    $('.menu>ul>li').hover(function(){
        var $this = $(this);
        $this.addClass('cur');
        if ($('ul',$this).size()>=1) {
            $('ul',$this).show();
        }
    },function(){
        var $this = $(this);
        $this.removeClass('cur');
        if ($('ul',$this).size()>=1) {
            $('ul',$this).hide();
        }
    })
	
});