
god.resultArgs={order:'active',start:0,limit:39,cat:0,searched:'',time:0,mine:0,rand:0};$(function(){if(window.location.hash){var hash=window.location.hash.substring(1);resultPreviewPost(parseInt(hash));}
if(god.url.order){god.resultArgs.order=god.url.order}
if(god.url.start){god.resultArgs.start=parseInt(god.url.start)}
if(god.url.limit){god.resultArgs.limit=parseInt(god.url.limit)}
if(god.url.searched){god.resultArgs.searched=god.url.searched}
if(god.url.time){god.resultArgs.time=parseInt(god.url.time)}
if(god.url.cat){god.resultArgs.cat=parseInt(god.url.cat)}
if(god.url.rand){god.resultArgs.rand=parseInt(god.url.rand)}
if(god.url.mine){if(!$.cookie('mine')){alert('Participate in some posts, then try again')}
god.resultArgs.rand=0;if(god.resultArgs.mine===0){god.resultArgs.mine=39;getResults(god.resultArgs);}}
getResults(god.resultArgs);makeIconBox($('#catsR .iconBox'),$('#sbBite'),'sidebar');$('#activeR').bind('click',function(){god.resultArgs.mine=0;god.resultArgs.rand=0;if(god.resultArgs.order!='active'){god.resultArgs.order='active';getResults(god.resultArgs);}});$('#recentR').bind('click',function(){god.resultArgs.mine=0;god.resultArgs.rand=0;if(god.resultArgs.order!='recent'){god.resultArgs.order='recent';getResults(god.resultArgs);}});$('#mostCommentsR').bind('click',function(){god.resultArgs.mine=0;god.resultArgs.rand=0;if(god.resultArgs.order!='mostComments'){god.resultArgs.order='mostComments';getResults(god.resultArgs);}});$('#leastCommentsR').bind('click',function(){god.resultArgs.mine=0;god.resultArgs.rand=0;if(god.resultArgs.order!='leastComments'){god.resultArgs.order='leastComments';getResults(god.resultArgs);}});$('#mineR').bind('click',function(){if(!$.cookie('mine')){alert('Participate in some posts, then try again')}
god.resultArgs.rand=0;if(god.resultArgs.mine===0){god.resultArgs.mine=39;getResults(god.resultArgs);}});$('#randomR').bind('click',function(){god.resultArgs.mine=0;god.resultArgs.rand=39;getResults(god.resultArgs);});$('#searchBar').keyup(function(e){if(e.keyCode==13){god.resultArgs.mine=0;god.resultArgs.rand=0;god.resultArgs.searched=$(this).val();getResults(god.resultArgs);}});$('#robLimit > span').html(god.resultArgs.limit);$('#robPages').click(function(){var pagePop=$('#robPopPage')
if(pagePop.is(':visible')){pagePop.slideUp(339);}else{pagePop.show();}});clickMover($('#robLimit'),$('#robPopLimit'));clickMover($('#robTime'),$('#robPopTime'));$('#robPopLimit div').click(function(){god.resultArgs.limit=this.getAttribute('limit');god.resultArgs.start=0;$('#robLimit > span').html(god.resultArgs.limit);getResults(god.resultArgs);});$('#robPopTime div').click(function(){god.resultArgs.time=this.getAttribute('time');$('#robTime > span').html($(this).text());getResults(god.resultArgs);});$('#robClear').click(function(){god.resultArgs={order:'active',start:0,limit:19,cat:0,searched:'',time:'',mine:'',rand:''};$('#robTime > span').html('All')
getResults(god.resultArgs);});$('#sidePopCatsList > div, #sidePopIconList > div').click(function(){god.resultArgs.mine=0;god.resultArgs.rand=0;god.resultArgs.cat=this.getAttribute('cat');getResults(god.resultArgs);});});iconSidebarSet=function(ec){$('.icon',ec).bind('click',function(){god.resultArgs.mine=0;god.resultArgs.rand=0;if(god.resultArgs.cat!=reverseIcons[this.getAttribute('cat')]){god.resultArgs.cat=reverseIcons[this.getAttribute('cat')];getResults(god.resultArgs);}});}
commentHandle=function(ta,button,postid,replyid){if(!navigator.cookieEnabled){alert('You must have cookies enabled to flag posts');return false;}
if(ta.val().length<3){alert('Add a longer comment, come on, this isnt kindergarten');button.one('click',function(){commentHandle(ta,button,postid,replyid);});return false;}else if(god.now()-$.cookie('lastcom')<13900){alert('Wait a few seconds in between comments. (spam deterrent)');button.one('click',function(){commentHandle(ta,button,postid,replyid);});}else{ta.attr('disabled','disabled');$.ajax({type:'POST',dataType:'json',data:{'text':ta.val(),'postid':postid,'replyid':replyid},url:'ss/comment-handle.php',success:function(json,status){if(json.error){ta.attr('value','Comment Fail');}
else{if(replyid===0){var freshCom='<div class="halfPostComment">'+ta.val()+'<div class="halfPostCommentDate">just now</div></div>';$(freshCom).hide().insertAfter($('#halfPostCommentFormTop')).slideDown('normal');}else{var freshCom='<div class="halfPostComment halfPostCommentReply">'+ta.val()+'<div class="halfPostCommentDate">just now</div></div>';if(ta.parent().parent().find('.halfPostCommentReply').length!=0){$(freshCom).hide().insertAfter(ta.parent().parent().find('.halfPostCommentReply:last')).slideDown('normal');}else{$(freshCom).hide().insertAfter(ta.parent()).slideDown('normal');}}
ta.attr('value','Comment Successful');$.cookie('lastcom',god.now(),god.cookieArgs);addMine(postid);}},error:function(html,status){},timeout:5000});}}
resultPreviewPost=function(postid){if($('#halfPost[postid = '+postid+']').length===0){if($('.result > .icon[postid = '+postid+']','#resultsHolder')[0]){var PPoffset=$('.result > .icon[postid = '+postid+']','#resultsHolder').position();PPoffset.top=PPoffset.top-84;}
$('#resultsHolder2').html('<div id="halfPost"  class="loadImg"><img class="loadImg" src="images/ajax.gif"></img></div>');if(PPoffset){$('#halfPost').css('top',PPoffset.top+'px')}
$.ajax({type:'GET',dataType:'json',data:'postid='+postid,url:'ss/show-post.php',success:function(json,status){document.title='Flammus - '+json.title;var make='<div id="halfPost" postid="'+postid+'" class="hotbox"><div id="halfPostHead" class="shownError">'+json.title+'</div>';make+='<div id="halfPostBody">'+json.body+'</div>';if(json.spam!==null){make+='<div id="halfPostFlaggedBar">This has been marked as spam: <span id="isSpam">This is spam</span> | <span id="isNotSpam">This is not spam</span></div>';}
make+='<div id="halfPostActionBar"><span id="commentButton" >+Comment</span><span id="flagButton">Xspam</flag></div>';make+='<div class="halfPostCommentForm" id="halfPostCommentFormTop" style="display:none"><textarea class="halfPostCommentTA" id="halfPostCommentTA" name="comment" maxlength="800" ></textarea><span id="halfPostCommentSubmit">+submit</span></div></div>';$('#resultsHolder2').html(make);$('#halfPostCommentSubmit').one('click',function(){commentHandle($('#halfPostCommentTA'),$('#halfPostCommentSubmit'),postid,0);});if(PPoffset){$('#halfPost').css('top',PPoffset.top+'px')}
$('#commentButton').bind('click',function(){$('.halfPostCommentForm').toggle();});$('#flagButton').bind('click',function(){if(!navigator.cookieEnabled){alert('You must have cookies enabled to flag posts');return false;}
if(confirm('Are you sure this is spam, yo?')){spamHandle(postid);}});$('#isSpam').bind('click',function(){if(!navigator.cookieEnabled){alert('You must have cookies enabled to flag posts');return false;}
spamHandle(postid);ratedSpam(json.spam,json.notspam,'spam');});$('#isNotSpam').bind('click',function(){if(!navigator.cookieEnabled){alert('You must have cookies enabled to flag posts');return false;}
spamHandle(postid,true);ratedSpam(json.spam,json.notspam,'notspam');});$.ajax({type:'GET',dataType:'json',data:'postid='+postid,url:'ss/show-comments.php',success:function(json,status){if(json.error||json.empty){if(json.error){if($('#commAlert').length==0){$('<div class="shownError" id ="commAlert">').html('Error Getting Comments').fadeIn(400).insertAfter($('#halfPostCommentFormTop'));}}else{$('<div class="halfPostComment">No comments yet. Be "first".</div>').insertAfter($('#halfPostCommentFormTop'));}}else{var make='';var replies=[];for(i in json){if(parseInt(json[i].replyid)===0){make+='<div comid="'+json[i].commentid+'" class="halfPostComment">'+json[i].body+'<div class="halfPostCommentBottom"><span class="halfPostCommentDate">'+json[i].dateposted+'</span><span class="replyButton">+reply</span><span class="commentSpamButton">Xspam</span></div></div>';}else{replies.push(json[i])}}
$(make).insertAfter($('#halfPostCommentFormTop'));if(replies.length!=0){var com=''
for(i in replies){com='<div comid="'+replies[i].commentid+'" class="halfPostComment halfPostCommentReply">'+replies[i].body+'<div class="halfPostCommentBottom"><span class="halfPostCommentDate">'+replies[i].dateposted+'</span><span class="commentSpamButton">Xspam</span></div></div>';$(com).insertAfter($('.halfPostComment[comid = '+replies[i].replyid+'] > .halfPostCommentBottom','#resultsHolder2'));}}
$('span.replyButton','#resultsHolder2').bind('click',function(){var comReplyBox='<div class="halfPostCommentForm" id="halfPostCommentFormReply"><textarea class="halfPostCommentTA" id="halfPostCommentReplyTA" name="comment" maxlength="800" ></textarea><span id="halfPostCommentReplySubmit">+submit</span></div></div>';if($('#halfPostCommentFormReply',$(this).parent().parent()).length===0){$('#halfPostCommentFormReply').remove();$(comReplyBox).insertAfter($(this).parent());$('#halfPostCommentReplySubmit').one('click',function(){commentHandle($('#halfPostCommentReplyTA'),$(this),postid,$(this).parent().parent().attr('comid'));});}else{$('#halfPostCommentFormReply').remove();}});$('span.commentSpamButton ','#resultsHolder2').one('click',function(){spamComHandle($(this).parent().parent().attr('comid'))});}
$('<div id="halfPostCommentFormBottom" class="halfPostCommentForm"><textarea maxlength="800" name="comment" id="halfPostCommentBottomTA" class="halfPostCommentTA"></textarea><span id="halfPostCommentSubmitBottom">+submit</span></div>').appendTo('#halfPost');$('#halfPostCommentSubmitBottom').one('click',function(){commentHandle($('#halfPostCommentBottomTA'),$('#halfPostCommentSubmitBottom'),postid,0);});},error:function(html,status){if($('#commAlert').length===0){$('<div class="shownError" id ="commAlert">').html('Error Getting Comments').fadeIn(400).insertAfter($('#halfPostCommentFormTop'));}},timeout:39000});},error:function(html,status){$('#resultsHolder2').html('');if($('#connectAlert').length==0){$('<div class="shownError" id ="connectAlert">').html('Error Getting Post Info.').fadeIn(400).appendTo($('#resultsHolder2'));}},timeout:39000});}}
ratedSpam=function(spam,notspam,vote){if(vote==='spam'){spam=parseInt(spam)+1;}
else{notspam=parseInt(notspam)+1;}
$('#halfPostFlaggedBar').css({'font-size':'12px','background-color':'#431D00'}).html('Vote counted. Spam: '+spam+' votes, Not Spam: '+notspam+' votes');}
getResults=function(dataObject){$('#resultsHolder').html('<div class="loadImg"><img src="images/ajax.gif"></img></div>');$.ajax({type:'GET',dataType:'json',data:dataObject,url:'ss/fetchposts.php',success:function(json,status){if(json.error||json.empty){$('#resultsHolder').html('');if(json.error){$('<div class="hotbox">').html('<div class="shownError" id ="connectAlert">Server-side error. My b.</div>').fadeIn(400).appendTo($('#resultsHolder'));}
if(json.empty){$('<div class="hotbox">').html('<div class="shownError" id ="connectAlert">No Results to Display :(</div>').fadeIn(400).appendTo($('#resultsHolder'));}}else{god.resultArgs.limit=parseInt(god.resultArgs.limit);var pag=json.shift();if($('#robPopPage')[0]){$('#robPopPage').remove()}
$('div#robResults > span').text(pag.results);$('div#robPages > span').text(((god.resultArgs.start+god.resultArgs.limit)/god.resultArgs.limit)+"/"+pag.pages);if(pag.pages>1){if(pag.results>god.resultArgs.start+god.resultArgs.limit){if($('#footRight').length===0){$('<span id="footRight">').html('Next Page &gt;&gt;').bind('click',function(){god.resultArgs.start+=god.resultArgs.limit;getResults(god.resultArgs);}).appendTo($('#footerWrap'))}}else{$('#footRight').remove()}
if(god.resultArgs.start!==0){if($('#footLeft').length===0){$('<span id="footLeft">').html('&lt;&lt; Last Page').bind('click',function(){god.resultArgs.start-=god.resultArgs.limit;getResults(god.resultArgs);}).appendTo($('#footerWrap'))}}else{$('#footLeft').remove()}
var popDivs='';for(i=1;i<=pag.pages;i+=1){popDivs+='<div page="'+(i-1)+'">'+i+'</div>';}
$('<div class="robPop" id="robPopPage">').html(popDivs).appendTo($('#robPages'));$('#robPopPage div').bind('click',function(){god.resultArgs.start=this.getAttribute('page')*god.resultArgs.limit;getResults(god.resultArgs);})}else{$('#footRight').remove();$('#footLeft').remove();}
var holder=$('#resultsHolder');holder.html('');for(i in json){var resultDiv=$('<div class="result">');$('<div class="icon" catid="'+json[i].catid+'" postid="'+json[i].postid+'" style="background-image:url(_icons/'+json[i].catid+'.png);"></div>').bind('mouseover',function(){$(this).css({'background-image':'url(_icons/6.png)'})}).bind('mouseout',function(){$(this).css({'background-image':'url(_icons/'+this.getAttribute('catid')+'.png)'})}).bind('click',function(){resultPreviewPost(this.getAttribute('postid'));var hash=this.getAttribute('postid')+'_';hash+=encodeURI($(this).parent().find('p').text().replace(/ /g,"-"));window.location.hash=hash;}).appendTo(resultDiv);$('<p>').html(json[i].title).appendTo(resultDiv);var stats='<div class ="stats"><span class="stat commentNum">'+json[i].comments+'</span><span class="stat viewNum">'+json[i].views+'</span><span class="stat timeNum">'+json[i].dateposted+'</span></div>';resultDiv.append($(stats));resultDiv.appendTo(holder);}}},error:function(html,status){$('#resultsHolder').html('');if($('#connectAlert').length==0){$('<div class="hotbox"></div>').html('<div class="shownError" id ="connectAlert">No Results or Connection Error</div>').fadeIn(400).appendTo($('#resultsHolder'));}},timeout:39000});};spamHandle=function(post,notSpam){if($.cookie('flagged')){if(inArray($.cookie('flagged').split('_'),post)){return false;}
$.cookie('flagged',$.cookie('flagged')+'_'+post,god.cookieArgs);}else{$.cookie('flagged',post,god.cookieArgs);}
var notA=notSpam?1:0;$.ajax({type:'POST',dataType:'json',data:{postid:post,not:notA},url:'ss/flag-handle.php',success:function(json,status){},error:function(html,status){},timeout:39000});}
spamComHandle=function(comment){$.ajax({type:'POST',dataType:'json',data:{commentid:comment},url:'ss/spamcom-handle.php',success:function(json,status){$('#halfPost div.halfPostComment[comid = '+comment+']').slideUp();},error:function(html,status){},timeout:39000});}