﻿$(document).ready(function($){
						   				   
	  _initMusic();
	  //留言
	  CommentShow(1)
	  
	  _initSendComment();  
	  
	 _initLogin();
})

function copyToClipBoard(){ 
 
     if($.browser.msie)
	 {
	   url = this.location.href; 
	   
	   window.clipboardData.setData("Text",url);   
	   
	   alert("复制成功，您可以粘贴到QQ/MSN上推荐给您的好友，分享让生活更美好！"); 
	 }
	 else
	 {
	   alert("只有在IE上方可使用此功能"); 
	 }
}


function visitgarden(){
	
     <!-- start -->
				$.get(
			   "/action/aoke",
				 function(msg)
					{
						if(msg!="")
						{
							 window.location.href = '/'+msg+'/garden';
					    }
					}
				);
    <!-- end -->	
}


function setRain(){
	
	
	  $("#cup").attr("src","/images/garden/cup1.gif")
	
      var flashobj = thisMovie("mygarden");
	  
	   flashobj.setRain();
	   
	   <!-- start -->
			$.post(
		   "/"+domain+"/garden/addpersist",
			 function(msg){});
	   <!--  end  -->
}




function thisMovie(movieName) {
		    if (navigator.appName.indexOf("Microsoft") != -1)
			{
		        return window[movieName]
		    }
		    else {
		        return document[movieName]
		    }
	}




function _initMusic(){
	
     $("img[@status]").click(function(){
									  
			var status = $(this).attr("status");	
			
		    var flashobj = window.document.mygarden;
			
			if(status=="stop")
			{
				 if(music==4)
				 {
						  url = musicurl;	 
				 }
				 else
				 {
						  url  = music;
				 }
				         flashobj.startSound(url);	
			             $(this).attr("src","/images/garden/stop.jpg")
			             $(this).attr("status","start")
			}
			else
			{
						 flashobj.stopMusic();	
						 $(this).attr("src","/images/garden/start.jpg")
						 $(this).attr("status","stop")
			}
	 })
}


function  _initSendComment(){

        $(".sendcomment .send img").click(function(){
									
			  var content = KE.util.getData("content");
	
			  if(content=="")
			  {
				   alert("请您输入内容"); 
			  }
			  else
			  {
				   <!-- start -->
						$.post(
					   "/"+domain+"/garden/board",
						{content:content},
						 function(msg)
							{
							  if(msg=="nologin")
							  {
								  alert("请您先登录再进行操作");
							  }
							  else
							  {
								  CommentShow(1);
								  
								  clearEditor('content'); 
								  
								  window.location.hash="se";
							  }
					    });
			       <!--  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 CommentShow(page){
		
	  <!-- start -->
	  $.getJSON(
			   "/"+domain+"/garden/boardlist/page/"+page,
			   
				 function(msg)
				  {
					  if(msg!="")
					  {
						 var html="";
						 
						 var length = msg.board.length;
						 
						 var item   = msg.board;
 
					     for(i=0;i<length;i++)
						 {
				             if(item[i].svisualize=='')  
							 {
								item[i].svisualize='/images/default/head.jpg';
							 }
							 
				    html+='<div class="comment" id="'+item[i].id+'"><div class="head"><p><a href="/'+item[i].domain+'" target="_blank">';
					
					html+='<img src="'+item[i].svisualize+'" /></a></p><p><a href="/'+item[i].domain+'" target="_blank">'+item[i].username+'</a></p></div>';
				  
				    html+='<div class="commentbody"><ul><li class="time">留言时间：'+item[i].timestamp;
				  
				  if(loginStatus=="host")
				  {
				     if(item[i].replay!="")
				     {
						var temp ="编辑回复"
					 }
					 else
					 {
						var temp ="回复"
				     }
					html+='<span><a href="javascript:void(0);" type="edit">'+temp+'</a> | <a href="javascript:void(0);" type="del">删除</a></span>'  
				  }
							   
				    html+='</li><li class="content">'+item[i].content+'</li></ul>';	
				  
				  if(item[i].replay!="")
				  {
				  html+='<ul class="replay"><li class="replaytime">主人回复：('+item[i].replaytime+')</li> <li class="replaycontent">'+item[i].replay+'</li></ul>';
				  }
				  
				  html+='</div><div class="clear"></div></div>';
				  
				         }
						    var page           =  msg.page.page;
							
							var totalpage      =  msg.page.totalpage;
							
							var totalcount     =  msg.page.totalcount;
							
						    if(totalpage>0)
						    var pagestr        =  setpage(page,totalpage)
		
							$(".comment").remove();
							
							$(".totalcount").html(totalcount);

		                    $(".content-top").after(html); 
							
							$(".comments .bottom").html(pagestr); 
							
							_initcomedit();
				   }
			  });
	  <!-- end --> 
}



//评论的操作

function _initcomedit(){
	
	      $(".comments .bottom a").click(function(){
												  
	       window.location.hash="se";
		   
		  })
	
	
           $(".comment a[@type]").click(function(){
																	 
                var type = $(this).attr("type");
				
				var id   = $(this).parent().parent().parent().parent().parent().attr("id");
	
				if(type=="del")
				{
					comdel(id);
				}
				else
				{
				    comedit(id);
				}
		   })    
}

// 评论删除

function comdel(id){
	
      if (confirm("删除后不可恢复，你确定要删除吗？"))
	  {
				 <!-- start -->
						$.post(
					   "/"+domain+"/garden/boarddel",
						{id:id},
						 function(msg)
							{
							  if(msg=="nologin")
							  {
								  alert("请您先登录再进行操作");  
							  }
							  else
							  {
								 $(".comment[@id="+id+"]").slideUp();
							  }
							  
					  });
			     <!-- end -->
	  }
}

//回复
function comedit(id){
	
	
	var sum = $(".comment[@id="+id+"] .replay").size();
	
	var replay = "";
	
	var relpaysum = $(".comment[@id="+id+"] .replays").size();

   if(relpaysum==0)
   {
	
		if(sum!=0)
		{
			 replay =  $(".comment[@id="+id+"] .replaycontent").html();
			 
					   $(".comment[@id="+id+"] .replay").hide();
		}	
		
	   var html='<ul class="replays"><li>主人回复：</li>'
	
	   html+='<li><input type="text" value="'+replay+'" /> <a replay="'+id+'">保存</a> <a canel="'+id+'">取消</a></li></ul>';
	
	   $(".comment[@id="+id+"] .commentbody").append(html);
	   
	   
	   $("a[@replay="+id+"]").click(function(){
													
			     var replay = $(this).parent().find("input").val();

				 if(replay=="")
				 {
				    alert("请您输入内容");	 
				 }
				 else
				 {
					 <!-- start -->
					  $.post(
					   "/"+domain+"/garden/replay",
						{id:id,replay:replay},
						 function(msg)
							{
							  if(msg=="1")
							  {
									$(".comment[@id="+id+"] .replays").remove();
									
									var sum = $(".comment[@id="+id+"] .replay").size();
									
									if(sum!=0)
									{
										$(".comment[@id="+id+"] .replaycontent").html(replay);
										
										$(".comment[@id="+id+"] .replay").show();
									}else
									{
								       	var  html='<ul class="replay"><li class="replaytime">主人回复：</b></li><li class="replaycontent">'+replay+'</li></ul>';	
		 
									    $(".comment[@id="+id+"] .commentbody").append(html);
									}
							  }
					  });
			          <!-- end --> 
				  }
		  })

          $("a[@canel="+id+"]").click(function(){
																
			    $(this).parent().parent().remove();
				
				$(".comment[@id="+id+"] .replay").show();
		  })	  		 
   }
}




function setpage(page,totalpage){
					var up;
					var uppage;
					var next;
					var nextpage;
					var total;
					
					total = "第 "+page+" 页 / 共 "+totalpage+" 页"    
					
					if(totalpage==1)
					{
						up='';
					}
					else if(page>1)
					{
						uppage = page-1;
						
						up='<a href="javascript:CommentShow(1);">首页</a> <a href="javascript:CommentShow('+uppage+');">上一页</a>';
					}
					else
					{
						up=' 首页  上一页';
					}1
					if(totalpage==1)
					{
						next ='';
					}
					else if(page<totalpage)
					{
						nextpage = page+1;
						next ='<a href="javascript:CommentShow('+nextpage+');">下一页</a> <a href="javascript:CommentShow('+totalpage+');">末页</a>';
					}
					else
					{
						next ='下一页 末页';
					}
					return total+' '+up+' '+next;
}

function _initLogin()
{
     $(".commentlogin a:first").click(function(){
											   
		var username = $("#user").val();
		
		var passwd   = $("#pw").val();
		
		if(username==""||passwd=="")
		{
			alert("请输入完整的用户名和密码");
		}
		else
		{	
		 <!-- start -->
				$.post(
			   "/login/login",
				{name:username,pass:passwd},
				 function(msg)
					{
					  if(msg=="nouser")
					   {
						  $("#user").val("");
						 
						  $("#pw").val("");
						 
					 	   alert("此用户不存在");
					   }
					   else if(msg=="nopasswd")
					   {
						   alert("密码错误,请重新输入密码");
						  
						   $("#pw").val("");
					  }
					  else
					  { 
					      $(".commentlogin").html("登录成功，请发表留言：");
					  }
				});
		 <!-- end -->
		}										   
	 })
}



function setBottle(){

	   $("#cup").attr("src","/images/garden/cup.gif");
}

