vanilla.comments={_uuid:"",_limit:20,_name_tmpl:'&#8212; <a href="/profile?id=#{person_id}">#{name}</a>',_anonymous_name:"&#8212; <em>Anonymous</em>",_prev_page_arrow:"&#171; Previous",_next_page_arrow:"Next &#187;",_count_tmpl:"Viewing comments #{start}-#{stop} of #{count}",_form_id:"comment_form",_indicator_class:"comment_indicator",_msgs_id:"comment_msgs",_errors_id:"comment_msgs",_list_id:"comment_list",_pager_header_id:"comment_pager_header",_pager_footer_id:"comment_pager_footer",_count_id:"comment_count",_preview_id:"comment_preview",_preview_title_id:"comment_title_preview",_captcha_id:"comment_captcha",_max_length:500,_comment_tmpl:'<div class="comment clearfix #{even_odd} #{first} #{nested_level_class}"><div class="meta">#{created} #{gravatar_img}</div><div class="content"><div class="title">#{title}</div>#{content} #{name} #{reply_link}</div></div>',_content_msg_tmpl:"#{remain} characters left (#{max} characters allowed)",_content_warn_tmpl:'<span class="warn">#{remain} characters left</span> (#{max} characters allowed)',_content_msg_id:"content_msg",_reset_form:true,_hide_form:false,_use_gravatars:true,_anon_gravatar:null,_gravatar_tmpl:'<img src="#{url}" width="40" height="40"></img>',_nested:false,_reply_link_tmpl:'<a class="reply_link" onclick="vanilla.comments._fill_reply_form(#{comment_id}, \'#{title}\')" href="#comment_form_anchor">[Reply]</a>',_journal_entry_id:"",_comment_filter:function(){},_msgs:{missing_email:"Please fill in your email address.",invalid_email:"That is not a valid email address.",missing_first_name:"Please fill in your First Name.",invalid_first_name:"Your First Name is too long. Please keep it under 255 characters.",invalid_last_name:"Your Last Name is too long. Please keep it under 255 characters.",invalid_title:"Your Title is too long. Please keep it under 255 characters.",missing_content:"Please enter your comments content.",invalid_comment_too_long:"We're sorry but that comment is too long.",invalid_comment_profanity:"We're sorry but we do not allow profanity in our comments.",require_approval:"Your comment has been saved and will appear when it has been approved.",require_login:"We're sorry but you must be logged in to post a comment.",approved:"Your comment has been posted.",comments_closed:"We're sorry but this article is closed for future comments.",comments_disabled:"Comments are no longer being accepted on this article.",comments_limit_reached:"We're sorry but the limit has been reached to number of comments for this article.",invalid_comment_spam:"That comment looks like spam!",spam_potential:"That comment looks like spam. Please type the letters you see below in order to submit your post.",captcha_incorrect:"That solution is incorrect. Please try again or get a new image.",duplicate_comment:"That comment has already been added.",user_ban:"We're sorry. You have been banned from posting comments on this site.",ajax_error:"We're sorry. There was a problem submitting your comment. Please come back and try again later."},_current_page:1,_total:0,_date_format:"%m/%d/%Y<br>%l:%M %p",_date_locale:"en",_allow_formatting:0,_max_nested_level:10,init:function(b){for(var a in b){if(a=="msgs"){for(var c in b.msgs){vanilla.comments._msgs[c]=b.msgs[c]}}else{vanilla.comments["_"+a]=b[a]}}if(vanilla.comments._allow_formatting){vanilla.comments._markdown_converter=new Showdown.converter()}jQuery(document).ready(function(){jQuery("#"+vanilla.comments._form_id).submit(vanilla.comments.post);vanilla.comments.show();var d=vanilla.last_action_data();if(d){jQuery("#"+vanilla.comments._form_id+" input[name=email]").val(d.email);jQuery("#"+vanilla.comments._form_id+" input[name=first_name]").val(d.first_name);jQuery("#"+vanilla.comments._form_id+" input[name=last_name]").val(d.last_name)}jQuery("#"+vanilla.comments._errors_id).ajaxError(function(g,f,e){jQuery(this).html(vanilla.comments._msgs.ajax_error).show();vanilla.comments._hide_indicator()});vanilla.text_counter({field_selector:"#"+vanilla.comments._form_id+" textarea[name=content]",max_length:vanilla.comments._max_length,message_selector:"#"+vanilla.comments._content_msg_id,message_template:vanilla.comments._content_msg_tmpl,warn_template:vanilla.comments._content_warn_tmpl});vanilla.comments._update_content_preview();jQuery("#"+vanilla.comments._form_id+" textarea[name=content]").keyup(function(e){vanilla.comments._update_content_preview()});if(vanilla.comments._allow_formatting){vanilla.comments._update_title_preview();jQuery("#"+vanilla.comments._form_id+" input[name=title]").keyup(function(e){vanilla.comments._update_title_preview()});vanilla.comments._interval_handler=window.setInterval(function(){vanilla.comments._update_content_preview();vanilla.comments._update_title_preview()},1000);jQuery("#submit_new_image").click(function(){jQuery("#"+vanilla.comments._captcha_id+" input[name=captcha_solution]").val("");return true})}})},post:function(a){a.preventDefault();vanilla.comments._show_indicator();jQuery.post("/api/c/"+vanilla.comments._uuid,jQuery("#"+vanilla.comments._form_id).serialize(),function(c){vanilla.comments._hide_indicator();if(c.success){var d=c.require_approval?vanilla.comments._msgs.require_approval:vanilla.comments._msgs.approved;jQuery("#"+vanilla.comments._msgs_id).html(d).show();if(vanilla.comments._reset_form){jQuery("#"+vanilla.comments._form_id+" input[name=title]").val("");jQuery("#"+vanilla.comments._form_id+" textarea[name=content]").each(function(){this.value=""});jQuery("#"+vanilla.comments._preview_id).html("");jQuery("#"+vanilla.comments._preview_title_id).html("")}if(vanilla.comments._hide_form){jQuery("#"+vanilla.comments._form_id).hide()}jQuery("#"+vanilla.comments._captcha_id).hide();vanilla.comments.show(true);if(vanilla.comments._interval_handler&&vanilla.comments._hide_form){window.clearInterval(vanilla.comments._interval_handler)}}else{if(c.error=="spam_potential"){jQuery("#"+vanilla.comments._captcha_id).show();jQuery("#"+vanilla.comments._captcha_id+" img.captcha").each(function(){this.src=c.captcha_url});jQuery("#"+vanilla.comments._captcha_id+" input[name=captcha_solution]").each(function(){this.value=""});jQuery("#"+vanilla.comments._captcha_id+" input[name=new_captcha]").each(function(){this.value=0})}jQuery("#"+vanilla.comments._msgs_id).hide();var b=vanilla.comments._msgs[c.error]||c.error;jQuery("#"+vanilla.comments._errors_id).html(b).show()}},"json")},show:function(c){var b="/api/c/"+vanilla.comments._uuid;var a=new Date().valueOf();jQuery.get(b,{buster:a,count:1,journal_entry_id:vanilla.comments._journal_entry_id},function(d){var e=d.count;vanilla.comments._total=e;if(e>0){vanilla.comments._show_indicator();vanilla.comments._update_pager(c);var f=vanilla.comments._limit*(vanilla.comments._current_page-1);jQuery.get(b,{buster:a,limit:vanilla.comments._limit,offset:f,journal_entry_id:vanilla.comments._journal_entry_id},function(g){vanilla.comments._process_comments(g);vanilla.comments._hide_indicator();if(c){jQuery("html:not(:animated),body:not(:animated)").animate({scrollTop:jQuery("#"+vanilla.comments._msgs_id).offset().top},10)}},"json")}},"json")},next_page:function(){vanilla.comments._current_page=vanilla.comments._current_page+1;vanilla.comments.show()},prev_page:function(){vanilla.comments._current_page=vanilla.comments._current_page-1;vanilla.comments.show()},page:function(a){vanilla.comments._current_page=a;vanilla.comments.show()},_process_comments:function(d){var a=jQuery("#"+vanilla.comments._list_id).html("");for(var c in d){var e=d[c];vanilla.comments._comment_filter(e);var b=vanilla.escape_html(e.username);if(!b){b=vanilla.escape_html(e.name)}if(b&&e.person_id){b=vanilla.template(vanilla.comments._name_tmpl,{name:b,username_url:encodeURIComponent(e.username),person_id:e.person_id})}else{b=vanilla.comments._anonymous_name}e.name=b;e.title=vanilla.escape_html(e.title)||"";if(!vanilla.comments._allow_formatting){e.content=vanilla.escape_html(e.content)}e.created=vanilla.strftime(vanilla.comments._date_format,new Date(e.created*1000),vanilla.comments._date_locale);e.i=vanilla.format_number(parseInt(c)+1+((vanilla.comments._current_page-1)*vanilla.comments._limit));e.even_odd=(parseInt(c)+1)%2==0?"even":"odd";e.first=(c==0)?"first":"";e.gravatar_img="";if(vanilla.comments._use_gravatars){if(e.email_hash){e.gravatar_img=vanilla.template(vanilla.comments._gravatar_tmpl,{url:vanilla.gravatar_url(e.email_hash,{size:40,hash:0})})}else{if(vanilla.comments._anon_gravatar){e.gravatar_img=vanilla.template(vanilla.comments._gravatar_tmpl,{url:vanilla.comments._anon_gravatar})}}}if(vanilla.comments._nested){e.reply_link=vanilla.template(vanilla.comments._reply_link_tmpl,{title:vanilla.escape_js(e.title),comment_id:e.comment_id});if(e.level==0){e.nested_level_class=""}else{if(e.level>vanilla.comments._max_nested_level){e.nested_level_class="nested level_"+vanilla.comments._max_nested_level;e.level=vanilla.comments._max_nested_level}else{e.nested_level_class="nested level_"+e.level}}}else{e.reply_link="";e.nested_level_class="";e.level=0}a.append(vanilla.template(vanilla.comments._comment_tmpl,e))}},_update_pager:function(c){var d=vanilla.comments._limit;var h=vanilla.comments._total;var f=Math.ceil(h/d);var g=c?f:vanilla.comments._current_page;vanilla.comments._current_page=g;var b=d*(g-1)+1;var j=d*g;if(j>h){j=h}jQuery("#"+vanilla.comments._count_id).html(vanilla.template(vanilla.comments._count_tmpl,{count:vanilla.format_number(h),start:vanilla.format_number(b),stop:vanilla.format_number(j)}));var a="";if(f>1){if(g==1){a+=vanilla.comments._prev_page_arrow+"&#160;&#160;"}else{a+='<a href="#" onclick="vanilla.comments.prev_page()">'+vanilla.comments._prev_page_arrow+"</a>&#160;&#160;"}for(var e=1;e<=f;e++){if(e==g){a+=e}else{a+='<a href="#" onclick="vanilla.comments.page('+e+')">'+e+"</a>"}if(f!=e){a+=", "}}if(g==f){a+="&#160;&#160;"+vanilla.comments._next_page_arrow}else{a+='&#160;&#160;<a href="#" onclick="vanilla.comments.next_page()">'+vanilla.comments._next_page_arrow+"</a>"}jQuery("#"+vanilla.comments._pager_header_id).html(a);jQuery("#"+vanilla.comments._pager_footer_id).html(a)}},_update_content_preview:function(){if(vanilla.comments._allow_formatting){jQuery("#"+vanilla.comments._form_id+" textarea[name=content]").each(function(){if(this.value){var a=vanilla.comments._markdown_converter.makeHtml(this.value);jQuery("#"+vanilla.comments._preview_id).html(a)}})}},_update_title_preview:function(){if(vanilla.comments._allow_formatting){jQuery("#"+vanilla.comments._form_id+" input[name=title]").each(function(){if(this.value){jQuery("#"+vanilla.comments._preview_title_id).html(vanilla.escape_html(this.value)).show()}})}},_fill_reply_form:function(a,b){jQuery("#"+vanilla.comments._form_id).each(function(){this.elements.parent_id.value=a;this.elements.title.value="Re: "+b})},_show_indicator:function(){jQuery("#"+vanilla.comments._form_id+" .submit").addClass(vanilla.comments._indicator_class)},_hide_indicator:function(){jQuery("#"+vanilla.comments._form_id+" .submit").removeClass(vanilla.comments._indicator_class)}};