Namespace('Nbcu.Sn.Comment');

Nbcu.Sn.Comment = function() {
	var THIS = this;
	
	// this class should have its own private _params object rather than using parent's
	var _params = {};
	THIS.setParam = function(key, value) {
		_params[key] = value;
	};
	THIS.set = function(o) {
		_params = o;
	}
	THIS.getParam = function(key) {
		return _params[key];
	};
	THIS.get = function() {
		return _params;
	}
	THIS.resetParams = function() {
		_params = {};
	};
	
	THIS.resetParams();
};

Nbcu.Sn.Comment.inherits(Nbcu);

nbcu.util.common.loadClass('Nbcu.Template');
nbcu.util.common.loadClass('Nbcu.Util.Form');
nbcu.util.common.loadClass('Nbcu.Content.Object');

/**
 * Paremeters:
 *
 * - version					// valid values: '', '2', '3'
 * - commentObjName
 *
 * Version 2:
 * - commentObj
 * - commentSelector
 * - commentFormSelector
 * - commentPagerSelector
 *
 * Version 3:
 * - refContent
 * - commentSelector
 * - maxRecordsPerPage
 * - maxPages
 * - recordsOrderBy
 * - eventHandler: null
 */
Nbcu.Sn.Comment.method('init', function(commentObj, commentObjName, commentSelector, commentFormSelector, commentPagerSelector) {
	var THIS = this;
	
	var initVersion2 = function() {
		nbcu.util.common.loadClass('Nbcu.Sn.Comment.v2');
		comment = nbcu.sn.comment.v2;
		var params = THIS.get();
		jqN.each(params, function(i, v) {
			comment.setParam(i, v);
		});
		comment.init(commentObj, commentObjName, commentSelector, commentFormSelector, commentPagerSelector);
		nbcu.sn.comment = comment;
		nbcu.sn.comment.v2 = comment;
	};
	
	var initVersion3 = function() {
		nbcu.util.common.loadClass('Nbcu.Sn.Comment.v3');
		comment = new Nbcu.Sn.Comment.v3();
		comment.init(THIS.get());
		if (typeof THIS.getParam('commentObjName') == 'string') {
			eval(THIS.getParam('commentObjName') + ' = comment');
			eval(THIS.getParam('commentObjName') + '.v3 = comment');
		}
	};
	
	var version = THIS.getParam('version') || '2';
	if (typeof version == 'number') {version = version.toString();}
	
	if (typeof THIS.getParam('commentObjName') != 'string' || THIS.getParam('commentObjName') == '') {THIS.setParam('commentObjName', 'nbcu.sn.comment')}
	
	var comment = null;								
	switch (version) {
		case '2':
			initVersion2();
			break;
		
		case '3':
			initVersion3();
			break;
		
		default:													// default version is 2.0
			initVersion2();
	}
	
	return THIS;
});

/**
 * Get comments from SNAS without having to initialize object.
 */
Nbcu.Sn.Comment.method('getCommentByContent', function(callback, contentSSUniqueKey, contentID, contentURL, contentType, fromRow, toRow, startDate, endDate, orderBy) {
	var params = {};
	params.contentSSUniqueKey = contentSSUniqueKey || '';
	params.contentID = contentID || '';
	params.contentURL = contentURL || '';
	params.contentTypeCode = contentType || '';
	params.fromRow = fromRow || '';
	params.toRow = toRow || '';
	params.startDate = startDate || '';
	params.endDate = endDate || '';
	params.orderBy = orderBy || '';
	//params.fetchChildComments = 'true';
	if (nbcu.config.getParam('facebookConnectEnabled') == 'true') {
		params.commentSourceSystemType = 'facebook';
	}
	
	return nbcu.api.call('getCommentByContent', params, 'sn', 'snas', 'DIRECT', 'GET', callback);
});

Namespace('nbcu.sn.comment');
nbcu.sn.comment = new Nbcu.Sn.Comment();
