function initMicroblog(){
	$("#selecting").toggle(function() {
	  $(".DIY_box").show("slow");
	}, function() {
	   $(".DIY_box").hide("slow");
	});

	$("#close").click(function(){
		 $(".DIY_box").hide("slow");
	});
	
	$("a[ref='listcomment']").one('click', function() {
		var module="microblog";
		var recordId = $(this).parents("li").attr("recordid");
		var uid= $("input[name='curuser']").val();
		
		$.post("../comment/list3.asp", { module: "microblog",recordId:recordId, time: (new Date().getTime()) },
	   		function(data){
		   		$("li[recordid="+recordId+"]").append(data);
		  		 $("li[recordid="+recordId+"]").find("div[ref='commentblock']").show("slow");
		});
			
					
	}).toggle(function(){
		$(this).parents("li").find("div[ref='commentblock']").show("slow");	
	
	}, function() {
	   $(this).parents("li").find("div[ref='commentblock']").hide("slow");
	});
	
	jQuery("a[rel='facebox']").facebox(); 


}

function initMicroblog2(){
$("#mb_publish").click(function(){
				
	var content = $("textarea[name='content']").val();
	if(content.length<1){
		msgbox("内容不能为空");
		$("textarea[name='content']").focus();
	}else{
		//ajax提交
		var uid= $("input[name='curuser']").val();
		if(uid==null || uid.length<1){
			$.facebox({ajax: '<s:url  action="home/login2"/>?time='+new Date().getTime()  });
		}else{
			$.post("../mb/publish.asp", { content: content,imgurl:$("#Upfiler_file_iframe").contents().find("#imgurl").text() , time: (new Date().getTime()) },
			   function(data){
			     $(data).prependTo("#mblist");
			     $("textarea[name='content']").empty().hide().show("100000");
			     var blogs = $(".person_atten_r").find(".num a").text();
	   			 blogs = parseInt(blogs)+1;
	   			 $(".person_atten_r").find(".num a").text(blogs);
			     $("#wordresult").html(140);
			     $("#Upfiler_file_iframe").unbind();
			     $("#Upfiler_file_iframe").contents().find("#imgurl").empty();
			     $("#publisher_perch").hide();
			     $("#publisher_image").show();
			});
		}
	}

});

$("textarea[name='content']").keyup(function(event){
	var word = $(this).val().length;
	if(parseInt(word)>140){//字数大于100取前100个字符
		word = 140;
		var content = $(this).val();
		content = content.substring(0,140); 
		$(this).val(content);
	}
	var result = 140-word ;
	$("#wordresult").html(result);
	$(this).val(content);
});

$("#publisher_file").change(function() {
	var uid= $("input[name='curuser']").val();
	if(uid==null || uid.length<1){
		$.facebox({ajax: '../home/login2.asp?time='+new Date().getTime()  });
	}else{
		$("#publisher_image_form").submit();
 			$("#publisher_image").hide();
		$("#publisher_image_loading").show();
	}
});

$("#Upfiler_file_iframe").bind("load",function(){
	$("#publisher_image_loading").hide();
	
	$("textarea[name='content']").append("分享图片").trigger('keyup');
	$("#publisher_perch_name").text($("#Upfiler_file_iframe").contents().find("#imgname").text());
	$("#publisher_perch").show();
	$("#publisher_preimage").find("img").attr("src",$("#Upfiler_file_iframe").contents().find("img").attr('src'));
	//alert($("#Upfiler_file_iframe").contents().find("#imgurl").text());
	//alert($("#Upfiler_file_iframe").contents().find("#imgname").text());
});

$("#publisher_perch").mouseover(function(){
	$("#publisher_imgpreview").show();	

}).mouseout(function(){
	$("#publisher_imgpreview").hide();

});

$("#publish_topic").click(function(){
	var content = $("textarea[name='content']").text();
	var flag = content.indexOf('#请在这里输入自定义话题#');
	//alert(content.lastIndexOf('#请在这里输入自定义话题#'));      
	     
	if(flag == -1){
		$("textarea[name='content']").append('#请在这里输入自定义话题#');
		var curContent = $("textarea[name='content']").text();
		var newFlag = curContent.indexOf('#请在这里输入自定义话题#');
		var range= document.body.createTextRange();  
		range.moveToElementText(cc)      
		range.moveEnd('character',-1);     
		range.moveStart('character',newFlag+1);
		range.select(); 
	}else{
		var curContent = $("textarea[name='content']").text();
		var newFlag = curContent.indexOf('#请在这里输入自定义话题#');
		var ff = curContent.substring(newFlag,curContent.length).length - curContent.length-1;
		var range= document.body.createTextRange();  
		range.moveToElementText(cc);    
		range.moveEnd('character',ff);     
		range.moveStart('character',flag+1);
		range.select();
	
	}
	
});




}
function addConcen(followid){
	var uid= $("input[name='curuser']").val();
	if(uid==null || uid.length<1){
		$.facebox({ajax: '../home/login2.asp?time='+new Date().getTime()  });
	}else{
		$.post("../mb/addConcern.asp", { followerid: followid, time: (new Date().getTime()) },
		   function(data){
		    $(".microbo_index_rightC02").find("p[recordid="+followid+"]").html("已关注");
		    var followers = $(".person_atten_m").find("a").text();
		    followers = parseInt(followers)+1;
		    $(".person_atten_m").find("a").text(followers);
		});
	}

}

function deleteComment(recordid,cid){
		var module="microblog";
		var uid= $("input[name='curuser']").val();
		if(uid==null || uid.length<1){
			$.facebox({ajax: '../home/login2.asp?time='+new Date().getTime()  });
		}else{
			$.post("../comment/delete.asp", { commentId: cid,recordId:recordid,module:module, time: (new Date().getTime()) },
			   function(data){
			   $("#mblist").find("li[recordid="+recordid+"]").find("div[ref='commentblock']").find("li[cid="+cid+"]").remove();
				var commentcount = $("li[recordid="+recordid+"]").find("div[ref='commentblock']").find(".PL_list").find("span[ref='commentcount']").text();
				commentcount = parseInt(commentcount)-1;
				$("li[recordid="+recordid+"]").find("div[ref='commentblock']").find(".PL_list").find("span[ref='commentcount']").text(commentcount);
				$("li[recordid="+recordid+"]").find("a[ref='listcomment']").find("span").text("("+commentcount+")");
				if(commentcount == 0){
					$("li[recordid="+recordid+"]").find("div[ref='commentblock']").find(".PL_list").hide();
				}
			});
		
		}
		
		
	}
	
function addFavorite(contentid){
	var uid= $("input[name='curuser']").val();
	if(uid==null || uid.length<1){
		$.facebox({ajax: '../home/login2.asp?time='+new Date().getTime()  });
	}else{
		$.post("../mb/addFavorite.asp", { microBlogId: contentid, time: (new Date().getTime()) },
		   function(data){
		    msgbox(data);
		});
	
	}
	

} 

function deleteMB(contentid){
	var uid= $("input[name='curuser']").val();
	if(uid==null || uid.length<1){
		$.facebox({ajax: '../home/login2.asp?time='+new Date().getTime()  });
	}else{
		$("#mblist").find("li[recordid="+contentid+"]").hide("slow");
		$.get("../mb/delete.asp", { microBlogId: contentid, time: (new Date().getTime()) });
		
	     }
}

function delPic(){
	$("#publisher_perch").hide();
	$("#publisher_image").show();
}