var tab,endPage,active;
$(function(){
	$("#text").html("资讯详情");
	var newsId = GetQueryString("newsId");
	active = newsId;
	tab = GetQueryString("tab");
	endPage = GetQueryString("endPage");

	$("#collect").click(function(){
   	 var newsId =GetQueryString("newsId");
   	 
   	 if(!$('#collect').hasClass("cancle")){
   		 $.ajax({
			    	url:baseUrl+'/api/user/collect.do',
			    	data:{
			    		favoriteType:1,
			    		relationId:newsId,
			    		orginUri:location.href,
			    		thumbnail:"../../static/images/news_collect.jpg"
			    	},
				    success:function(data){
				    	if(data.status===311){	
				    	   localStorage.clear();	
				    	   localStorage.setItem("newsId", newsId);
				    	   //toast.show({msg:"还未登录,请先登录"});
				    	   //setTimeout(function(){
				    		   return location.href="../user/login.html";
				    	   //},1000);
				    	}else if(data.status===200){
				    		$('#collect').addClass("cancle");
				    		$('#collect').attr("src","../../static/images/collected.png");
				        }else{
				        	wrongMsg(data.message);
				        }
				  }
		    	});
   	 }else{
   		 $.ajax({
			    	url:baseUrl+'/api/user/cancel_collect.do',
			    	data:{
			    		favoriteType:1,
			    		relationId:newsId
			    	},	 	    				    
				    success:function(data){
				    	if(data.status===311){	
				    	   localStorage.clear();	
				    	   localStorage.setItem("newsId", newsId);
				    	   //toast.show({msg:"还未登录,请先登录"});
				    	   //setTimeout(function(){
				    		   return location.href="../user/login.html";
				    	   //},1000);
				    	}else if(data.status===200){
				    		$('#collect').removeClass("cancle");
				    		$('#collect').attr("src","../../static/images/collect.png");
				        }else{
				        	wrongMsg(data.message);
				        }
				  }
		    	});
		    	
		}
   	
   });
	return Ajax({
		url:baseUrl+ '/api/news/detail.do',
		data:{
			newsId:newsId
		},
		callback:function(obj){
			var news = obj.data.news;
			var pubTime = news.pubTime.substr(5,6);
			if(news.fid===undefined||news.fid===0){
        		$('#collect').removeClass("cancle");
        		$('#collect').attr("src","../../static/images/collect.png");
        	}else{
        		$('#collect').addClass("cancle");
        		$('#collect').attr("src","../../static/images/collected.png");
        	}
			$("#newsType").html(news.newsTypeName);
			$("#title").html(news.title);
			$("#pubTime").html(pubTime);
			$("#author").html(news.author);
			$("#viewCount").html(news.viewCount);
			$("#content").html(news.content);
			if(news.mthumbnail==null||news.mthumbnail==""||news.mthumbnail==undefined){
				$("#mthumbnail").hide();
			}else{
				$("#mthumbnail").attr("src",news.mthumbnail);
				$("#mthumbnail").show();
			}
		}
	});
});
/*
function goBack(){
	return location.href="./newsList.html";
	// + tab + "&endPage=" + endPage + "&active=" + active
}
*/