	$(document).ready(function() {
						
		// new comment
		$('#add_new_comment').click(function(){
			v = $('#new_comment').val();
			if ( $('#new_comment').val() == '' )
				display_error( 'Please write a comment.' );
			else if ( v.length > 500 )
				display_error( 'Comment length must have MAXIMUM 500 chars.' );
			else{
				$('#comments_loader').show();
				no_history_server_post( { m : 'add_comment', comment : $('#new_comment').val() , id : user_id } , add_comment );
				$('#comments_loader').hide();
			}
			return false;
		});
		
		$('#new_comment').keyup(function(){
			v = $(this).val(); x = v.length; 
			if ( x < 1 ) x = '0';
			$('#no_chars').html(x);
		});
		
		$('#build_recorded_videos').prepend( $('#build_recorded_videos #simple_pagination').clone() );
		$('#build_my_pictures').prepend( $('#build_my_pictures #simple_pagination').clone() );
		$('#build_my_friends').prepend( $('#build_my_friends #simple_pagination').clone() );
		
		if ( typeof(page) != 'undefined' ) build_box_content( page , 'build_comments');
		if ( typeof(r_page) != 'undefined' && r_page > 1 ) build_box_content( r_page , 'build_recorded_videos');
		if ( typeof(p_page) != 'undefined' && p_page > 1 ) build_box_content( p_page , 'build_my_pictures');
		if ( typeof(f_page) != 'undefined' && f_page > 1 ) build_box_content( f_page , 'build_my_friends');
		
	});

	// adds a comment to the comment section of the show, and refreshes the comments
	function add_comment( data )
	{
		if ( data['err'] )
			display_error( data['err'] );
		else {
			build_comments( 1 );
			$('#new_comment').val('');
		}
	}
	
	function build_comments(lpage){ build_box_content( lpage , 'build_comments' ) }
	function build_recorded_videos(lpage){ build_box_content( lpage , 'build_recorded_videos' ) }
	function build_my_pictures(lpage){ build_box_content( lpage , 'build_my_pictures' ) }
	function build_my_friends(lpage){ build_box_content( lpage , 'build_my_friends' ) }
	
	function build_box_content( lpage , type )
	{
		page = lpage;
		$('#' + type).empty().append( loader() );
		
		no_history_server_post( { m : type , page : lpage , user_id : user_id } , function( data ) {
			if ( data['err'] ) {
				display_error( data['err'] );
			}else if ( data['server'] && data['server'][type] ){
				$('#' + type ).empty().append( data['server']['pagination'] );
				$('#' + type ).append( data['server'][type] ).append( data['server']['pagination'] );
			}
			
			if ( typeof do_footer == 'function' )
				do_footer();
		} );
	}
	
	
	
	function delete_comment(id)
	{
		if ( confirm('Are you sure you want to delete this comment ? ') ) {
			no_history_server_post( { m:'delete_comment', id:id },function() {
				build_comments( page );
			});
		}
		return false;
	}
	
	
	