$(function()
{
	cargarNoticias(0);
});

function cargarNoticias(nPage)
{
	$('#news').load($.sah.actionUrl('News','renderNews'), {
		page: nPage
	}, function()
	{
		// callback
	});
}

function cargarComentarios(nLimit)
{
	if(nLimit == undefined)
		nLimit = 0;
	$.ajax( {
		url: $.sah.ajaxUrl('Index', 'ajax_getComments'),
		data: {
			item_id: nLastPhotoLoadedId,
			table_name: 'fotos',
			limit: nLimit,
			order: nLimit == 0 ? 'ASC' : 'DESC'
		},
		beforeSend: function()
		{
			$('#loading_comments').show();
			$('#last_comments').empty();
		},
		success: function(aComments, st)
		{
			if(aComments.length == 0)
				$('#last_comments').text('No comments');
			else
			{
				if(nLimit > 0)
					aComments.reverse();
				$.each(aComments, function(i, Comment)
				{
					$('#last_comments').append(
						DivComment =
							$('<div>').attr('id', 'comment' + Comment.id).addClass('comment')
									.append($('<b>').text(Comment.autor + ':')).append(
										$('<div>').text(Comment.comment)).append(
										$('<div>').addClass('album_date').text(
											'On ' + Comment.short_date)));
					/* can edit? using foo ninja var -_- jusha!! */
					if(foo)
						DivComment.append('[').append(
							$('<a>').data('comment_id', Comment.id).attr('href', 'javascript:;')
									.text('Delete').click(
										function(e)
										{
											if(confirm('Delete comment?'))
											{
												nCommentId = $(this).data('comment_id');
												$.ajax( {
													url: $.sah.ajaxUrl('Index',
														'ajax_deleteComment'),
													data: {
														comment_id: nCommentId
													},
													success: function(bOk, st)
													{
														if(bOk)
															$('#comment' + nCommentId).slideUp(
																'fast', function()
																{
																	$(this).remove();
																});
													}
												});
											}
										})).append(']');
				});
			}
			// $('#last_comments').show();
		},
		complete: function(Xhr, st)
		{
			$('#loading_comments').hide();
		}
	});
}
