	var isHover = 0;
	$(document).ready(function(){
		$('.topmenu ul li:last a').css('border-right','1px #1F3957 solid');
		
		$('#mail_loading').hide();		

		$('.tip').animate({'opacity':1},10000).slideUp();
		$('.icon_tip').animate({'top':17},200).animate({'top':22},200).animate({'top':17},200).animate({'top':22},200).animate({'top':17},200).animate({'top':22},200).animate({'top':17},200).animate({'top':22},200).animate({'top':17},200).animate({'top':22},200).animate({'opacity':1},8000).slideUp();
		$('#btnSubmit').removeAttr('disabled');		

		getComment($('#current_post_id').val(),1);	

		//post new comment
		$('#btnSubmit').click(function(){
			if($('#content').val() == ""){
				alert("Bạn chưa nhập nội dung cho bài bình luận!");
				$('#content').focus();
			}else{
				var c_id = $('#current_post_id').val();
				var c_name = $('#user').val();
				var c_email = $('#email').val();
				var c_content = $('#content').val();
				addComment(c_id,c_name,c_email,c_content);
			}
		});		

		//reader

		$('.news_item').each(function(){

			var news = $(this);
			//Phóng to bài viết
			$(this).find('#zoom').click(function(){
				$('.news_big').css({'width':'700px','top':'10px'});
				$('.news_big').html("<div id='close_icon' onClick='closePanel()'><img src='image/x.png' title='Đóng khung này lại' /></div>" + news.html() + '<hr><a href="javascript:window.print();" style="color: #225599;">In bài này</a>');
				$('.mask').fadeIn();
				$('.news_full').fadeIn();
			});
			//Tao trang in
			$(this).find("#print").click(function(){
				$('.news_big').css({'width':'700px','top':'10px'});
				$('.news_big').html("<div id='close_icon' onClick='closePanel()'><img src='image/x.png' title='Đóng khung này lại'/></div>" + news.html());
				$('.mask').fadeIn();
				$('.news_full').fadeIn();
			});
		});	

		$('.mask').click(function(){
			$(this).fadeOut();
			$('.news_full').fadeOut();
		});		

		$('.news_big').each(function(){
			$(this).mouseover(function(){
				isHover = 1;
			});			

			$(this).mouseout(function(){
				isHover = 0;
			});
		});		

		 $('.news_full').click(function(){
			 if(isHover==0){
				 $('.mask').fadeOut();
				 $('.news_full').fadeOut();
			 }
		 });
		 
		 $('#sendmail').click(function(){
			$('.news_big').html("<div id='close_icon' onClick='closePanel()'><img src='image/x.png' title='Đóng khung này lại' /></div>" + $('#sendmail_form').html());
				$('.news_big').css({'width':'400px','top':'100px'});
				$('.mask').fadeIn();
				$('.news_full').fadeIn();	
				$('.btnSendMail').click(function(){

					if(($('#s_mail').val()=="")||($('#s_tomail').val()=="")||($('#s_subject').val()=="")){

						alert("Bạn chưa nhập đủ thông tin!");

						return false;

					}else{

							$('#mail_loading').show();

							$('#btnSendMail').attr('disabled','disabled');

						 $.post("email.php",{

							s_mail: $('#s_mail').val(),

							s_tomail: $('#s_tomail').val(),

							s_subject: $('#s_subject').val(),

							s_title: $('#s_title').val()
						},function(data){
							$('#mail_loading').hide();
							if(data!=""){
								$('.news_big').html("<div id='close_icon' onClick='closePanel()'><img src='image/x.png' title='Đóng khung này lại' /></div><h1>Email đã được gửi thành công!</h1>");
							}else{
								alert("Có sự cố khi gửi Email, xin thử lại sau!");
							}
						});
					}
				 });		 
		 });
	});	

	function closePanel(){
		$('.mask').fadeOut();
		$('.news_full').fadeOut();
	}

	function getComment(id,page){
		$('#ajax-loading').show();
		$('#comment_list').hide();
		 $.post("binhluan.php?act=list",{
			id: id,
			page: page
		},function(data){
			$('#comment_list').html(data);
			$('#ajax-loading').hide();
			$('#comment_list').show();
		});
	}

	function addComment(id,name,email,content){

		$('#btnSubmit').attr('disabled','disabled');

		$('#ajax-loading').show();

		$('#comment_list').hide();

	    $.post("binhluan.php?act=add",{

			cid: id,

			cname: name,

			cemail: email,

			ccontent: content

		},function(data){

			$('form')[0].reset();

			$('#btnSubmit').removeAttr('disabled');

			$('#comment_list').html(data);

			$('#ajax-loading').hide();

			$('#comment_list').show();

			$('.msgError').show();

		});

	}
