$(function(){

	//加载页面时,判断是否登陆
	var userid = $.cookie("userid");
	if (userid && userid != "null" && userid != null) {
		$(".myWorkspace").attr("href","workspaces.html?"+userid);
		loginStatus();
	}
	
	//登陆个人信息下拉菜单
	$('.head-portrait').hover(function() {
		$(".personal-infor").stop(true, false).slideDown(500);
	}, function() {
		$(".personal-infor").stop(true, false).slideUp(500);
	});
	
	//搜索框跳转页面
	function synContent(type) {
		if (type == 1) {		
			$("#searchContent").val($("#hsearchContent").val());
		} else {	
			$("#hsearchContent").val($("#searchContent").val());
		}
	}
	$("#hsearchContent").blur(function() {
		synContent(1);
	});
	$("#searchContent").blur(function() {
		synContent(2);
	});
	
	
	var lookFor = 0;
	$("#lookFor ul li").on("click",function(){
		lookFor=$(this).index();
		console.log(lookFor);
	});
	$("#search").on("click", function() {
		var searchContent = $("#searchContent").val();
		location.href = "search.html?searchContent=" + encodeURI(searchContent)+"&lookFor=" + lookFor;
	});
	
	//enter绑定时间
	$("#searchContent").keydown(function(e){
		if(e.which==13) {
			synContent(2);
		 var searchContent = $("#searchContent").val();
		 console.log(searchContent);
			location.href = "search.html?searchContent=" + encodeURI(searchContent)+"&lookFor=" + lookFor;
		}
		
	})
	$("#hsearchContent").keydown(function(e){
		if(e.which==13) {
			synContent(1);			
			var searchContent = $("#hsearchContent").val();		
			console.log(searchContent);
			location.href = "search.html?searchContent=" + encodeURI(searchContent);
		}	
	})
	
	$("#hsearch").on("click", function() {
		var searchContent = $("#hsearchContent").val();
		location.href = "search.html?searchContent=" + encodeURI(searchContent);
	});
	
	//热门领域
	$(".field").bind("click",function(){
		location.href = "search.html?subject=" + encodeURI($(this).text());
	})
	//热门专家
	$('.professor').hover(function() {
		$(this).find(".professor-data").stop(true, false).animate({
			"padding": "94px 0",
			"top": "-50px"
		})
	}, function() {
		$(this).find(".professor-data").stop(true, false).animate({
			"padding": "25px 0",
			"top": "58%"
		})
	})
	/*发布需求*/
	$("#postNow").click(function(){
		if(userid=="null"||userid==undefined){
			location.href="login.html";
		}
		$.ajax({
			url: "/ajax/professor/auth",
			type: "GET",
			timeout: 10000,
			dataType: "json",
			data: {
				"id": userid,
			},
			success: function(data, textState) {
				if(data.success) {
					var $rta=data.data;
					if($rta.authStatus==3){
						location.href="myDemand.html";
					}else{
						location.href="realname-authentication.html"
					}
					
				}

			},
			error: function(XMLHttpRequest, textStats, errorThrown) {

			}
		})
	})
	/*我是专家*/
	$("#JoinKeXiu").click(function(){
		if(userid=="null"||userid==undefined){
			location.href="login.html";
		}
		$.ajax({
			url: "/ajax/professor/auth",
			type: "GET",
			timeout: 10000,
			dataType: "json",
			data: {
				"id": userid,
			},
			success: function(data, textState) {
				if(data.success) {
					var $rta=data.data;
					if($rta.authType==1){
						location.href="needList.html";
					}else{
						location.href="expert-authentication.html"
					}
					
				}

			},
			error: function(XMLHttpRequest, textStats, errorThrown) {

			}
		})
	})
})