var proxy = '/file-mobile/proxy.php'; 
var commentsOff = false;
var pagesize = 10;
var moderation = 'post';
var profiles = false;
var wid = 1166 // this the video player that you modify in the widget 
var defaultAvatar = 'http://mediafactory.fm/static/1/images/global/male.gif';
var avatar = true;
var exactDate = false;
var anonymous = false;
var login = true;
var pager = true;
var pagerAjax = false;
var pagerLimit = 2;
var pagerShowPrevNext = true;
var pagerShowFirstLast = true;
var pagerShowNumbers = true;
var translate = [['just now','moments ago','about a minute ago','minutes ago','about an hour ago','hours ago','day ago','days ago'],['comments','Newest to oldest','Oldest to newest','Most thumbs up','More comments','No comments yet.','Comments have been disabled.','You must login to vote for a comment.','An error has occurred and your comment was not added. Please try again.','like'],['Guest comment','Name','Email','Comment','Add comment','Thank you for your comment. It will first have to be checked by our moderators before showing up on the site.','Thank you for your comment. ','To see it online, refresh your browser. It may take a few minutes for your media to appear.'],['Webcam','Browse','Cancel','Please wait...','Attach an image or video (optional)'],['/profile/user/','upload DESC'],['first','prev','next','last']];

var ValidatorForm = new FMFormValidate();
ValidatorForm.addValidationErrorListener(function(element, message) {
	handleValidation(element,message); return false;
});

function makeUploadAge(time_value) {

	var values = time_value.split(" "); // split up the incoming date format
	var v2 = values[0].split("-");
	// some browsers won't parse the date if the month is a number
	// so here we swap the number for the short form, plus we can use these later when displaying the date
	switch(v2[1]) {
		case "01": v2[1] = "Jan"; break;
		case "02": v2[1] = "Feb"; break;
		case "03": v2[1] = "Mar"; break;
		case "04": v2[1] = "Apr"; break;
		case "05": v2[1] = "May"; break;
		case "06": v2[1] = "Jun"; break;
		case "07": v2[1] = "Jul"; break;
		case "08": v2[1] = "Aug"; break;
		case "09": v2[1] = "Sep"; break;
		case "10": v2[1] = "Oct"; break;
		case "11": v2[1] = "Nov"; break;
		case "12": v2[1] = "Dec"; break;
	}
	
	switch(v2[1]) {
		case "1": v2[1] = "Jan"; break;
		case "2": v2[1] = "Feb"; break;
		case "3": v2[1] = "Mar"; break;
		case "4": v2[1] = "Apr"; break;
		case "5": v2[1] = "May"; break;
		case "6": v2[1] = "Jun"; break;
		case "7": v2[1] = "Jul"; break;
		case "8": v2[1] = "Aug"; break;
		case "9": v2[1] = "Sep"; break;
	}
	
	time_value = v2[1]+" "+v2[2]+", "+v2[0]+" "+values[1]; // recreate the date
	var parsed_date = Date.parse(time_value); // turn it into a date object
	var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); // find out the time right now
	var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); // get the difference between the two
	// determine what information to show based on the elapsed time
	var r = '';
	if (delta < 2) { r = translate[0][0];} 
	else if(delta < 60) { r = translate[0][1]; } 
	else if(delta < 120) { r = translate[0][2];} 
	else if(delta < (45*60)) { r = (parseInt(delta / 60)).toString() + ' '+translate[0][3]; } 
	else if(delta < (2*90*60)) {  r = translate[0][4]; }  // 2* because sometimes read 1 hours ago
	else if(delta < (24*60*60)) { r = (parseInt(delta / 3600)).toString() + ' ' + translate[0][5]; } 
	else if(delta < (48*60*60)) { r = '1 '+translate[0][6]; } 
	else if(delta < (6*24*60*60)) { r = (parseInt(delta / 86400)).toString() + ' '+translate[0][7]; } 
	else { r = v2[1]+" "+v2[2]+", "+v2[0];} 
	// return the upload age
	if (exactDate == true) {
		var time = values[1].split(':');
		if (time[0] > 12) {
			time[0] = time[0]-12;
			time[2] = "pm";
		} else {
			time[2] = "am";
		}
		var dt = v2[1]+" "+v2[2]+", "+v2[0]+" "+time[0]+":"+time[1]+time[2];
		return dt;
	} else {
		return r;
	}
}


function updateDateTime() {
	$$('#fmCommentsWrapper abbr').each(function(e) {	// grab all the <abbr> tags
		$(e).update(makeUploadAge(e.title)); // update the value with the new time
	});
}


function getDateTime() {	
	var t = new Date();
	
	if (t.getHours() < 10){
		hours = "0" + t.getHours();
	} else {
		hours = t.getHours();
	}
	
	if (t.getMinutes() < 10){
		minutes = "0" + t.getMinutes();
	} else {
		minutes = t.getMinutes();
	}
	
	if (t.getSeconds() < 10){
		seconds = "0" + t.getSeconds();
	} else {
		seconds = t.getSeconds();
	}
		
	if (t.getMonth() < 10){
		month = "0" + (t.getMonth()+1);
	} else {
		month = t.getMonth()+1;
	}
	
	if (t.getDate() < 10){
		date = "0" + t.getDate();
	} else {
		date = t.getDate();
	}
	
	t = t.getFullYear()+"-"+month+"-"+date+" "+hours+":"+minutes+":"+seconds; // format it in the correct way
	return t;
}


// Containers

var loginForm = '<div id="loginformContainer" class="fmFormbox"><form action="/my_cl/?mod=home&amp;action=login" method="post" id="loginform"><ul><li class="label">E-mail address</li><li><input type="text" name="username"  id="fmLoginUsername" class="fmTextInput fmInput required"></li><li class="label">Password</li><li><input type="password" name="password" id="fmLoginPassword" class="fmTextInput fmInput required"></li><li class="label"><br/><input type="submit" value="Login" class="fmButton"> <a class="FmRegister" href="/my_cl/?mod=signup" onclick="_gaq.push([\'b._trackPageview\', \'/virtual_register_fm/\']);">Click here to register</a></li></ul><input type="hidden" id="referer" name="referer" value="'+window.location+'"></form></div>';

var commentForm = new Template('<div id="uploadFormWrapper" class="fmFormbox"><form id="uploadForm" action=""><ul><li class="label"><label for="fmDescription">Comment</label></li><li><textarea class="fmTextarea required" id="fmDescription" name="message" title="Comment"></textarea></li></ul><input type="hidden" name="parent" id="fmParent" value="#{parentId}"><input type="hidden" name="username" id="fmUsername" value="#{username}" /><input type="hidden" name="userid" id="userid" value="#{userid}" /><input type="hidden" name="avatarid" id="avatarid" value="#{avatarid}" /></form><br/><div id="uploadStatus"><ul><li class="label">'+translate[3][4]+'</li></ul><a id="uploadBtn" class="fmButton select_file" href="#" onclick="return false;"><div id="flashSelectFile"></div> '+translate[3][1]+' <span id="selectFileBtn"></span></a><div id="fileList"></div><div class="fmClearfix"></div><div class="fmButtonWrapper fmClearfix"><a class="fmButton" onclick="this.blur(); Uploader.startUpload(); return false;">'+translate[2][4]+'</a> <a class="fmButton" id="fmCancelUpload" onclick="window.location = window.location">'+translate[3][2]+'</a></div></div><div id="postUpload"></div><div class="fmClear"></div><div id="loader" style="display:none">'+translate[3][3]+'</div></div>');
//var commentForm = new Template('<div id="uploadFormWrapper" class="fmFormbox"><form id="uploadForm" action=""><ul><li class="label"><label for="fmDescription">Comment</label></li><li><textarea class="fmTextarea required" id="fmDescription" name="message" title="Comment"></textarea></li></ul><input type="hidden" name="parent" id="fmParent" value="#{parentId}"><input type="hidden" name="username" id="fmUsername" value="#{username}" /><input type="hidden" name="userid" id="userid" value="#{userid}" /><input type="hidden" name="avatarid" id="avatarid" value="#{avatarid}" /></form><br/><div id="uploadStatus"><ul><li class="label">'+translate[3][4]+'</li></ul><a id="uploadBtn" class="fmButton select_file" href="#" onclick="return false;"><div id="flashSelectFile" style="display:block; position: absolute;"></div> '+translate[3][1]+' <span id="selectFileBtn"></span></a><div id="fileList"></div><div class="fmClearfix"></div><div class="fmButtonWrapper fmClearfix"><a class="fmButton" onclick="this.blur(); Uploader.startUpload(); return false;">'+translate[2][4]+'</a> <a class="fmButton" id="fmCancelUpload">'+translate[3][2]+'</a></div></div><div id="postUpload"></div><div class="fmClear"></div><div id="loader" style="display:none">'+translate[3][3]+'</div></div>');

var anonCommentForm = new Template('<div class="fmFormbox" id="anonCommentformContainer"><form id="fmPostAnonComment" onsubmit="if (!ValidatorForm.submit(this)) { return false; } else { postanoncomment(#{parentId}, $(\'comment_author\').value, $(\'fmCommentEmail\').value, $(\'comment_comment\').value, this); return false;};"><ul><li class="label"><label for="comment_author">'+translate[2][1]+'</label></li> <li><input type="text" name="author" id="comment_author" class="fmTextInput fmInput required" title="'+translate[2][1]+'"/></li><li class="label"><label for="fmCommentEmail">'+translate[2][2]+'</label></li> <li><input type="text" name="email" id="fmCommentEmail" class="fmTextInput fmEmail fmInput required" title="'+translate[2][2]+'"/></li><li class="label"><label for="comment_comment">'+translate[2][3]+'</label></li> <li><textarea name="message" id="comment_comment" class="fmTextArea fmTextarea required" title="'+translate[2][3]+'"></textarea></li><li class="label"><br/><input type="submit" value="'+translate[2][4]+'" class="fmButton"/></li></ul></form></div>');

var registerForm = '<div style="display:none" id="fmCommentRegister" class="fmFormbox"><form><h2>Register</h2><ul><li class="label"><label for="username">Username *</label></li><li><input type="text" class="fmTextInput fmUsername fmInput required checkUnique" id="username" name="user" title="Username" /></li><li class="label"><label for="firstname">First name *</label></li><li><input type="text" class="fmTextInput fmInput required" id="firstname" name="firstname" title="First name" /></li><li class="label"><label for="lastname">Last name *</label></li><li><input type="text" class="fmTextInput fmInput required" id="lastname" name="lastname" title="Last name" /></li><li class="label"><label for="email">Email *</label></li><li><input type="text" class="fmTextInput fmEmail fmInput required checkUnique" id="email" name="email" title="Email" /></li><li class="label"><label for="password">Password *</label></li><li><input type="password" class="fmTextInput fmPassword fmInput required" id="password" name="password" title="Password" /></li><li class="label"><label for="confirmpassword">Confirm password *</label></li><li><input type="password" class="fmTextInput fmPasswordConfirm fmInput" id="confirmpassword" /></li><li class="label"><label for="captcha">Captcha</label></li> <li><span id="captcha_captcha"><img alt="captcha" src="http://www.filemobile.com/services/captcha?rand=891932b2f0bff0b1b7800f6f79436e80"/></span> <input type="text" name="captcha" class="fmCaptcha fmCaptcha" id="captcha"/></li><li class="label"><br/><input type="submit" class="fmButtonSm" value="Create"/></li> </ul></form></div>';

var formInfo = '<div class="fmCommentRight" id="fmFormInfo"> <div class="inside"> <h4>Want to quickly add a comment?</h4><a class="fbcbutton" href="#"><img src="http://wiki.developers.facebook.com/images/5/55/Connect_white_medium_long.gif" alt="" facebook="" connect=""/></a> Why use Facebook Connect? <ul> <li>No need to create another account</li> <li>Quickly post comments on all of our stories</li> <li>Allow your Facebook friends to see the comments you make on your wall</li> </ul> </div> </div>';

if (profiles) {

	var commentBlock = new Template('<div class="fmComment fmClearfix"><div class="fmUser fmClearfix"><a href="'+translate[4][0]+'#{profileid}" class="fmAvatar"><img src="#{avatar}" /></a><div class="fmInfo fmClearfix"><a href="'+translate[4][0]+'#{profileid}" class="fmName">#{username}</a><abbr title="#{upload}" class="fmTimestamp">#{uploadage}</abbr></div></div><div class="fmContent">#{comment}</div><div class="fmRating"> <div class="fmValue" id="vote#{mid}">#{votecount}</div><span class="fmLike" onclick="like(#{mid}, #{uinid} )">'+translate[1][9]+'</span> </div></div>');
	
	var commentBlockWithImage = new Template('<div class="fmComment fmClearfix"><div class="fmUser fmClearfix"> <a href="'+translate[4][0]+'#{profileid}" class="fmAvatar"> <img src="#{avatar}" /> </a> <div class="fmInfo fmClearfix"> <a href="'+translate[4][0]+'#{profileid}" class="fmName">#{username}</a> <abbr title="#{upload}" class="fmTimestamp">#{uploadage}</abbr> </div> </div><div class="fmContent"><img src="#{image}/14" />#{comment}</div><div class="fmRating"> <div class="fmValue" id="vote#{mid}">#{votecount}</div><span class="fmLike"  onclick="like(#{mid}, #{uinid} )">'+translate[1][9]+'</span> </div></div>');

	var commentBlockWithVideo = new Template('<div class="fmComment fmClearfix"><div class="fmUser fmClearfix"> <a href="'+translate[4][0]+'#{profileid}" class="fmAvatar"> <img src="#{avatar}" /> </a> <div class="fmInfo fmClearfix"> <a href="'+translate[4][0]+'#{profileid}" class="fmName">#{username}</a> <abbr title="#{upload}" class="fmTimestamp">#{uploadage}</abbr> </div> </div><div class="fmContent"><object style="width: 320px; height: 240px;" id="null" class="null" data="http://www.filemobile.com/static/widgets/videoplayerv2/videoplayer_v2.swf" type="application/x-shockwave-flash" allowscriptaccess="always"><param value="http://www.filemobile.com/static/widgets/videoplayerv2/videoplayer_v2.swf" name="movie"/><param value="true" name="allowFullScreen"/><param value="always" name="allowScriptAccess"/><param value="mid=#{mid}&amp;wid='+wid+'&amp;sessiontoken='+fm.cookies.getCookie('SABRE_ID')+'" name="FlashVars"/></object><br/>#{comment}</div><div class="fmRating"> <div class="fmValue" id="vote#{mid}">#{votecount}</div><span class="fmLike" onclick="like(#{mid}, #{uinid} )">'+translate[1][9]+'</span> </div></div>');

} else {
	
	var reportAsOffensive = '<a href="/file-mobile/report.php?mid=#{mid}&reason=I find this comment offensive: #{mid}" class="fmReport">report as offensive</a>';
	
	var commentBlock = new Template('<div class="fmComment fmClearfix"><div class="fmUser fmClearfix"> <span class="fmAvatar"> <img src="#{avatar}" /> </span> <div class="fmInfo fmClearfix"> <span class="fmName">#{username}</span> <abbr title="#{upload}" class="fmTimestamp">#{uploadage}</abbr> </div> </div><div class="fmContent">#{comment}</div><div class="fmRating"> <div class="fmValue" id="vote#{mid}">#{votecount}</div><span class="fmLike" onclick="like(#{mid}, #{uinid} )">'+translate[1][9]+'</span> </div>'+reportAsOffensive+'</div>');
	
	var commentBlockWithImage = new Template('<div class="fmComment fmClearfix"><div class="fmUser fmClearfix"> <span class="fmAvatar"><img src="#{avatar}" /> </span> <div class="fmInfo fmClearfix"> <span class="fmName">#{username}</span> <abbr title="#{upload}" class="fmTimestamp">#{uploadage}</abbr> </div> </div><div class="fmContent"><img src="#{image}/14" />#{comment}</div><div class="fmRating"> <div class="fmValue" id="vote#{mid}">#{votecount}</div><span class="fmLike"  onclick="like(#{mid}, #{uinid} )">'+translate[1][9]+'</span> </div>'+reportAsOffensive+'</div>');
	
	var commentBlockWithVideo = new Template('<div class="fmComment fmClearfix"><div class="fmUser fmClearfix"> <span class="fmAvatar"><img src="#{avatar}" /> </span> <div class="fmInfo fmClearfix"> <span class="fmName">#{username}</span> <abbr title="#{upload}" class="fmTimestamp">#{uploadage}</abbr> </div> </div><div class="fmContent"><object style="width: 320px; height: 240px;" id="null" class="null" data="http://www.filemobile.com/static/widgets/videoplayerv2/videoplayer_v2.swf" type="application/x-shockwave-flash" allowscriptaccess="always"> <param value="http://www.filemobile.com/static/widgets/videoplayerv2/videoplayer_v2.swf" name="movie"/> <param value="true" name="allowFullScreen"/> <param value="always" name="allowScriptAccess"/> <param value="mid=#{mid}&amp;wid='+wid+'&amp;sessionToken='+fm.cookies.getCookie('SABRE_ID')+'" name="FlashVars"/> </object><br/>#{comment}</div><div class="fmRating"> <div class="fmValue" id="vote#{mid}">#{votecount}</div><span class="fmLike"  onclick="like(#{mid}, #{uinid} )">'+translate[1][9]+'</span></div>'+reportAsOffensive+'</div>');

}

// Global vars
var externalid;
if(!externalid) externalid = location.href.substr(7,location.href.length);

var external_title;
if(!external_title) external_title = location.href.substr(7,location.href.length);

var external_url = location.href;

var channel;
if(!channel) channel = 0;

var env;
if(!env) env = 'live';

var parentId = 0;
var code = '';
var moderationStatus = 1;
if(moderation == 'post') moderationStatus = 3;
var start = 0;
var sort = 'upload DESC';
if (translate[4][1]) sort = translate[4][1];
if (pagesize > 500) pagesize = 500;
var injector = 'FM-MMC-v1';

function initApp(userIn) {
	if (!avatar) { $('fmComments').addClassName('fmNoAvatar'); }
	
	// Get parent media and get its comments
	jsonPRequest('media.getFiles', {"filters":{ 'externalid' : externalid, 'moderationStatus': 'notdenied' }, "noCache":true},
    	function(result) {
    		if(result.totalCount > 0) {
    			parentId = result.data[0].id;
    			if (!avatar) { $('fmComments').addClassName('fmNoAvatar'); } // if avatars are turned off, hide them by adding the 'fmNoAvatar'
    			
    			renderComments(userIn.id, start);
			  	initHeader(userIn, parentId, start);
    		} else {
    			// if there isn't a parent media for this URL, tell the user there is no comments then create the parent media
    			$('fmComments').innerHTML = '<div id="nocomments">'+translate[1][5]+'</div>';
    			var params = {"fileData" : {'title':external_title, 'message':'Parent media for comments on '+external_title, 'externalid':externalid, 'metadata':{'external_title':external_title, 'external_url':external_url}  } }
				//console.log(params);
				jsonPRequest('media.insertTextFile', params,
					function(result4) { initHeader(userIn, result4, start);},
					function(exception)  { console.log('Error: Unable to create a new parent, reload the app');},
					true
				);
    		}
    	},
    	function(exception)  {
    		// oops, something went wrong
    		console.log(exception);
    	},
    	true
  	);
}


function renderComments(uid, sortOpt, sortted) {
	if(!sortOpt){ sort = sort } else { sort = sortOpt };
	if(sortted == true) start = 0;
	// swap the text on the 'more comments' button with a loading image
	if ($('fmMoreCommentsBtn')) {
		$('fmMoreCommentsBtn').innerHTML = '<img src="http://www.filemobile.com/static/mmc/images/loading.gif" alt="'+translate[3][3]+'" />';
	}
	//
	if (pager && fmGetQueryVariable('fmPage') > 0) {
		start = (parseInt(fmGetQueryVariable('fmPage'))-1)*pagesize;
	}
	jsonPRequest('media.getFiles', {"sort":sort, 'limit':pagesize, 'start':start, 
	"filters":{'parentid':parentId, 'context':'comment', 'moderationStatus':moderationStatus }, 
	'fields':['filetype', 'uid', 'user_name', 'votecount', 'author', 'upload', 'message', 'publicUrl', 'status', 'avatar'],
	"noCache":true},
		function(result2) {
			// find out how many total comments there are
			//if (moderation == "post") { x = result.totalCount; } 
			x = result2.totalCount;
			$('fmCommentCount').innerHTML = x+" "+translate[1][0]; // display the comment count
			//
			if (pager && (externalid || external_title) || pager && pagerAjax) {
				fmPager(start,pagesize,x);
			}			
			// up the counter
			start = start + pagesize;
			// there are comments
			if(result2.totalCount > 0) { 
				var data = result2.data;
				// if the page is new or the person has changed the sort options, remove all the old comments from the list
				if (start <= pagesize || (pager && pagerAjax == false)) {
					$('fmComments').innerHTML = "";
				}
				data.each( 
					function (currentComment) { 
						//build a comment from the template
						if(currentComment.status) {
							//need to get the file data to get the author
							if(currentComment.uid == 1) {
								avatar = defaultAvatar;
								var comment = {'username':currentComment.author, 'comment':currentComment.message, 'votecount':currentComment.votecount, 'upload':currentComment.upload, 'uploadage':makeUploadAge(currentComment.upload), 'mid':currentComment.id, 'uinid':uid, 'profileid':currentComment.uid, 'avatar':avatar};
					   			var renderedComment = commentBlock.evaluate(comment); 
							}
							else {
								var avatar = '';
								if(currentComment.avatar != 0) {
									if (env == 'dev') avatar = 'http://fmdev.s3.amazonaws.com/storage/' + currentComment.avatar + '/12';
									else avatar = 'http://rstorage.filemobile.com/storage/' + currentComment.avatar + '/12';
								}
								else avatar = defaultAvatar;
																
								// if the comment is a text only comment, use the text comment template
								// else, use the media comment template
								if (currentComment.filetype == 4) {
									var comment = {'username':currentComment.user_name, 'comment':currentComment.message, 'votecount':currentComment.votecount, 'upload':currentComment.upload, 'uploadage':makeUploadAge(currentComment.upload), 'mid':currentComment.id, 'uinid':uid, 'profileid':currentComment.uid, 'avatar':avatar};
									var renderedComment = commentBlock.evaluate(comment); 
								} else if (currentComment.filetype == 1) {
									var comment = {'username':currentComment.user_name, 'comment':currentComment.message, 'image':currentComment.publicUrl, 'votecount':currentComment.votecount, 'upload':currentComment.upload, 'uploadage':makeUploadAge(currentComment.upload), 'mid':currentComment.id, 'uinid':uid, 'profileid':currentComment.uid, 'avatar':avatar};
									var renderedComment = commentBlockWithImage.evaluate(comment); 
								} else {
									var comment = {'username':currentComment.user_name, 'comment':currentComment.message, 'image':currentComment.publicUrl, 'votecount':currentComment.votecount, 'upload':currentComment.upload, 'uploadage':makeUploadAge(currentComment.upload), 'mid':currentComment.id, 'uinid':uid, 'profileid':currentComment.uid, 'avatar':avatar};
									var renderedComment = commentBlockWithVideo.evaluate(comment); 
								}
							}
							// insert the comment into the list
							$('fmComments').insert(renderedComment);
					   	}
					}
				);
				// hide the more comments button if there aren't any more comments to load
				if (data.length < pagesize || start == result2.totalCount ) {
					$('fmMoreCommentsBtn').hide();
				} else {
					$('fmMoreCommentsBtn').show();
				}
				// replace the text on the more comments button
				if ($('fmMoreCommentsBtn')) {
					$('fmMoreCommentsBtn').innerHTML = translate[1][4];
				}
			} else {
				// display the message that there are no comments yet
				$('fmComments').innerHTML = '<div id="nocomments">'+translate[1][5]+'</div>';
			}
		},
		function(exception2) {	
			// something went wrong, tell us
			console.log(exception2);
		},
		true
	);
}

// 
function tabs(e) {
	// get all <li> elements
	$(e).up(0).childElements().each(function(t,i) {
		if (e==t) {
			// show the tab the user just clicked on
			if ($('fmTab'+i)) {
				$('fmTab'+i).show();
				$(e).addClassName('fmActive');
			}
		} else {
			// hide all the other tabs
			if ($('fmTab'+i)) {
				$('fmTab'+i).hide();
				$(t).removeClassName('fmActive');
			}
		}	
	});	
}

function updateCount() {
	if ($("nocomments")) {
		$("nocomments").remove();	
	}
	// update the count 
	var x  = $('fmCommentCount').innerHTML;
	var matches = x.match(/^(\d+)/);
	$('fmCommentCount').innerHTML = (parseInt(matches[0])+1)+" "+translate[1][0];
}

function initHeader(userIn, parent) {
	if(userIn.id > 1){
		// logged in user
		var commentFormParams = {parentId : parent, username : userIn.user, userid : userIn.id, avatarid:userIn.avatar};
		var renderedCommentForm = commentForm.evaluate(commentFormParams);
		// create tabs
		code += '<ul class="fmTabs fmClearfix"><li onClick="tabs(this);" class="fmActive">'+translate[2][3]+'</li><li class="fmLast" onClick="tabs(this);">'+translate[3][0]+'</li><li style="float:right; border:none; background:none; cursor:auto; padding-right:0px;">Welcome, ' + userIn.user + ' | <a href="/my_cl/?mod=home&action=logout&referer='+encodeURI(window.location)+'">logout</a></li></ul>';
		// create tab containers
		code += '<div id="fmTab0" class="fmTab fmClearfix">'+renderedCommentForm+'</div>';
		code += '<div id="fmTab1" class="fmTab fmClearfix" style="display:none;"><object id="" class="" style="width: 420px; height: 316px;" data="http://filemobile.com/static/widgets/mmc_uploader/mmc_app.swf" type="application/x-shockwave-flash" allowscriptaccess="always"><param value="http://filemobile.com/static/widgets/mmc_uploader/mmc_app.swf" name="movie"/><param value="true" name="allowFullScreen"/><param value="always" name="allowScriptAccess"/><param value="vhost='+vhost+'&parentid='+parent+'&channel='+channel+'&injector='+injector+'&recordingLength=20&sessiontoken='+fm.cookies.getCookie('SABRE_ID')+'&uploadCompleteText='+translate[2][6]+' To see it online, refresh your browser. It may take a few minutes for your video to appear." name="FlashVars"/></object></div>';
	} else {
		if (commentsOff) {
			code += '<div id="fmCommentsDisabled">'+translate[1][6]+'</div>';
		} else {
			//anonymous user
			var anonCommentFormParams = {parentId : parent};
			var renderedAnonCommentForm = anonCommentForm.evaluate(anonCommentFormParams);
			// create tabs
			
			
			if (anonymous == false && login == false) { } else { code += '<ul class="fmTabs fmClearfix">'; }
			
			if (anonymous != false) {
				code +='<li onClick="tabs(this);" class="fmActive">'+translate[2][0]+'</li>';
				last = "fmLast";
				tab = "fmTab1";
				style = ' style="display:none;"'
			} else {
				last = "fmActive";
				tab = "fmTab0"
				style = '';
			}
			
			if (login == true) {
				code +='<li class="'+last+'" onClick="tabs(this);">Login</li>';
			} else if (login != false) {
				code +='<li class="'+last+'">'+login+'</li>';
			}
			
			if (anonymous == false && login == false) { } else { code += '</ul>'; }
			
			// create tab containers
			
			if (anonymous != false) {
				code += '<div id="fmTab0" class="fmTab fmClearfix">';
				if (anonymous != true && anonymous != false) {
					code += anonymous;
				} else {
					code += renderedAnonCommentForm;
				}
				code += '</div>';
			}
			
			if (login == true) {
				code += '<div id="'+tab+'" class="fmTab fmClearfix"'+style+'>'+loginForm+'</div>';
			}
		}
	}
	// create sort options and show the number of total comments
	links = '<div id="fmCommentCount" class="fmLeft"></div>';
	links += '<select class="fmRight" onChange="if(this.value != \'\'){ sort = this.value; renderComments('+userIn.id+', this.value, true); }">';
	// place the default sort option at the top of the list (works better then selected="selected")
	if (translate[4][1] == "upload DESC") {
		links += '<option value="upload DESC">'+translate[1][1]+'</option>';
		links += '<option value="upload ASC">'+translate[1][2]+'</option>';
		links += '<option value="votecount DESC, upload ASC">'+translate[1][3]+'</option>';	
	} else if (translate[4][1] == "upload ASC"){
		links += '<option value="upload ASC">'+translate[1][2]+'</option>';
		links += '<option value="upload DESC">'+translate[1][1]+'</option>';
		links += '<option value="votecount DESC, upload ASC">'+translate[1][3]+'</option>';			
	} else {
		links += '<option value="votecount DESC, upload ASC">'+translate[1][3]+'</option>';	
		links += '<option value="upload DESC">'+translate[1][2]+'</option>';
		links += '<option value="upload ASC">'+translate[1][1]+'</option>';		
	}
	links += '</select>';
	// create button to load more comments
	more = '<a class="fmButton" id="fmMoreCommentsBtn" style="display:none;" href="javascript:renderComments('+userIn.id+')">'+translate[1][4]+'</a>';
	// write all info into their containers
	$('fmCommentsBox').innerHTML = code;
	$('fmCommentsHeader').innerHTML = links;
	$('fmCommentsMore').innerHTML = more;
	// product link and filemobile link
	powered = '<div id="fmPowered"><a href="http://www.filemobile.com/products/multimediacomments">Multimedia Comments</a> are powered by <a href="http://www.filemobile.com">Filemobile</a></div>';
	//$('fmCommentsBox').insert({after: powered}); 
	// update the upload times every 15 seconds
	setInterval(updateDateTime,15000);
	// start the uploader
	Uploader.init($('flashSelectFile'));
}

function like(mid, uid) {
	// if the user isn't logged in display the error message asking them to log in
	if (uid == 1) {
		alert(translate[1][7]);
	} else {	
		if (!$('vote'+mid).next().hasClassName("fmDisabled")) {	
			$('vote'+mid).next().addClassName("fmDisabled");
			$('vote'+mid).innerHTML = parseInt($('vote'+mid).innerHTML)+1;
			jsonPRequest('media.rateFile', {"id":mid,"rating":10,"returnData":true},
	    		function(result) {
	    			// change the number after the action has been successful
	    			// $('vote'+mid).innerHTML = result.votecount;
	    		},
	    		function(exception) { console.log(exception); }
	  		);
  		}
	}
}

function confirmCredentials(username, password) {
 	jsonPRequest('users.confirmCredentials', {"username":username, "password":password, "returnUserInfo":true, "login":true},
    	function(result) { 
    		if(result.id > 1) {  window.location.reload(); }
			else { alert("Wrong login, please try again"); }
		},
		function(exception) { console.log(exception); },
		true
  	);
}

function dologin() {
	var username = $('fmLoginUsername').value;
	var password = $('fmLoginPassword').value;
	confirmCredentials(username, password);
}

function postanoncomment(parentId, author, email, comment, e) {
	author = author.stripScripts().stripTags();
	email = email.stripScripts().stripTags();
	comment = comment.stripScripts().stripTags();
	// disable the text inputs and submit button
	$$('#'+e.id+' input').each(function(f) {
		f.disabled = true;
	});
	// disable the comment text area
	$$('#'+e.id+' textarea').each(function(f) {
		f.disabled = true;
	});
	// add the error overlay
	$(e).up(0).insert({top: '<div id="fmErrorOverlay"></div>'});
	//
	var avatar = defaultAvatar;
	// set the variables for the template
	var commentBody = {username: author, email: email, avatar: avatar, comment:comment, votecount:'0', upload:getDateTime(), uploadage:translate[0][0]};
	// create the template
	var renderedComment = '<div id="fmNewPost">'+commentBlock.evaluate(commentBody)+'</div>';
	// send the comment to the DB
	jsonPRequest('media.insertTextFile', {"fileData":{'parentid':parentId,'context':'comment', 'author':author, 'sender':email, 'message':comment, 'channel':channel, 'injector':injector}},
    	function(result) {
    		updateCount();
			// insert the new comment
			if (sort == "upload DESC") {
				$('fmComments').insert({top: renderedComment});
			} else {
    			$('fmComments').insert({bottom: renderedComment});
    		}
    		$('fmErrorOverlay').addClassName('fmNoBackground');
    		// show the moderation message id needed
    		if (moderation == 'pre') {
    			var out = translate[2][5];
    		} else {
    			var out = translate[2][6];
    		}
    		// display the message
    		$('fmErrorOverlay').innerHTML = '<span class="fmSuccess">'+out+'</span>';
    		//
			$('fmNewPost').scrollTo();
    	},
    	function(exception) {
    		//console.log(exception);
    		// remove the loader image and show the error and ok button
    		$('fmErrorOverlay').addClassName('fmNoBackground');
    		$('fmErrorOverlay').innerHTML = '<span class="fmError">'+translate[1][8]+'</span><a onclick="this.up().remove();" class="fmButton">Ok</a>';
		    // re-enable the text inputs and submit button
			$$('#fmPostAnonComment input').each(function(f) {
				f.disabled = false;
			});
			// re-enable the comment text area
			$$('#fmPostAnonComment textarea').each(function(f) {
				f.disabled = false;
			});
    	},
    	true
  	);
}


function logout() {
	document.cookie = "SABRE_ID" + "=" + ";path=" + ";domain=" + "" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	window.location = window.location;
}



function jsonPRequest(method,args,resultHandler,exceptionHandler,realJSON) {
    // Fix for IE bug where a 0 value passed as a number gets output from Prototype's Ajax.Request as undefined
    for ( var fieldName in args )
        if ( ( typeof ( args [ fieldName ] ) == 'number' ) && ( args [ fieldName ] == 0 ) )
            args [ fieldName ] = args [ fieldName ].toString ();

    args.method = method;
    
    if(realJSON) args = { 'jsonArgs': Object.toJSON ( args ) };


 	var ajax = new Ajax.Request(
        proxy,
        {
            method: 'post',
            parameters: args,
            onComplete: function(transport) {
                data = eval("(" + transport.responseText + ")");
                if (data["status"]) {
                    resultHandler(data["result"]);
                } else {
    				if (exceptionHandler) {
    					exceptionHandler(data);
    				} else {
    					alert('Uncaught exception: ' + data["result"]);
    				}
                }
            }
        });
}

Event.observe(window, 'load', function() {
	jsonPRequest('users.getLoggedInUser', {},
		function(result){ initApp(result); },
		function(result) { alert('Init failed, reload the page'); },
		false
	);
	
	if (!avatar) { $('fmComments').addClassName('fmNoAvatar');}
});


function testError() {
$('uploadForm').up(0).insert({top: '<div id="fmErrorOverlay"></div>'});
// remove the loader image and show the error and ok button
			    		$('fmErrorOverlay').addClassName('fmNoBackground');
			    		$('fmErrorOverlay').innerHTML = '<span class="fmError">'+translate[1][8]+'</span><a onclick="this.up().remove();" class="fmButton">Ok</a>';
						// re-enable the comment text area
						$$('#uploadForm textarea').each(function(f) {
							f.disabled = false;
						});

}

// Flash uploader

var Uploader = { 

	swf : null,
    fileMap : [],

	init : function(element) {

		var swf = new fm.flash.Object({
		  src : 'http://filemobile.com/static/widgets/swfupload.swf',
		  width : $('uploadBtn').getWidth(),
		  height : $('uploadBtn').getHeight(),
		  wmode : 'transparent',
		  id : 'uploaderSwf',
		  flashVars : { 
			 buttonText     : '',
			 callbackObject : 'Uploader',
			 debugEnabled   : 'false',
			 uploadURL      : 'http://filemobile.com/services/upload2',
			 buttonImageURL : '',
			 fileSizeLimit  : '250 MB',
			 fileQueueLimit : 1,
			 fileUploadLimit: 1,
			 httpSuccess    : '',
			 fileTypes		: "*.eps; *.jpg; *.jpeg; *.bmp; *.gif; *.pdf; *.png; *.3g2; *.3gp; *.ac3; *.aac; *.aiff; *.amr; *.asf; *.au; *.avi; *.dirac; *.dv; *.flav; *.flv; *.mkv; *.mov; *.mp4; *.m4a; *.mj2; *.mp2; *.mp3; *.mpeg; *.mpg; *.ogg; *.wav; ",
			 filePostName   : 'fmupload',
			 cancelButtonId : "fmCancelUpload",
			 movieName      : 'file',
			 useQueryString : 'false',
			 requeueOnError : 'false',
			 assumeSuccessTimeout : 0
		  }
		});

		swf.embed(element);
		this.swf = element.firstChild;

	},

	debug : function(str) {
		fm.util.log(str);
	},

	testExternalInterface : function() {
		return true;
	},

	flashReady : function() {
		fm.util.log('flash ready');
	},

	fileDialogStart : function() {  },
	fileDialogComplete : function() {  },
	fileQueueError : function(errorCode,file,message) { 
		alert("Sorry, you can only upload one image");
	},

	fileQueued : function(fileObj) { 
    	$('fileList').innerHTML+='<div id="uploadFile' + (this.fileMap.length) + '" class="queuedUploadItem"><img class="progressBar" src="http://filemobile.com/static/2/images/blank.gif" width="0px"  height="20px" /><div class="filename">' + fileObj.name + '</div><div class="percHolder">(<span class="percCount">0</span>%)</div></div>'; 
    	this.fileMap[this.fileMap.length] = fileObj;
    	//var uploadedFileType = fileObj.name.substr(fileObj.name.lastIndexOf('.')+1);
    	//console.log(uploadedFileType);
	},

    fetchFileElem : function(fileObj) {
    	for(i=0;i<this.fileMap.length;i++) {
    		if (this.fileMap[i].name == fileObj.name) {
    			return $('uploadFile'+i); 
    		}
    	}
    },

	uploadStart : function() { 
		this.swf.ReturnUploadStart(true);
	},

    updateProgressBar : function (elem, percent){
    	if(percent < 1){
    		elem.down('img').writeAttribute("width",0);
    	} else {
    		elem.down('img').writeAttribute("width",((Math.round(percent)) + "%"));
    	}	
    },

    uploadProgress : function(fileObj,bytesLoaded) {
		//fm.util.log(fileObj);
		//fm.util.log(bytesLoaded);
    	elem = this.fetchFileElem(fileObj);
    	var perc = bytesLoaded / fileObj.size * 100;
    	elem.down('span').innerHTML = Math.round(perc,2);
    	//elem.getElementsByTagName('span')[0].innerHTML = Math.round(perc,2);
    	Uploader.updateProgressBar(elem, perc);
    	//progress = elem.getElementsByClassName('progressBar')[0];
    	elem.down('.progressBar',0).setStyle({backgroundImage:'url(http://filemobile.com/static/vidcom/images/progressbar/active.gif)'});
    },

    uploadComplete : function(fileObj) {
    	elem = this.fetchFileElem(fileObj);
    	var uploadedFileType = fileObj.name.substr(fileObj.name.lastIndexOf('.')+1);
    	Uploader.updateProgressBar(elem, 100);
    	elem.down('.progressBar',0).setStyle({backgroundImage:'url(http://filemobile.com/static/vidcom/images/progressbar/complete.gif)'});
		if(this.swf.GetStats().files_queued > 0) {
			this.swf.StartUpload();			
		} else {
			// disable the comment text area
			$$('#uploadForm textarea').each(function(f) {
				f.disabled = true;
			});
			// insert the overlay
			$('uploadForm').up(0).insert({top: '<div id="fmErrorOverlay"></div>'});
				
			// remove the ajax image
			$('fmErrorOverlay').addClassName('fmNoBackground');
			
    		// show the moderation message id needed
    		if (moderation == 'pre') {
    			var out = translate[2][5];
    		} else {
    			function oc(a) {
					var o = {};
					for(var i=0;i<a.length;i++) {
						o[a[i]]='';
					}
					return o;
				}
    			var videoFiletypes = ['3g2','3gp','asf','avi','dirac','dv','flav','flv','mkv','mov','mp4','mj2','mpeg','mpg'];
    			if( uploadedFileType in oc(videoFiletypes) ) { 
       			    var out = translate[2][6]+"To see it online, refresh your browser. It may take a few minutes for your video to appear.";
    			} else {
    				var out = translate[2][6]+translate[2][7];    			
    			}
    		}
    		// display the message
    		$('fmErrorOverlay').innerHTML = '<span class="fmSuccess">'+out+'</span>';
			// make sure the user can see their new comment
			updateCount();
		}
    },

    startUpload : function() {
		
		// form validation	
		var validator = new FMFormValidate();
		validator.addValidationErrorListener( function(element,message) {
			handleValidation(element,message); return false;
		});
		
		// check to make sure the user is uploading a file or has a text comment
		/*
		if (this.fileMap.length < 1 && $('fmDescription').value == ''){
			$('selectFileBtn').innerHTML =  ' is required';
			$('uploadBtn').style.color = "#CC0000";
			return false;	
		} else {
			$('selectFileBtn').innerHTML =  '';
			$('uploadBtn').style.color = "#333333";
		}
		*/
		this.swf.SetPostParams({
			'sessiontoken' : fm.cookies.getCookie('SABRE_ID'), 
			'vhost': vhost,
			'message' : $('fmDescription').value.stripScripts().stripTags().replace(/(\r\n|\r|\n)/g, "<br/>"),
			'parentid' : $('fmParent').value,
			'context' : 'comment',
			'channel' : channel,
			'injector' : injector
		});
			
		if(this.fileMap.length < 1){
			// if the form validation fails dont do anything						
			if (!validator.submit($('uploadForm'))){
				return false;
			// if the form validation passes create and send the comment
			} else if(validator.submit($('uploadForm'))) {
				// toss up the overlay
				$('uploadForm').up(0).insert({top: '<div id="fmErrorOverlay"></div>'});
				// disable the comment text area
				$$('#uploadForm textarea').each(function(f) {
					f.disabled = true;
				});
				var desc = $('fmDescription').value.stripScripts().stripTags().replace(/(\r\n|\r|\n)/g, "<br/>");
				// send the text commment
				jsonPRequest('media.insertTextFile', {"fileData":{'parentid':$('fmParent').value,'context':'comment', 'author':$('fmUsername').value, 'sender':$('userid').value, 'message':desc, 'contenttype':'text/plain', 'channel':channel, 'injector':injector}},
			    	function(result) {
			    		var avatar = '';
						if($('avatarid').value != 0) {
							if (env == 'dev') avatar = 'http://fmdev.s3.amazonaws.com/storage/' + $('avatarid').value + '/12';
							else avatar = 'http://rstorage.filemobile.com/storage/' + $('avatarid').value + '/12';
						}
						else avatar = 'http://mediafactory.fm/static/1/images/global/male.gif';
			    		// create the new comment
			    		var commentBody = {username: $('fmUsername').value, uinid: $('userid').value, avatar:avatar, comment:desc, votecount:'0', upload:getDateTime(), uploadage:translate[0][0], mid:123};
						// insert the new comment
						if (sort == "upload DESC") {
							$('fmComments').insert({top:'<div id="fmNewPost"></div>'});
							$('fmNewPost').innerHTML = commentBlock.evaluate(commentBody);
						} else {
			    			$('fmComments').insert({bottom:'<div id="fmNewPost"></div>'});
							$('fmNewPost').innerHTML = commentBlock.evaluate(commentBody);
			    		}
			    		
			    		$('fmErrorOverlay').addClassName('fmNoBackground');
			    		// show the moderation message id needed
			    		if (moderation == 'pre') {
			    			var out = translate[2][5]+translate[2][7];
			    		} else {
			    			var out = translate[2][6];
			    		}
			    		// display the message
			    		$('fmErrorOverlay').innerHTML = '<span class="fmSuccess">'+out+'</span>';
			    		updateCount();
			    		$('fmNewPost').scrollTo();
			    		
			    	},
			    	function(exception) {
			    		// remove the loader image and show the error and ok button
			    		$('fmErrorOverlay').addClassName('fmNoBackground');
			    		$('fmErrorOverlay').innerHTML = '<span class="fmError">'+translate[1][8]+'</span><a onclick="this.up().remove();" class="fmButton">Ok</a>';
						// re-enable the comment text area
						$$('#uploadForm textarea').each(function(f) {
							f.disabled = false;
						});
			    	},
			    	true
			  	);	
			  	return false;
			}
		}

						
		if(!validator.submit($('uploadForm'))) {
			return false;
		} else if (validator.submit($('uploadForm'))) {
			this.swf.StartUpload();
		}	
    }
}

//

function fmGetQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
} 

function fmPager(start,size,total) {

	// create all the variables
	var j = 0;
	var out = '';
	var pager = '';
	var first = '';
	var prev = '';
	var next = '';
	var last = '';
	var numbers = '';
	var url = document.location.href;
	var active = '';
	var current = 1;
	var limit = pagerLimit;
	var button;
	var span = new Template('<span class="fmButton fmDisabled#{css}">#{text}</span>');
	var numbersObj;
	
	// set the button jQuery.tmpls
		
	if (pagerAjax === true) {
		var button = new Template('<a class="fmButton#{css}" onclick="renderComments(0,false,false,#{page});">#{text}</a>');
	} else {
		var button = new Template('<a class="fmButton#{css}" href="#{url}fmPage=#{page}">#{text}</a>');
	}
	
	// check the document for a query string
	if (url.indexOf("fmPage=") >= 0 || pagerAjax) {
				
		// find out the current page
		if (pagerAjax) {
			current = start/size+1;
		} else {
			current = parseInt(fmGetQueryVariable('fmPage'));
		} 
		
		// remove the fmPage variable from the URL
		url = url.substr(0,url.lastIndexOf('fmPage')-1);
		
		// add to or create the url query string
		if (url.indexOf("?") < 0) {
			url += "?";
		} else {
			url += "&";
		}
				
		// if this isn't the first page, add a previous link
		if (current > 1) {
			prev = {'url':url, page:(current-1), text:translate[5][1], css: ' fmPrev'};
			first = {'url':url, page:1, text:translate[5][0], css: ''};
			prev = button.evaluate(prev);
			first = button.evaluate(first);
		} else {
			prev = {text:translate[5][1], css: ' fmPrev'};
			first = {text:translate[5][0], css: ''};
			prev = span.evaluate(prev);
			first = span.evaluate(first);
		}
		
		
		
		// if this isn't the last page, add a next link
		if (current*size < total) {
			next = {'url':url, page:(current+1), text:translate[5][2], css: ' fmNext'};
			last = {'url':url, page:(Math.ceil(total/size)), text:translate[5][3], css: ''};
			next = button.evaluate(next);
			last = button.evaluate(last);
		} else {
			next = {text:translate[5][2], css: ' fmNext'};
			last = {text:translate[5][3], css: ''};
			next = span.evaluate(next);
			last = span.evaluate(last);
		}

	} else {
	
		// if theres no fmPage, show the first page of results
		var current = 1;
		
		// add to or create the query string
		if (url.indexOf("?") < 0) {
			url += "?";
		} else {
			url += "&";
		}
		
		// create the next button
		first = {text:translate[5][0], css: ''};
		prev = {text:translate[5][1], css: ' fmPrev'};
		next = {'url':url, page:(current+1), text:translate[5][2], css: ' fmNext'};
		last = {'url':url, page:(Math.ceil(total/size)), text:translate[5][3], css: ''};
		
		first = span.evaluate(first);
		prev = span.evaluate(prev);
		next = button.evaluate(next);
		last = button.evaluate(last);
		
	}
	
	// set the number of numbers before and after the current
	if (pagerShowNumbers) {
	
		var firstNum = current - limit;
		var lastNum = current + limit;
		
		for (i=0;i<limit;i++) {
			if (firstNum < 1 && current > 0) {
				firstNum++;
				if (lastNum <= total/size) {
					lastNum++;
				}
			} else {
				break;
			}
		}
		
		for (i=0;i<limit;i++) {
			if (lastNum > total/size) {
				lastNum++;
				if (lastNum - limit >= Math.ceil(total/size)+1) {
					if (firstNum-1 > 0) {
						firstNum--;
					}
				}
			} else {
				break;
			}
		}
		
		j = firstNum;
		
		var end = lastNum*size;
		if (end > total) {
			end = total;
		}
		
		// create the numbers buttons
		for (i=(j-1)*size;i<end;i=i+size) {
			if (j == current) {
			 	numbersObj = {'url':url, page:j, text:j, css: ' fmActive'};
			} else {
				numbersObj = {'url':url, page:j, text:j, css: ''};
			}
			numbers += button.evaluate(numbersObj);
			j++;
		}
		
	}
	
	// build the pager
	//
	var addClass = '';
	if (pagerShowFirstLast === false) {
		addClass += ' fmNoFirstLast';
	}
	if (pagerShowPrevNext === false) {
		addClass += ' fmNoPrevNext';
	}
	if (pagerShowNumbers === false) {
		addClass += ' fmNoNumbers';
	}
	//
	pager += '<div class="fmPager fmClearfix'+addClass+'">';
	if (pagerShowFirstLast === true) {
		pager += first;
	}
	if (pagerShowPrevNext === true) {
		pager += prev;
	}
	if (pagerShowNumbers === true) {
		pager += numbers;
	}
	if (pagerShowPrevNext === true) {
		pager += next;
	}
	if (pagerShowFirstLast === true) {
		pager += last;
	}
	pager += '</div>';
	
	// export the pager
	$('fmCommentsMore').innerHTML = pager;

	
}
