$(document).ready(function() {
	$('#comment').keyup(limit_comment);
	
	$(".view_all_comments").click(function(e) {
		e.preventDefault();
		ID = $(this).attr('id');
		exanded_height = $('#comments_'+ID).height();
		parent_height = $(this).parent().height() + 10;	
		$(this).before($(this).text()).remove();
		$('#comments_'+ID).removeClass('hide').css({'display': 'block' , 'marginTop' :-exanded_height}).animate({marginTop : 0}, 750);
		return false;
	});
	
	$(".btn_comment_articles").click(function(e) {
		e.preventDefault()
		var ID = $(this).attr('rel');
		var comment  = $('#comment_'+ ID).val();
		var section = $('#section_'+ ID).val();
		
		if(ID.length <= 0) {			
			return false;
		}
		if(comment.length <=0) {			
			return false;
		}
		
		_lag.hover_box('#posting');	
		
		$.post('/includes/comment_add_articles.php', {
			'articleID': ID,
			'comment' : comment,
			'section' : section
			},
			function(data) {
				if(data == 'success') {
					_lag.hover_box('#posted');
					setTimeout(function(){window.location.reload();}, 1000);
				} else {
					$(_lag.target).html(_lag.temp);
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$('#comment_message').html(data);
				}
			}
			);
	});
/*	$(".btn_comment_feeds").click(function(e) {
		e.preventDefault()
		var ID = $(this).attr('rel');
		var comment  = $('#comment_'+ ID).val();
		var section = $('#section_'+ ID).val();
		
		if(ID.length <= 0) {			
			return false;
		}
		if(comment.length <=0) {			
			return false;
		}
		
		_lag.hover_box('#posting');	
		
		$.post('/includes/comment_add_feeds.php', {
			'articleID': ID,
			'comment' : comment,
			'section' : section
			},
			function(data) {
				if(data == 'success') {
					_lag.hover_box('#posted');
					setTimeout(function(){window.location.reload();}, 1000);
				} else {
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$('#comment_message').html(data);
				}
			}
			);
	});
*/
	$('.feeds_insert').bind("click", function(event) {
		event.preventDefault();
		var id = $(this).attr('rel');
		var feed = $('#feed_'+ id).val();
		
		if(feed.length <= 0) {
			$("#message").html('error');
			return false;
		}
		
		_lag.hover_box('#posting');	
		$.post("/includes/feed_insert.php", {
			'feed' : feed
			}, function(data) {
				if(data == 'success') {
					_lag.hover_box('#posted');
					setTimeout(function(){window.location.reload();}, 2000);
				} else {
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$("#message").html(data);
				}
		});
		return false;
	});
	$('.feeds_comments_insert').bind("click", function(event) {
		event.preventDefault();
		var feedID = $(this).attr('rel');
		var comment = $('#feeds_comments_'+ feedID).val();
		var refer_url = $("#refer_url").val();
		
		if(comment.length <= 0) {
			$("#message").html('error');
			return false;
		}
		
		_lag.hover_box('#posting');	
		$.post("/includes/feeds_comments_insert.php", {
			'feedID' : feedID,
			'comment' : comment,
			'refer_url' : refer_url
			}, function(data) {
				if(data == 'success') {
					_lag.hover_box('#posted');
					setTimeout(function(){window.location.reload();}, 2000);
				} else {
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$("#message").html(data);
				}
		});
		return false;
	});
});
