/**
 * @class HD.CommentsWidget
 * @description The purpose of CommentsWidget is to provide a mechanism for users to read
 * 				and submit comments for media
 * 				Registered as hd_comments_widget.
 * @constructor
 * @extends HD.Widget
 * @see HD.CommentsWidget.hooks
 * @see HD.CommentsWidget.templates
 * @property {object} 	config
 *                    	The configuration for the widget.
 * @property {object} 	[config.hooks=HD.CommentsWidget.hooks]
 *                 		Customized subset of hooks (merged with the defaults).
 * @property {boolean} 	config.requiresLogin
 *                    	Whether a user must be logged in to submit a comment
 *                    	Default is false.
 * @property {boolean} 	submitAbove 
 * 						Show submission form above comments
 * 						Default is false
 * @property {boolean} 	submitBelow 
 * 						Show submission form below comments
 * 						Default is false
 * @property {boolean} 	confirmation 
 * 						Whether to show confirmation on comment submission
 * 						Default is false
 * @property {boolean} 	showCharCount 
 * 						Whether to show character count display on comment submission
 * 						Default is false
 * @property {boolean}	paginate
 * 						Whether to paginate comments
 * 						Default is false
 * @property {number}	pageSize
 * 						Number if comments to show per page if paginated
 * 						Default is 10
 * @property {number}	firstPageSize
 * 						Number of comments to show on the first page if paginated
 * 						Default is 10
 * @property {object} 	[config.templates=HD.TagCloudWidget.templates]
 *                 		Customized subset of templates (merged with the defaults).			
 * @property {object}  	[config.pagingHooks]
 *                 		Customized subset of hooks for HD.util.Paging.
 * @property {object}  	[config.pagingTemplates]
 *                 		Customized subset of templates for HD.util.Paging.         
 */
HD.CommentsWidget = function(config) {
    this.config = config || {};
	this.config.requiresLogin = this.config.requiresLogin || false;
	this.config.submitAbove = this.config.submitAbove || false;
	this.config.submitBelow = this.config.submitBelow || false;
	this.config.confirmation = this.config.confirmation || false;
	this.config.showCharCount = this.config.showCharCount || false;
	this.config.paginate = this.config.paginate || false; 
	this.config.pageSize = this.config.pageSize || 10;
	this.config.firstPageSize = this.config.firstPageSize || this.config.pageSize;
    
	/** Observer collection */
    this.observers = [];
	this.loadTemplates(arguments.callee);
};

/**
 * The collection of default templates.
 * @fieldOf HD.CommentsWidget
 */
HD.CommentsWidget.templates = {
		
	/**
	 * Label for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	titleLabel          : "Comments",
	
	/**
	 * Post comment label for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	postCommentLabel    : "Post a Comment",
	
	/**
	 * Comment field label for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	commentFieldLabel   : "Comment:",
	
	/**
	 * Submit comment label for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	submitLabel         : "Submit",
	
	/**
	 * Loading text for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	loadingText         : "Loading comments...",
	
	/**
	 * No comments text for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	noCommentsText      : "This item has no comments, be the first to leave your mark.",
	
	/**
	 * Confirmation label for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	confirmationLabel   : "Thank You",
	
	/**
	 * Confirmation text for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	confirmationValue   : "Thank you for your submission. After a quick review, your content will be posted to the website within one or two business days. Content deemed to be off topic, offensive or promoting dangerous riding cannot be posted.",
	
	/**
	 *Submit another comment text for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	submitAnotherText   : "Post another comment",
	
	/**
	 * Conditions short text for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	termsConditionsShortPreText    : "By submitting your comment, you confirm that you are at least 18 years of age (or the age of majority in your state of residence) and agree to the terms and conditions stated in <a onclick=\"javascript:window.open('http://www.harley-davidson.com/wcm/Content/Pages/Utility/user_content_policy.jsp?locale=en_US', '', 'width=598,height=540,scrollbars=yes,resizable=yes,toolbar=no,location=no,menubar=no,directories=no,status=no')\" href=\"javascript:void(0)\">Harley-Davidson's Policy For User-Submitted Content</a>.",
	
	/**
	 * Max character value for the widget
	 * @memberOf HD.CommentsWidget
	 */	
	maxCharValue   : 200,
	
	
	/**
	 * @constant
	 * @return {string} Label for the widget: titleLabel
	 * @memberOf HD.CommentsWidget
	 */
	getTitleLabel : function(){
		return this.titleLabel;
	},
	
	/**
	 * @constant
	 * @return {string} Post comment label for the widget: postCommentLabel
	 * @memberOf HD.CommentsWidget
	 */
	getPostCommentLabel : function(){
		return this.postCommentLabel;
	},
	
	/**
	 * @constant
	 * @return {string} Comment field label for the widget: commentFieldLabel
	 * @memberOf HD.CommentsWidget
	 */
	getCommentFieldLabel : function(){
		return this.commentFieldLabel;
	},
	
	/**
	 * @constant
	 * @return {string} Submit button label for the widget: submitLabel
	 * @memberOf HD.CommentsWidget
	 */
	getSubmitLabel : function(){
		return this.submitLabel;
	},
	
	/**
	 * @constant
	 * @return {string} Loading comments text for the widget: loadingText
	 * @memberOf HD.CommentsWidget
	 */
	getLoadingText : function(){
		return this.loadingText;
	},
	
	/**
	 * @constant
	 * @return {string} No comments text for the widget: noCommentsText
	 * @memberOf HD.CommentsWidget
	 */
	getNoCommentsText : function(){
		return this.noCommentsText;
	},
	
	/**
	 * @constant
	 * @return {string} Confirmation label for the widget: confirmationLabel
	 * @memberOf HD.CommentsWidget
	 */
	getConfirmationLabel : function() {
		return this.confirmationLabel;
	},
	
	/**
	 * @constant
	 * @return {string} Confirmation text for the widget: confirmationValue
	 * @memberOf HD.CommentsWidget
	 */
	getConfirmationValue : function() {
		return this.confirmationValue;
	},
	
	/**
	 * @constant
	 * @return {string} Submit another comment text for the widget: submitAnotherText
	 * @memberOf HD.CommentsWidget
	 */
	getSubmitAnotherText : function() {
		return this.submitAnotherText;
	},
	
	/**
	 * @constant
	 * @return {string} Short terms and conditions text for the widget: termsConditionsShortPreText
	 * @memberOf HD.CommentsWidget
	 */
	getTermsConditionsShortPreText : function() {
		return this.termsConditionsShortPreText;
	},
	
	/**
	 * @constant
	 * @return {string} Error template for the widget
	 * @memberOf HD.CommentsWidget
	 */
	getErrorsHtml : function() {
		return this.errorsHtml;
	},
	
	/**
	 * @constant
	 * @return {string} Value for the widget: maxCharValue
	 * @memberOf HD.CommentsWidget
	 */
	getMaxCharValue : function(){
		return this.maxCharValue;
	},
	
	/**
	 * @constant
	 * @return {string} Main template for the widget
	 * @memberOf HD.CommentsWidget
	 */
	getHtml : function() {
		return this.html;
	},
	
	/** 
	 * Error template for the widget
	 * @memberOf HD.CommentsWidget
	 * @type jst_template
	 */	
	errorsHtml : '\
		{if errors}\
			{for error in errors}\
				<div class="${classes.ERROR}">${error.errorMessage}</div>\
			{/for}\
		{/if}',
	
	/** 
	 * Main template for the widget
	 * @memberOf HD.CommentsWidget
	 * @type jst_template
	 */			
	html :  '\
		{if comments}\
			{macro commentsForm()}\
				<li><form class="${hooks.FORM}">\
					<div class="${classes.TITLE}">${templates.getPostCommentLabel()}</div>\
					<div class="${classes.WRAPPER} ${hooks.ERROR}"></div>\
					<div class="${classes.LABEL}">${templates.getCommentFieldLabel()}</div>\
					<textarea cols="30" rows="5" class="${classes.VALUE} ${hooks.TEXTAREA}"></textarea><br/>\
					{if config.showCharCount}\
						<div id="hdCharCount"><input type="text" class="${hooks.CHARCOUNT}" value="${templates.getMaxCharValue()}" /></div>\
					{/if}\
					<div class="${classes.AGREEMENT}">\
						<div class="${classes.LABEL} ${hooks.LEGAL_SM}">\
							${templates.getTermsConditionsShortPreText()}\
						</div>\
					</div>\
					<input type="Submit" value="${templates.getSubmitLabel()}" class="${hooks.SUBMIT}" />\
				</form></li>\
				<li class="${classes.HIDDEN}">\
					<div class="${classes.CONFIRMATION} ${hooks.CONFIRMATION}">\
						<div class="${classes.LABEL}">${templates.getConfirmationLabel()}</div>\
						<div class="${classes.VALUE}">${templates.getConfirmationValue()}</div>\
						<div class="hdSubmitComment hdSubmitAnotherComment ${hooks.SUBMIT_ANOTHER_COMMENT}">${templates.getSubmitAnotherText()}</div>\
					</div>\
				</li>\
			{/macro}\
			{macro commentDisplay()}\
				<li class="${classes.COMMENT}">\
					<div>\
						<span class="${classes.DATE}">${comment.createdDate|date}</span> \
						<span class="${classes.AUTHOR}">${comment.submittedBy}</span>\
					</div>\
					<div class="${classes.VALUE}">${comment.text}</div>\
				</li>\
			{/macro}\
			<div class="${classes.COMMENTS} ${classes.WIDGET}">\
				<ul>\
				{if config.submitAbove}\
					${commentsForm()}\
				{/if}\
				{if comments.length > 0}\
					{if config.paginate}\
						{for comment in comments}\
							{if comment_index < (config.pageSize*pageNumber) && comment_index >= (config.pageSize*(pageNumber-1))}\
								${commentDisplay()}\
							{/if}\
						{/for}\
						<li><span class="${hooks.PAGING}"></span></li>\
					{else}\
						<li class="${classes.TITLE}">${templates.getTitleLabel()}</li>\
						{for comment in comments}\
							${commentDisplay()}\
						{/for}\
					{/if}\
				{else}\
					<li class="${classes.EMPTY}">${templates.getNoCommentsText()}</li>\
				{/if}\
				</ul>\
			</div>\
			{if config.submitBelow}\
				${commentsForm()}\
			{/if}\
		{else}\
			${templates.getLoadingText()}\
		{/if}'
};

(function() {
	var classes = HD.CSS_CLASSES;
	
	/**
	 * The collection of hooks
	 */
	HD.CommentsWidget.hooks = {
		
		/**
		 * Standalone: (1)<br />
		 * Use: Submit comment form<br />
		 * Type: Form<br />
		 * @memberOf HD.CommentsWidget
		 */
		FORM : classes.COMMENTS + '-form',
		
		/**
		 * Dependencies: 1: FORM <br/>
		 * Use: Comment field<br />
		 * Type: Textarea
		 * @memberOf HD.CommentsWidget
		 */
		TEXTAREA : classes.COMMENTS + '-textarea',
		
		
		/**
		 * Standalone: (1)<br />
		 * Use: Short legal description container<br />
		 * @memberOf HD.CommentsWidget
		 */
		LEGAL_SM : classes.COMMENTS + '-legal-sm',
		
		/**
		 * Standalone: (1)<br />
		 * Use: Full legal description container<br />
		 * @memberOf HD.CommentsWidget
		 */
		LEGAL_FULL : classes.COMMENTS + '-legal-full',
		
		/**
		 * Standalone: (1)<br />
		 * Use: Shows/Hides the legal description<br />
		 * @memberOf HD.CommentsWidget
		 */
		TERMS_BUTTON : classes.COMMENTS + '-terms-btn',
		
		/**
		 * Dependencies: 1: FORM <br/>
		 * Use: Refreshes the submission form after successful submission<br />
		 * @memberOf HD.CommentsWidget
		 */
		SUBMIT_ANOTHER_COMMENT : classes.COMMENTS + '-submit-comment',
		
		/**
		* Dependencies: 1: FORM <br/>
		 * Use: Loader on comment submission<br />
		 * @memberOf HD.CommentsWidget
		 */
		COMMENT_SUBMITTED : classes.COMMENTS + '-' + classes.LOADING,
		
		/**
		 * Dependencies: 1: FORM <br/>
		 * Use: Error container<br />
		 * @memberOf HD.CommentsWidget
		 */
		ERROR : classes.COMMENTS + '-error',
		
		/**
		 * Dependencies: 1: FORM <br/>
		 * Use: Confirmation container<br />
		 * @memberOf HD.CommentsWidget
		 */
		CONFIRMATION : classes.COMMENTS + '-confirmation',
		
		/**
		 * Dependencies: 1: FORM <br/>
		 * Use: Character count<br />
		 * @memberOf HD.CommentsWidget
		 */
		CHARCOUNT : classes.COMMENTS + '-charcount',
		
		/**
		 * Dependencies: 1: FORM <br/>
		 * Use: Form submission<br />
		 * @memberOf HD.CommentsWidget
		 */
		SUBMIT : classes.COMMENTS + '-submit',
		
		/**
		 * Standalone: 0..n <br/>
		 * Use: Selecting the nodes that will contain pagers <br/>
		 * @memberOf HD.CommentsWidget
		 */
		PAGING : classes.PAGING

		
	};
})();

HD.CommentsWidget.prototype = {
    
	/**
	 * Sets event listeners for the widget.
	 * @param {object} [data]
	 *                 Event data from the render phase
	 */
    setListeners : function(data) {
    	if(data == null) {
    		return;
    	}

    	var classes = HD.CSS_CLASSES;
    	var parentEl = this.getParent();
    	
    	// Get the submission elements
    	var formEl = HD.getByClass(this.config.hooks.FORM, '*', parentEl)[0];
    	var commentEl = HD.getByClass(this.config.hooks.TEXTAREA, '*', parentEl)[0];
    	var charCountEl = HD.getByClass(this.config.hooks.CHARCOUNT, '*', parentEl)[0];
    	
    	// Initialize the form and set submit event
    	if(formEl && commentEl) {
    		HD.removeClass(formEl, classes.ERROR);
	    	var modelCb = this.model;
    		var mediaCb = data;
			var cb = this;
			
			// Set up the character counter
			if (this.config.showCharCount && charCountEl){
				commentEl.onkeyup = function(){
					var charCount = commentEl.value.length;
					var maxChars = cb.config.templates.getMaxCharValue();
					charCountEl.value = maxChars - charCount;
					
					cb.getByHook("SUBMIT", function(el) {
						if (charCount > maxChars){
							el.disabled = true;
							HD.addClass(el, classes.DISABLED);
						}
						else{
							el.disabled = false;		
							HD.removeClass(el, classes.DISABLED);
						}
					}, '*', parentEl);
					
				};
			}
			

    		formEl.onsubmit = function() {
    			// Get the submission
    			var filteredCommentValue = HD.util.Common.stripHtmlTags(commentEl.value);
				var submitComment = function() {
	    			modelCb.submitComment.call(modelCb, mediaCb.mediaId, mediaCb.contentType, filteredCommentValue);
				};
				// Force a login check if required.
				if (cb.config.requiresLogin) {					
					login.model.isUserLoggedIn(function(userResponse) {
						if(userResponse.loggedInLevel > 1) {
							submitComment();
						} else {
							var observer = {
								update : function(eventName, eventData) {
									if (eventName == "logged_In") {
										submitComment();
										login.model.removeObserver(this);
										HD.util.Common.getObservable().removeObserver(this);
									} else if (eventName == "overlayClose_Click") {
										login.model.removeObserver(this);
										HD.util.Common.getObservable().removeObserver(this);
									}
								}
							};
					
							HD.util.Common.getObservable().addObserver(observer);
							login.model.addObserver(observer);
					
							if(userResponse.loggedInLevel > 0){
								login.view.promptCreateScreenName();
							}else{
								login.view.promptAuthentication();
							}
						}
					});
				}
				// Otherwise submit the comment like normal.
				else {
					submitComment();
				}
    			return false;
    		};
    		
    		// Toggle the terms and conditions
    		var partialLegalEl = HD.getByClass(this.config.hooks.LEGAL_SM, '*', parentEl)[0];
    		var fullLegalEl = HD.getByClass(this.config.hooks.LEGAL_FULL, '*', parentEl)[0];
    		
    		var legalTriggerEl = HD.getByClass(this.config.hooks.TERMS_BUTTON, '*', parentEl)[0];
    		
    		if(legalTriggerEl && fullLegalEl){
	    		legalTriggerEl.onclick = function() {
	    			if(HD.hasClass(fullLegalEl, classes.HIDDEN)) {
	    				HD.removeClass(fullLegalEl, classes.HIDDEN)
	    			} else {
	    				HD.addClass(fullLegalEl, classes.HIDDEN)
	    			}
	    		};
    		}
    	}
    	
		// initialize paging
		var pagingEls = HD.getByClass(this.config.hooks.PAGING, "*", parentEl);
		if (pagingEls.length > 0) {
			var paging = new HD.util.Paging({
				startingPage : 1,	// starting page index
				containers : pagingEls,	// element(s) to hold paging controls 
				defaultPageSize : this.config.pageSize,
				templates : this.config.pagingTemplates || {},
				hooks     : this.config.pagingHooks || {}
			});
			var self = this;
			
			var pagingObserver = {

				update : function(eventName, eventData) {

					if(eventName == "paging_Next") {
						self.preparePaging(self.commentData, self.commentData.pageNumber+1, true);
					} else if(eventName == "paging_Previous") {
						self.preparePaging(self.commentData, self.commentData.pageNumber-1, true);
					} else if(eventName == "paging_Page") {
						self.preparePaging(self.commentData, eventData, true);
					}
				}
			};
			paging.view.addObserver(pagingObserver);
			
			/** 
			 * Paging for the gallery.
			 * @type HD.util.Paging
			 */
			this.paging = paging;
		}
    	
    	
    	// Set the click even to submit another comment
    	var cb = this;
    	var confirmationEl = HD.getByClass(this.config.hooks.SUBMIT_ANOTHER_COMMENT, '*', parentEl)[0];
    	if(confirmationEl != null) {
	    	confirmationEl.onclick = function() {
	    		cb.hideConfirmation.call(cb);
	    	};
    	}
    	
    	//var authorEls = HD.getByClass(classes.AUTHOR, "span", parentEl);
		//var comments = data.comments;
		//for(var i = 0, len = authorEls.length; i < len; i++) {
		//	this.setAuthorListener(authorEls[i], comments[i]);
		//}
    },
    
    /**
	 * Sets author listeners for the widget to show profile.
	 * @param {HTMLElement} element
	 *                 		Element to be clicked
	 * @param {string}		authorId
	 * 						Author ID of the profile to be shown
	 */
    setAuthorListener : function(element, authorId) {
    	if(element == null || authorId == null) {
    		return;
    	}
    	
    	var cb = this;
    	element.onclick = function() {
    		cb.notifyObservers.call(cb, "authorSelected", authorId);
    		cb.model.getMemberProfile.call(cb.model, authorId);
    	};
    },
    
    /**
	 * Sets the paging functionality.
	 * @param {HTMLElement} eventData
	 *                 		Event data from the render phasevv
	 * @param {number}		thisPage
	 * 						Page of comments to create
	 * @param {boolean}		doRender
	 * 						Whether to re-render the comments widget
	 */
    preparePaging : function(eventData, thisPage, doRender){
    	eventData.pageNumber = thisPage;
		eventData.totalPages = Math.ceil(eventData.numberOfComments/this.config.pageSize);
		eventData.totalMedia = eventData.numberOfComments;
		eventData.pageSize = this.config.pageSize;
		this.commentData = HD.clone(eventData || {}, false);
		if (doRender){
			this.render(eventData);
		}
		this.paging.controller.updatePagingData(eventData);
		
    },
    
    /**
	 * Monitors events by HD.CommentsWidget.
	 * @param {string} eventName
	 *                 The name of the event
	 * @param {object} [eventData]
	 *                 Data for the event
	 */
    update : function(eventName, eventData) {
    	
    	var classes = HD.CSS_CLASSES;
    	var parentEl = this.getParent();
		var inputEl = HD.getByClass(this.config.hooks.TEXTAREA, '*', parentEl)[0];
    	
    	if(eventName == "getComments_Start") {
    		this.loading(true);
    		this.render(eventData);
    	} else if(eventName == "getComments_Finish") {
    		this.loading(false);
    		this.render(eventData);
    		if (this.config.paginate){
    			this.preparePaging(eventData, 1, false);
    		}
    	} 
    	else if(eventName == "submitComment_Start") {
    		
    		if(inputEl){
        		HD.addClass(inputEl, this.config.hooks.COMMENT_SUBMITTED);
        	}
    	}
    	else if(eventName == "submitComment_Finish") {
    		this.loading(false);
    		if(inputEl){
        		HD.removeClass(inputEl, this.config.hooks.COMMENT_SUBMITTED);
        	} 
    		
    		// Reset the counter
    		var charCountEl = HD.getByClass(this.config.hooks.CHARCOUNT, '*', parentEl)[0];
    		if (this.config.showCharCount && charCountEl){
    			charCountEl.value = this.config.templates.getMaxCharValue();
    		}
    		
    		
    		if(this.config.confirmation) { 
    			this.showConfirmation(eventData);
    		} else {
    			this.render(eventData);
    			if (this.config.paginate){
        			this.preparePaging(eventData, 1, false);
        		}
    		}
    	} else if(eventName == "submitComment_Error") {
    		this.loading(false);
    		if(inputEl){
        		HD.removeClass(inputEl, this.config.hooks.COMMENT_SUBMITTED);
        	}    		
    		this.renderError(eventData);
    	}
    },
    
    /**
	 * Shows the confirmation after successful submission
	 */
    showConfirmation : function() {
    	var classes = HD.CSS_CLASSES;
    	var parentEl = this.getParent();
    	
    	var formEl = HD.getByClass(this.config.hooks.FORM, '*', parentEl)[0];
    	var textareaEl = HD.getByClass(this.config.hooks.TEXTAREA, '*', parentEl)[0];
    	var errorWrapperEl = HD.getByClass(this.config.hooks.ERROR, '*', parentEl)[0];
    	var confirmationEl = HD.getByClass(this.config.hooks.CONFIRMATION, '*', parentEl)[0];
    	
    	if(textareaEl){
    		textareaEl.value = "";
    	}
    	
    	if(formEl){
    		HD.addClass(formEl.parentNode, classes.HIDDEN);
    		HD.removeClass(formEl, classes.ERROR);
    	}
   		
    	if (errorWrapperEl){
    		errorWrapperEl.innerHTML = '';
    	}
    	
    	if (confirmationEl){
    		HD.removeClass(confirmationEl.parentNode, classes.HIDDEN);
    	}
    },
    
    /**
	 * Hides the confirmation
	 */
    hideConfirmation : function() {
    	var classes = HD.CSS_CLASSES;
    	var parentEl = this.getParent();
    	var formEl = HD.getByClass(this.config.hooks.FORM, '*', parentEl)[0];
    	var confirmationEl = HD.getByClass(this.config.hooks.CONFIRMATION, '*', parentEl)[0];
    	
    	if (confirmationEl){
    		HD.addClass(confirmationEl.parentNode, classes.HIDDEN);
    	}
    	
    	if(formEl){  	
    		HD.removeClass(formEl.parentNode, classes.HIDDEN);
    	}
    },
    
    /**
	 * Shows errors upon comment submission
	 * @param {object} errors
	 *                 The errors returned
	 */
    renderError : function(errors) {

    	var classes = HD.CSS_CLASSES;
    	var parentEl = this.getParent();
    	
    	var formEl = HD.getByClass(this.config.hooks.FORM, '*', parentEl)[0];
    	var errorWrapperEl = HD.getByClass(this.config.hooks.ERROR, '*', parentEl)[0];
    	
    	if (formEl){
    		HD.addClass(formEl, classes.ERROR);
    	}
   		
    	if (errorWrapperEl){
    		errorWrapperEl.innerHTML = this.getErrorsHtml(errors);
    	}
    },
    
    /**
	 * Renders the Error HTML for the widget based on dynamic data.
	 * @param {object} [errors]
	 *                 Event data from the render phase
	 * @returns {string} Error HTML for the widget
	 */
    getErrorsHtml : function(errors) {
		return this.processTemplate(this.config.templates.getErrorsHtml(), {
			errors : errors
		});
    },
    
    /**
	 * Renders the HTML for the widget based on dynamic data.
	 * @param {object} [data]
	 *                 Event data from the render phase
	 * @returns {string} HTML for the widget
	 */
    getHtml : function(data) {
		var self = this;
		return this.processTemplate(this.config.templates.getHtml(), {
			comments : (data && data.comments) || null,
			pageNumber : (data && data.pageNumber) || 1
		});
    }
};

HD.extend(HD.CommentsWidget, [HD.Widget]);

HD.register('hd_comments_widget', 'HD.CommentsWidget', {version: "1.0", build: "1"});