$(document).ready(function(){
	
	  _initDreamJourey();
	  
	  _initseedJourney();
	  
})


function _initDreamJourey(){
	 
	 blogsoperate(mid,0);
}


// 分 页
function setpage(fun,mid,page,totalpage){
			
			var up;
			var uppage;
			var next;
			var nextpage;
			if(totalpage==1)
			{
				up='';
			}
			else if(page>1)
			{
				uppage = page-1;
				up='<a href="javascript:'+fun+'('+mid+','+uppage+');">上一页</a>';
			}
			else
			{
				up='上一页';
			}
			if(totalpage==1)
			{
				next ='';
			}
			else if(page<totalpage)
			{
				nextpage = page+1;
				next ='<a href="javascript:'+fun+'('+mid+','+nextpage+');">下一页</a>';
			}
			else
			{
				next ='下一页';
			}
			    return up+' '+next;

}




// 梦想日志

function blogsoperate(mid,page){

	var blogssum = $(".dreaminfo[@mid="+mid+"] a[@item=dreamblogs] span").html();
		
	if(blogssum==0)
	{
		  var html;
		     
              html='<div class="dreamblogs" mid="'+mid+'"><div class="nodate">此梦想还没有追梦旅程。追梦日志用以记录每个梦想成真的过程和经验，帮助更多的人梦想成真！';
			  
			  html+='</div><div class="button"></div></div>';	
			 
			  $("div[@describeid="+mid+"]").prepend(html);
	}
	else
	{
     <!-- start -->
	 $.getJSON(
			   "/"+domain+"/dream/journeylist/mid/"+mid+"/page/"+page,
				 function(msg)
					{
					  if(msg!="")
					  {
							 var html = "";
		
							 var length = msg.blog.length;
							 
							 var item   = msg.blog;
													 
							 for(i=0;i<length;i++)
							 {
								 html+='<div class="journeycontent" id="'+item[i].id+'"><div class="top"><img src="/images/dream/qizi.gif" /> '+item[i].time+' <span>'
								 
								 
								 html+='<a href="/'+domain+'/dream/dreamjourneyshow/id/'+item[i].id+'" target="_blank"> 评论('+item[i].comment+')</a> ';
								 
								 if(loginStatus=="host")
								 {
								
				                    html+='｜<a href="/'+domain+'/dream/dreamjourneyshow/id/'+item[i].id+'/type/edit" target="_blank">编辑</a> ｜';
				
			                    	html+='<a href="javascript:del('+item[i].id+')">删除</a>';
								 }
								 
								 html+='</span></div><div class="middle"> '+item[i].content+' </div>';
								 
								 html+=' <div class="foot"></div><div class="road"></div></div>';
							 }
						  
						    var page       = msg.page.page;
							
							var totalpage  = msg.page.totalpage;
							
							var totalcount = msg.page.totalcount;
							
							if(totalcount>0)
							{
								var pagestr    = setpage("blogsoperate",mid,page,totalpage);
								
								
							    $(".page").html(pagestr);
						    }
							
							
						    $(".dreamjourney").html(html);
							
							$(".totalcount").html(totalcount);
							
					 }
			  });
		 <!-- end -->
	}
}

function _initseedJourney(){

                   $(".journey img:last").click(function(){
				
				   var cont = KE.util.getData("content");

				   if(cont=="")
				   {
				      alert("请输入内容");
				   }
				   else
				   {
					  <!-- start -->
						$.post(
					   "/"+domain+"/dream/journeysave",
						{cont:cont,mid:mid},
						 function(msg)
							{	
							 if(msg=="nologin")
							 {
								  alert("请您先登录后，再进行操作");
							 }
							else if(msg=="1")
							 {
								  blogsoperate(mid,0);
								  
								  window.location.hash="se";
								  
								  clearEditor('content');
							 }
			                
					    });
		              <!-- end -->
                   }
			})
}


function clearEditor(id) {
	
    KE.g[id].iframeDoc.open();
	
    KE.g[id].iframeDoc.write(KE.util.getFullHtml(id));
	
    KE.g[id].iframeDoc.close();
	
    KE.g[id].newTextarea.value = '';
	
}



// 删除日志

function del(id)
{
		 if (confirm("温馨提示：删除后不可恢复，你确定要删除吗？"))
		 {
		         <!-- start -->
						$.post(
				   "/"+domain+"/dream/Journeydel",
					{id:id},
					 function(msg)
						{
						  if(msg=="login")
						  {
							    alert("请你先登录");
						  }
						  else
						  {
							    $(".journeycontent[@id="+id+"]").slideUp();
                          }
					}); 
				  <!-- end -->
	  }     		  
}




function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= w/h){
if(image.width>w){
ImgD.width=w;
ImgD.height=(image.height*w)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>h){
ImgD.height=h;
ImgD.width=(image.width*h)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
}
}
