/*
 * jQuery comments panel v1.0.0 - http://www.onlinetvcast.com/
 *
 *
 */

// FIXME: глобальный рефакторинг
 
 (function($) {
 	function Module_CommentsPanel(options) {
 		var defaults = {
        	_id: {
        		comment_wrapper: 	'comment_wrapper',
        		comment_content: 	'comment_content'
        	},
        	_class: {
        		loading:			'loading',
        		commentsButton:		'add_comments'
        	}		        	        	
        };
 		this.isOpen = false;
        this.options = $.extend(defaults, options);
 		this.construct();
 	}
 	 	 	
 	Module_CommentsPanel.prototype = {
 		construct: function() {
 			this.comment_wrapper = $('#' + this.options._id.comment_wrapper);
			this.comment_content = $('#' + this.options._id.comment_content);
			this.comment_loading = $('.' + this.options._class.loading, this.comment_wrapper);
			this.commentsButton  = $('.' + this.options._class.commentsButton);
			
			// Устанавливаем условия при которых кнопки должні біть погашены
			this.setConditionsForClose();
 		},
 		
 		showCommentsPanel: function(url, videoContentId) {
 			var self = this;
 			if (self.isOpen) {
 				return;
 			}
			self.comment_wrapper.slideDown();
			// window.location.hash = '#comment_wrapper';
			$.ajax({
				url : url,
				type : "POST",
				dataType : 'html',
				timeout : 30000,
				error : function() {
					ajaxError();
				},
				success : function(html) {
					self.comment_content.html(html);
					self.comment_loading.hide();
					self.comment_content.slideDown();
					self.isOpen = true;
				},				
				// Parametrs
				data : { 'topicID' : videoContentId }
			});
		},
		
		hideCommentsPanel: function() {
			var self = this;
			self.comment_wrapper.slideUp(700, function(){
				self.comment_content.html('');
				self.comment_loading.show();
				self.isOpen = false;
			});
		},
		
		enableCommentsButton: function() {
			var self = this;
			self.commentsButton.removeClass('disabled');
		},
		
		disableCommentsButton: function() {
			var self = this;
			self.commentsButton.addClass('disabled');
		},
		
		setConditionsForClose: function() {
        	/*var self = this;
        	$j('.add_content').bind('click', function() {
        		self.commentsButton.addClass('disabled');
        	});*/
        }
 	}
 	
 	$.Module_CommentsPanel = function(options) {
 		return new Module_CommentsPanel(options);
 	};
 
 })(jQuery);
