
$(document).ready(function(){
	  $("#showallprintfooter").click(function(){
																var userId=$("#cuserId").val();
																var blogId=$("#itemId").val();	
																var pageurl=$("#pageurl").val();
																
																var fillLi=function(item){
																   var $relatedli=$this.find("li:first").clone(true)
																   var $img=$relatedli.find("span[class='imgborder']")
																   $img.find("a").attr("href",item.href).attr("title",item.title).attr("alt",item.title).find("img").attr("src",item.image).attr("alt",item.title);
																   $relatedli.find("a:last").attr("href",item.href).attr("title",item.title).attr("alt",item.title).text(item.user);
																   $relatedli.show();
																   $this.prepend($relatedli);
																   }
																var $this=$("#printfootlist");
																$this.hide();
																var $loading=$("<span>数据读入中....</span>");
																$this.after($loading);
																jQuery.getJSON("portlet/trace/footprint.do",{show:"all",userId:userId,blogId:blogId,pageurl:pageurl},function(data){
																													  if (data.error == "0") {
																														  $this.find("li:last").hide();
																														  $this.find("li").each(function(){
																																						 if ($(this).css("display") != "none") { $(this).remove(); }
																																						 })
																														  $this.prev().find("#allprintfooternumber").text(data.allprintfooter);
																														  $this.prev().find("#showtop4").remove();
																														  jQuery.each(data.items,function(i,item){fillLi(item);})
																														  $loading.remove();
																														  $this.show();
																														  }
																													  return false;
																													  })
																return false;
																})
																
   $("#addFootprint").click(function(){
																var userId=$("#userId").val();
																var itemId=$("#itemId").val();
																var type=$("#type").val();
																var $this=$("#printfootlist");
																var $allprintfooternumber=$("#allprintfooternumber");
																$.ajax({
																      type:"POST",
																	   url:"portlet/trace/addFootprint.do",
																	   data:"userId="+userId+"&itemId="+itemId+"&type="+type,
																       dataType:"json",
																	   cache:false,
																   success:function(Json){
																         
																         // alert(Json.hasDone);
																         // alert(Json.username);
																           if(Json.hasDone!=""){
																            alert('对不起,您已经踩过!');
																           }
																   			else if (Json.username!=""){
																   			
																			if ($this.find("li").length-1 > 4){$this.find("li:last").prev().prev().remove();}
																   			$("#printfootlist li:first").before("<li><span class=\"imgborder\"><a href=\"viewSpace.do?userId="+userId+"\"><img src=\""+Json.image+"\" /></a></span><a href=\"viewSpace.do?userId="+userId+"\">"+Json.username+"</a></li>");
																			$allprintfooternumber.text($allprintfooternumber.text()/1+1);
																   			
																   			}
																   			else{
																   			$.msgbox.msgbox(150,100,"添加脚印","页面读取失败！");
																   			}
																		   $.msgbox.closemsgbox();
																		   },
																   error:function(){$.msgbox.msgbox(150,100,"添加脚印","页面读取失败！")},
																   beforeSend:function(){$.msgbox.msgbox(150,100,"添加脚印","页面读取中！")},
																   complete: function(){}
																   })
				})		
				
  
})