

$(document).ready(function() {
	
	bindAddFriend();
	bindRemoveFriend();
	
	function bindRemoveFriend() {

		
		$('.remove_friend').each(function(i) {
			$(this).click(function(){
				var el = $(this);
				$.blockUI({
					message: '<p style="border:4px solid #379bcc;padding:20px;margin:0;" >Please wait..</p>',
					css: {
						border: '0px'
					},
					overlayCSS:  {  
		        		backgroundColor:'#379bcc',
		        		opacity:'0.6'  
		    		}					
				})
				
				
				uID = $(this).parent().children('.user_id').attr('value');
				NickName = $(this).parent().children('.user_name').attr('value');
				$.ajax({
					url: 'http://www.funhax.com/index.php?m=1&c=user&f=removeFriend&uID='+uID,
					type: 'POST',
					data: 'uID='+uID,
					dataType: 'html',
					success: function(data) {
						$(el).replaceWith(data)
						bindAddFriend();
						$.blockUI({
							message: '<p  style="border:4px solid #379bcc;padding:20px;margin:0;" >'+NickName+' has been removed from your friends</p>',
							css: {
								border: '0px'
							},
							overlayCSS:  {  
		        				backgroundColor:'#379bcc',  
		        				opacity:'0.6'  
		    				}
						});
						$(document).oneTime("1s", function() {
							$.unblockUI();
						});
					}	
				})
			})
		})
		
	}	// end bindSendPM
	
	
	
	
	
	function bindAddFriend() {
		
		$('.add_friend').each(function(i) {
			$(this).click(function(){
				var el = $(this);
				$.blockUI({
					message: '<p style="border:4px solid #379bcc;padding:20px;margin:0;" >Please wait..</p>',
					css: {
						border: '0px'
					},
					overlayCSS:  {  
		        		backgroundColor:'#379bcc',
		        		opacity:'0.6'  
		    		}					
				})
				uID = $(this).parent().children('.user_id').attr('value');
				NickName = $(this).parent().children('.user_name').attr('value');
				$.ajax({
					url: 'http://www.funhax.com/index.php?m=1&c=user&f=addFriend&isAjax=1',
					type: 'POST',
					data: 'formAddFriend=1&NickName='+NickName,
					dataType: 'html',
					success: function(data) {
						$(el).replaceWith(data);
						bindRemoveFriend();
						$.blockUI({
							message: '<p style="border:4px solid #379bcc;padding:20px;margin:0;" >'+NickName+' has been added to your friends</p>',
							css: {
								border: '0px'
							},
							overlayCSS:  {  
		        				backgroundColor:'#379bcc',  
		        				opacity:'0.6'  
		    				}
							
						});
						$(document).oneTime("1s", function() {
							$.unblockUI();
						});
					}	
				})
			})
		})
		
	}	// end bindSendPM
	
})
