(function($) {

	function wall(options) {
		
		this.options = {
		
			page: null,
				
			user_id: null,
			
			photo_id: null,
			
			video_id: null,
				
			comment_object_id: null,
				
			wall_object_id: 'wall'
				
		};
		
		this.initialize(options);
		
	};

	$.wall = function(options) {
		
		return new wall(options);
	    
	};

	wall.prototype = {
		
		initialize: function(options) {
			
			$.extend(this.options, options);
			
			if(this.options.wall_object_id && this.options.user_id && this.options.page) {
				
				this.get_user_comments();
				
			} else if(this.options.wall_object_id && this.options.user_id && this.options.comment_object_id) {
				
				if($('#' + this.options.comment_object_id).attr('value') != '' && $('#' + this.options.comment_object_id).attr('value') != 'Type your comment in here...') {
					
					this.add_user_comment();
					
				} else {
				
					alert('Enter message');
				
				}
				
			} else if(this.options.wall_object_id && this.options.user_id && this.options.comment_id) {
				
				this.delete_user_comment();
				
			} else if(this.options.wall_object_id && this.options.photo_id && this.options.page) {
				
				this.get_photo_comments();
				
			} else if(this.options.wall_object_id && this.options.photo_id && this.options.comment_object_id) {
				
				if($('#' + this.options.comment_object_id).attr('value') != '' && $('#' + this.options.comment_object_id).attr('value') != 'Type your comment in here...') {
					
					this.add_photo_comment();
					
				} else {
				
					alert('Enter message');
				
				}
				
			} else if(this.options.wall_object_id && this.options.photo_id && this.options.comment_id) {
				
				this.delete_photo_comment();
				
			} else if(this.options.wall_object_id && this.options.video_id && this.options.page) {
				
				this.get_video_comments();
				
			} else if(this.options.wall_object_id && this.options.video_id && this.options.comment_object_id) {
				
				if($('#' + this.options.comment_object_id).attr('value') != '' && $('#' + this.options.comment_object_id).attr('value') != 'Type your comment in here...') {
					
					this.add_video_comment();
					
				} else {
				
					alert('Enter message');
				
				}
				
			} else if(this.options.wall_object_id && this.options.video_id && this.options.comment_id) {
				
				this.delete_video_comment();
				
			}

		},
		
		get_user_comments: function() {
			
			var me = this;
			
			$.post(
					
				"libraries/wall/get_user_comments",
					
				{user_id:this.options.user_id,page:this.options.page},
					
				function(report) {
						
					if(!report.error) {
							
						$('#' + me.options.wall_object_id).html(report.message);
							
					}
						
				},
					
				'json'
					
			);
			
		},
		
		add_user_comment: function() {
			
			var me = this;
			
			$.post(
					
				"libraries/wall/add_user_comment",
					
				{user_id:this.options.user_id,comment_content:$('#'+this.options.comment_object_id).attr('value')},
					
				function(report) {
						
					if(!report.error) {
							
						me.options.page = 1;
						
						me.get_user_comments();
						
						$('#' + me.options.comment_object_id).attr('value','Type your comment in here...');
							
					}
						
				},
					
				'json'
					
			);
			
		},
		
		delete_user_comment: function() {
			
			var me = this;
			
			$('#delete_comment_' + this.options.comment_id).html('Wait a second...');
			
			$.post(
					
				"libraries/wall/delete_user_comment",
					
				{user_id:this.options.user_id,comment_id:this.options.comment_id},
					
				function(report) {
						
					if(!report.error) {
							
						me.options.page = 1;
						
						me.get_user_comments();
						
					}
						
				},
					
				'json'
					
			);
			
		},
		
		get_photo_comments: function() {
			
			var me = this;
			
			$.post(
					
				"libraries/wall/get_photo_comments",
					
				{photo_id:this.options.photo_id,page:this.options.page},
					
				function(report) {
						
					if(!report.error) {
							
						$('#' + me.options.wall_object_id).html(report.message);
							
					}
						
				},
					
				'json'
					
			);
			
		},
		
		add_photo_comment: function() {
			
			var me = this;
			
			$.post(
				
				"libraries/wall/add_photo_comment",
					
				{photo_id:this.options.photo_id,comment_content:$('#'+this.options.comment_object_id).attr('value')},
					
				function(report) {
						
					if(!report.error) {
							
						me.options.page = 1;
						
						me.get_photo_comments();
						
						$('#' + me.options.comment_object_id).attr('value','Type your comment in here...');
							
					}
						
				},
					
				'json'
					
			);
			
		},
		
		delete_photo_comment: function() {
			
			var me = this;
			
			$('#delete_comment_' + this.options.comment_id).html('Wait a second...');
			
			$.post(
					
				"libraries/wall/delete_photo_comment",
					
				{photo_id:this.options.photo_id,comment_id:this.options.comment_id},
					
				function(report) {
						
					if(!report.error) {
							
						me.options.page = 1;
						
						me.get_photo_comments();
						
					}
						
				},
					
				'json'
					
			);
			
		},
		
		get_video_comments: function() {
			
			var me = this;
			
			$.post(
					
				"libraries/wall/get_video_comments",
					
				{video_id:this.options.video_id,page:this.options.page},
					
				function(report) {
						
					if(!report.error) {
							
						$('#' + me.options.wall_object_id).html(report.message);
							
					}
						
				},
					
				'json'
					
			);
			
		},
		
		add_video_comment: function() {
			
			var me = this;
			
			$.post(
				
				"libraries/wall/add_video_comment",
					
				{video_id:this.options.video_id,comment_content:$('#'+this.options.comment_object_id).attr('value')},
					
				function(report) {
						
					if(!report.error) {
							
						me.options.page = 1;
						
						me.get_video_comments();
						
						$('#' + me.options.comment_object_id).attr('value','Type your comment in here...');
							
					}
						
				},
					
				'json'
					
			);
			
		},
		
		delete_video_comment: function() {
			
			var me = this;
			
			$('#delete_comment_' + this.options.comment_id).html('Wait a second...');
			
			$.post(
					
				"libraries/wall/delete_video_comment",
					
				{video_id:this.options.video_id,comment_id:this.options.comment_id},
					
				function(report) {
						
					if(!report.error) {
							
						me.options.page = 1;
						
						me.get_video_comments();
						
					}
						
				},
					
				'json'
					
			);
			
		}
		
	};

}(jQuery));
