$(document).ready(function($){

    _initLogin();
	
	_initKeyup();
	
	_initheight();
	
	_initAddFavorite();
	
	_initHeigh();
})




function _initHeigh(){
	
	   var height = $(".cateorycontent").height();
	   
	   if(height<100)
	   {
		   $(".cateorycontent").height(100)
	   }
}









function _initheight(){
	
	 var  contentheight    =   $(".cross-left-content").height();
	 
	 var  viewpoint        =   $(".viewpoint").height();
	 
      if(contentheight>viewpoint)
	  {
		  $(".viewpoint").height(contentheight);
	  }
	  else
	  {
		  $(".cross-left-content").height(viewpoint);
      }
	
}




function _initLogin(){
	
	   $(".login img").click(function(){
												 
		 var username = $(".login input:first").val();
		 
		 var passwd   = $(".login input:last").val();

		 if(username=="")
		 {
		    alert("请输入用户名");	 
			
			$(".login input:first").focus();
		 }
		 else if(passwd=="")
		 {
		    alert("请输入密码");	 
			
			$(".login input:last").focus();
		 }
		 else
		 {
		     <!-- start -->
				$.ajax({
					  url: "/login/Loginindex",
					  type: 'post',
					  dataType: 'json',
					  data: 'name='+username+'&pass='+passwd,
					  success: function(data){
						  
						    if(data.username=="nouser")
							 {
								    $(".login input:first").val("");
								 
								    $(".login input:last").val("");
									
								    alert("此用户不存在");
							 }
							 else if(data.username=="nopasswd")
					         {
								  $(".login input:last").val("");
								  
								  alert("密码错误,请重新输入密码");  
					         }
							 else
							 {
								 var html;
								 
								 html ='欢迎回来，<b><a href="/'+data.domain+'">'+data.username+'</a></b> ：<a href="/'+data.domain+'/manage/dreamadd">添加梦想</a>  | ';
								 
							     html+='<a href="/'+data.domain+'/manage/blogadd">发表日志</a> | <a href="/'+data.domain+'/manage/photoupload">上传图片</a> | ';
								 
							     html+='<a href="/'+data.domain+'/inspiration">添加灵感</a> |<a href="/login/logout">退出</a>  ';
								 
								$(".login").html(html);
							}
					  }
				});
	         <!-- end -->
	     }
    })	

}











function _initAddFavorite(){
	
       $("a[@type]").click(function(){
															 
				var type = $(this).attr("type");
				
				var url  = document.location.href; 

				if(type=="cope")
				{
					copyToClipBoard(url);
			    }
				else
				{
					AddFavorite(url,document.title)
			    }
	   })
	   
}






function AddFavorite(sURL,sTitle) {

	  
	  try{
            window.external.addFavorite(sURL, sTitle);
       }
       catch (e)       
	   {
			   try         
			   {
					window.sidebar.addPanel(sTitle, sURL, "");
			   }
			   catch (e)
			   {
	
				   alert("加入收藏失败，请使用Ctrl+D进行添加");
			   }
       }    
} 
 
 
 
 
function copyToClipBoard(url){ 
 
     if($.browser.msie)
	 {
	   window.clipboardData.setData("Text",url);   
	   
	   alert("复制成功，您可以粘贴到QQ/MSN上推荐给您的好友，分享让生活更美好！"); 
	 }
	 else
	 {
	   alert("只有在IE上方可使用此功能"); 
	 }
}
 
 
 function _initKeyup(){
	
	if($.browser.msie)
	{
	    $(document).keyup(function(){
			if(window.event.keyCode==13)
			{
			    $(".login img").click();
			}	
		})
	}
	else
	{
         $(document).keydown(function(event){
				  
				if(event.keyCode==13){ 
				
			       $(".login img").click();
				  
			    }
	      })
	}
}

