Comments = {
	Init : function() 
		{
			$( 'input[name=Comment_iPageGadgetId]' ).each( function( index, elem ) { Comments.GetComments( elem ) } );
		},
	SubmitComment : function( oLink )
		{
			var oForm = $(oLink).parents( 'form' ).get(0);
			
			$( '#oCommentWait', oForm ).fadeIn();
			$( '#oCommentError', oForm ).fadeOut();
			$.post( $('#PROJECT_RELATIVE_PATH').val() + 'comment-send/',
						$( oForm ).serialize(),
						function( data )
							{
								$('#oCommentWait', oForm).fadeOut();
								if( data.error )
								{
									$('#oCommentErrorText', oForm).html( data.error );
									$('#oCommentError', oForm).fadeIn();
									return;
								}
								if( data.success && data.id )
								{
									// Refresh list
									Comments.GetComments( $( 'input[name=Comment_iPageGadgetId]', oForm ).get(0) );
									
									$( 'input[name=Comment_sUserName]', oForm ).val('');
									$( 'input[name=Comment_sUserEmail]', oForm ).val('');
									$( 'textarea[name=Comment_sComment]', oForm ).val('');
								}
							},
							'json' );
		},
	
	GetComments : function( oHdnPageGadgetId )
		{
			$.ajax(	{ 
						url: $('#PROJECT_RELATIVE_PATH').val() + 'comment-load/' + $(oHdnPageGadgetId).val() + '/', 
						success: function( data )
									{
										
										$( '#oCommentsList', $(oHdnPageGadgetId).parents('div.CommentsContainer').get(0) ).html( data );
									}
					});
		}
}

$(document).ready( function()
	{
		Comments.Init();
	} );	
	

