function need_to_show_more(){if(comments_page<max_comments_page){upper=comments_count-((comments_page*comments_per_page))-10;lower=comments_count-((comments_page+1)*comments_per_page)-9;if(lower<1){lower=1;}
if(sort_order==='oldest'){upper=((comments_page+1)*comments_per_page)+10;lower=(comments_page*comments_per_page)+11;if(upper>comments_count){upper=comments_count;}}
$('#show_more_comments').html('Show '+lower+'-'+upper+' of '+comments_count+' comments');$('#show_more_comments').show();}else{$('#show_more_comments').hide();}}
function show_hide_comments(upper,lower,order){var comments=$('#paged_comments');var random_n=Math.floor(Math.random()*1000000000);jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':order,'tstamp':random_n},function(data){comments.append(data);apply_text_size();});need_to_show_more();apply_text_size();}
function comments_next(button){var upper=comments_count-((comments_page*comments_per_page))-10;var lower=comments_count-((comments_page+1)*comments_per_page)-9;if(lower<1){lower=1;}
if(sort_order==='oldest'){upper=((comments_page+1)*comments_per_page)+10;lower=(comments_page*comments_per_page)+11;if(upper>comments_count){upper=comments_count;}}
comments_page=comments_page+1;show_hide_comments(upper,lower,sort_order);}
function expand_all(button){var upper=comments_count;var lower=1;var comments=$('#paged_comments');var random_n=Math.floor(Math.random()*1000000000);jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':sort_order,'tstamp':random_n},function(data){comments.html(data);apply_text_size();});comments_page=max_comments_page;need_to_show_more();$('#subscribe_order').html('<a href="#comments" onclick="collapse_all();return false;">Collapse All</a>');apply_text_size();}
function collapse_all(button){var upper=comments_count;var lower=comments_count-9;comments_page=0;if(lower<1){lower=1;}
if(sort_order==='oldest'){upper=10;lower=1;}
var comments=$('#paged_comments');var random_n=Math.floor(Math.random()*1000000000);jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':sort_order,'tstamp':random_n},function(data){comments.html(data);apply_text_size();});need_to_show_more();$('#subscribe_order').html('<a href="#comments" onclick="expand_all()">Expand All</a>');apply_text_size();}
function sort_oldest(button){var lower=1;var upper=10;sort_order='oldest';comments_page=0;var random_n=Math.floor(Math.random()*1000000000);jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':'oldest','tstamp':random_n},function(data){$('#paged_comments').html(data);});need_to_show_more();$('#newest_option').show();$('#oldest_option').hide();$('#subscribe_order').html('<a href="#comments" onclick="expand_all();return false;">Expand All</a>');}
function sort_newest(button){sort_order='newest';var upper=comments_count;var lower=comments_count-9;comments_page=0;if(lower<1){lower=1;}
var comments=$('#paged_comments');var random_n=Math.floor(Math.random()*1000000000);jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'tstamp':random_n},function(data){comments.html(data);apply_text_size();});need_to_show_more();$('#newest_option').hide();$('#oldest_option').show();$('#subscribe_order').html('<a href="#comments" onclick="expand_all();return false;">Expand All</a>');apply_text_size();}
