// JavaScript Document


// 引导页相关js


var resetHeight= function(){ // 页面自适应浏览器窗口高度
					var i = $(window).height();
					var $H= $("div.main").height();
					var $h= $("div.nav").height();
					var $height = (i-$H)>$h?i-$H-4:$h;
					$("div.footer").height($height);
					
	}
var resetWidth = function(){
				   var i = $(window).width()<975?975:$(window).width();
				   $("div.main").width(i)
				   
}
var highLight = function(){ //搜索按钮逐渐高光
					var $c = $('<div class="hl1"></div>');
					$("dd.search").append($c);
					var $l = $("input.submit").position().left;
					var $t = $("input.submit").position().top;
					$("input.submit").next("div.hl1").css({"height":'30px',"width":'40px',"position":'absolute',"left":$l+'px',"top":$t+'px',"display":'none'});
					$("input.submit").hover(function(){
						
						$(this).next('div').show()
													 },
										 function(){
						$(this).next('div').hide()
													 }
						)
					
	}
var form_validation = function(){//搜索框验证
					var $target = $("input.text");
					$target.css("color","#999").focus(function(){
													if($(this).val()=="站内搜索"){
														$(this).val("");
													}
													$(this).css("color","#000")
													  })
											    .blur(function(){
													var i = $(this).val();
												     (i=="站内搜索"||i.replace(/(^\s*)|(\s*$)/g,"")=="")?$(this).val("站内搜索").css("color","#999"):$(this).val(i);
													  })
											   
					
	}
var skin_box = function(){/*换肤按钮动画*/
		var $target = $("a.skin");
		$target.click(function(){
			if(!$(this).parent().is(":animated")){
				if($(this).parent().children("ul").is(":hidden")){
					$(this).parent().removeClass("skin_info").addClass("opacity1").animate({"width":"230px","height":"120px"},300,function(){
																																				$(this).children('a').children('span').text('▲')
																																				.end().end()
																																				.children("ul").show();
																																				});
				}else{
					$(this).parent().children("ul").hide().end().css({"height":"25px","width":'70px'}).end().children("span").text("▼");
				}
			}
			})
	}
var dl = function(){/*登录框动画*/
		var $target = $("a.login");
		
		$target.click(function(){
		     var $h = $(this).parent().children("ul").height();
		     var $h1=$(this).parent().children("ul").find(".last").height();
		     if($(this).parent("div").attr("id")=="userLogin"||$(this).parent("#loginBack").children("ul").find(".gsm").children("a").length<=4){
			 var $H = 120;
			 }else{
			 var $H = $h1+$h; 
			 }
			 $(this).parent().children("ul").height($H);
			if(!$(this).parent().is(":animated")){
				if($(this).parent().children("ul").is(":hidden")){
				   
				   
					$(this).parents("div.position").css("background-position","right bottom" )
					$(this).parent().animate({"width":"230px","height":$H+"px"},300,function(){
																																				$(this).children('a').children('span').text('▲')
																																				.end().end()
																																				.children("ul").show();
																																				});
				}else{
				    $(this).parent("#loginBack").children("ul").hide().height($h-$h1);
					$(this).parent().children("ul").hide().end().css({"height":"25px","width":'70px'}).end().children("span").text("▼");
					$(this).parents("div.position").css("background-position","right -117px")
				}
			}
			})
	}
var menu = function(x){//二级菜单动画
			var $target = $(x);
			for(var i=1;i<$target.length;i++){
				var $val = 0;
				for(var j=0;j<$($target[i]).children("div").children("div").children("a").length;j++){
					$val+=$($($target[i]).children("div").children("div").children("a")[j]).outerWidth();
					$($($target[i]).children("div")).width($val)
					}
			}
			$target.css("overflow","visible")
			$target.children("div").hide();
			$target.mouseenter(function(){
				
				var $target2 = $(this).children("div").children("div").children("a");
				var $this = $(this);
				if($target2 != null){
				$($target2[$target2.length-1]).addClass("last")
				var $w = $this.children("div").width();
				var $W = $this.width()/2;
				//在这里控制导航菜单相对于窗口的位置
				$this.children("div").css("left",$W-$w/2+"px").show();
				var $xxx =$(this).children("div")[0];
				if($xxx){
				var $a = $xxx.getBoundingClientRect().left;//获取DOM相对于浏览器的位置
				
				if($a<0){
				$this.children("div").css("left",$W-$w/2-$a+"px");
				}else if($a+$this.children("div").outerWidth()>$(window).width()){
				var $b= $a+$this.children("div").outerWidth()-$(window).width();
				$this.children("div").css("left",$W-$w/2-$b+"px");
				}
				}
				}
			})
			.mouseleave(function(){
					$(this).children("div").hide();
					
			})
			$target.mouseenter(function(){
							var $l = $(this).position().left;
							var $w = $(this).width()/2;
							var $width = $("div.hl2").width()/2;
							var $width1= $("div.pointing").width()/2;
							$("div.hl2").css({"left":$l+$w-$width+'px'}).show();/*stop(false,true).animate({'height':"55px"},"slow")*/
							$(this).children("span.pointing").css("left",$w-$width+45+'px').show();
					})
					.mouseleave(function(){
							var $height = $("div.hl2").height();
							$("div.hl2")/*.stop(false,true)*/.hide();/*animate({"height":'0px'},"slow")*/
						    $("span.pointing").hide();
											})
			
	}

var change = function(){//切换样式
		
		var $target = $("ul.skin_box li a");
		
		var $t = $("link.skin");
		
		$target.click(function(){
					   
					   
					   var $i = $(this).attr("class");
					   var $href = $(this).attr("href");
					  
					   $("link#"+$i).attr("href",$href).siblings("link.skin").attr("href","");
					   
					   
					   return false;
		})
}
var xnfw_hover = function(){//校内服务下拉菜单
	 var $target = $("div.nav li.other a").last();
	 var $t2 = $("div.mac_menu");
	 var xnfw_hover_hide = null;
	 $t2.css("visibility","hidden");
	 $target.mouseleave(function(){
		
		xnfw_hover_hide= setTimeout(function(){
		$t2.css({"display":"none"}); 
		},300)
		}).mouseenter(function(){
        if(xnfw_hover_hide !=null)	{
		clearTimeout(xnfw_hover_hide);
		}
		$t2.css({"visibility":"visible","display":"block"});
	 })
	 $t2.hover(function(){
	 	clearTimeout(xnfw_hover_hide);
	 },function(){
	 	$(this).css("display",'none')
	 })
}
$(function(){
	//页面自适应大小	
	resetHeight();
	$(window).resize(function(){
		resetHeight();
		})
	//页面自适应宽度
	resetWidth();
	$(window).resize(function(){
		resetWidth();
		})
	//按钮高亮动画
	highLight();
	//表单效果
	form_validation();
	//皮肤按钮动画
	skin_box();
	//登录效果
	dl();
	xnfw_hover();//校内服务下拉菜单
	})

