document.write ('<script type="text/javascript" src="/assets/js/jquery/jquery.truncate.js"></script>');


$(function (){
	FB.ensureInit(function (){
		load_comments(1, 'false');
	});
});

function add_comment (){
	var url = '/'+loaded_module+'/comentar';
	var post_data = {comment: $("#comment").val(), parent: c_parent, add_comment: 1};
	
	$("#comments_form_container").html('').addClass('processing');
	
	$.post(url, post_data, function (response){
		$("#comments_form_container").removeClass('processing').html(response);
		if ($("#comments_form_container > .procFail").size() == 0) load_comments (1, 'true');
	});
}

function comment_box (){
	var url = '/'+loaded_module+'/comentar';
	
	$("#comments_form_container").html('').addClass('processing');
	
	$.post(url, function (response){
		$("#comments_form_container").removeClass('processing').html(response);
		
		$("#comments_form_container > .hidden").slideDown('fast');
	});
}

function load_comments (page_number, hide_first){
	var url = '/'+loaded_module+'/comentarios';
	var get_data = {parent: c_parent, hidefirst: hide_first, page: page_number};
	
	$("#comments_container").html('').addClass('processing');
	
	$.get(url, get_data, function (response){
		$("#comments_container").removeClass('processing').html(response);
		
		$('.comment_c').truncate({
							textmore: ' leer el mensaje completo...',
							textless: ' ...menos'
						});
		
		$("#comments_container .hidden").slideDown('fast');
		
		$("#pagination > a").click(function (){
			load_comments(parseInt($(this).attr('href').replace("#", '')), 'false');
			return false;
		});
		
		if ($.browser.msie && $.browser.version < 7) {
			$("#comments_container .comment").each(function (){
				if ($(this).height() < 65) $(this).height(65);
			});
			
			$("#footer").css('bottom', '0');
		}
		
		FB.XFBML.Host.parseDomElement(document.getElementById('comments_container'));
	});
}

function del_comment (c_id){
	var url = '/'+loaded_module+'/comentar';
	var confirmation = confirm('¿Está seguro que desea borrar este comentario?.\n Esta acción no se puede deshacer');
	
	if (confirmation) {
		$.post(url, {del: c_id.replace('comment_', '')}, function (response){
			if (response == 'true') {
				$('#'+c_id).parent().slideUp('fast', function (){
					$(this).remove()
				});
			};
		});
	}
}
