(function(a,u){function y(c){return typeof c==="string"}function p(c){var g=D.call(arguments,1);return function(){return c.apply(this,g.concat(D.call(arguments)))}}function v(c,g,h,i,B){var s;if(i!==k){g=h.match(c?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);h=g[3]||"";if(B===2&&y(i))i=i.replace(c?J:I,"");else{s=e(g[2]);i=y(i)?e[c?b:j](i):i;i=B===2?i:B===1?a.extend({},i,s):a.extend({},s,i);i=t(i);if(c)i=i.replace(K,F)}c=g[1]+(c?"#":i||!g[1]?"?":"")+i+h}else c=g(h!==k?h:u[f][l]);return c}function z(c,
g,h){if(g===k||typeof g==="boolean"){h=g;g=t[c?b:j]()}else g=y(g)?g.replace(c?J:I,""):g;return e(g,h)}function o(c,g,h,i){if(!y(h)&&typeof h!=="object"){i=h;h=g;g=k}return this.each(function(){var B=a(this),s=g||q()[(this.nodeName||"").toLowerCase()]||"",n=s&&B.attr(s)||"";B.attr(s,t[c](n,h,i))})}var k,D=Array.prototype.slice,F=decodeURIComponent,t=a.param,w,e,m,r=a.bbq=a.bbq||{},C,E,q,d=a.event.special,j="querystring",b="fragment",f="location",l="href",I=/^.*\?|#.*$/g,J=/^.*\#/,K,M={};t[j]=p(v,0,
function(c){return c.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")});t[b]=w=p(v,1,function(c){return c.replace(/^[^#]*#?(.*)$/,"$1")});w.noEscape=function(c){c=c||"";c=a.map(c.split(""),encodeURIComponent);K=RegExp(c.join("|"),"g")};w.noEscape(",/");a.deparam=e=function(c,g){var h={},i={"true":true,"false":false,"null":null};a.each(c.replace(/\+/g," ").split("&"),function(B,s){var n=s.split("="),A=F(n[0]),L=h,H=0,x=A.split("]["),G=x.length-1;if(/\[/.test(x[0])&&/\]$/.test(x[G])){x[G]=x[G].replace(/\]$/,
"");x=x.shift().split("[").concat(x);G=x.length-1}else G=0;if(n.length===2){n=F(n[1]);if(g)n=n&&!isNaN(n)?+n:n==="undefined"?k:i[n]!==k?i[n]:n;if(G)for(;H<=G;H++){A=x[H]===""?L.length:x[H];L=L[A]=H<G?L[A]||(x[H+1]&&isNaN(x[H+1])?{}:[]):n}else if(a.isArray(h[A]))h[A].push(n);else h[A]=h[A]!==k?[h[A],n]:n}else if(A)h[A]=g?k:""});return h};e[j]=p(z,0);e[b]=m=p(z,1);a.elemUrlAttr||(a.elemUrlAttr=function(c){return a.extend(M,c)})({a:l,base:l,iframe:"src",img:"src",input:"src",form:"action",link:l,script:"src"});
q=a.elemUrlAttr;a.fn[j]=p(o,j);a.fn[b]=p(o,b);r.pushState=C=function(c,g){if(y(c)&&/^#/.test(c)&&g===k)g=2;var h=c!==k;h=w(u[f][l],h?c:{},h?g:2);u[f][l]=h+(/#/.test(h)?"":"#")};r.getState=E=function(c,g){return c===k||typeof c==="boolean"?m(c):m(g)[c]};r.removeState=function(c){var g={};if(c!==k){g=E();a.each(a.isArray(c)?c:arguments,function(h,i){delete g[i]})}C(g,2)};d.hashchange=a.extend(d.hashchange,{add:function(c){function g(i){var B=i[b]=w();i.getState=function(s,n){return s===k||typeof s===
"boolean"?e(B,s):e(B,n)[s]};h.apply(this,arguments)}var h;if(a.isFunction(c)){h=c;return g}else{h=c.handler;c.handler=g}}})})(jQuery,this);
(function(a,u,y){function p(w){w=w||u[o][k];return w.replace(/^[^#]*#?(.*)$/,"$1")}var v,z=a.event.special,o="location",k="href",D=document.documentMode,F=a.browser.msie&&(D===y||D<8),t="onhashchange"in u&&!F;a.hashchangeDelay=100;z.hashchange=a.extend(z.hashchange,{setup:function(){if(t)return false;a(v.start)},teardown:function(){if(t)return false;a(v.stop)}});v=function(){function w(){C=E=function(q){return q};if(F){r=a('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;
E=function(){return p(r.document[o][k])};C=function(q,d){if(q!==d){var j=r.document;j.open().close();j[o].hash="#"+q}};C(p())}}var e={},m,r,C,E;e.start=function(){if(!m){var q=p();C||w();(function d(){var j=p(),b=E(q);if(j!==q){C(q=j,b);a(u).trigger("hashchange")}else if(b!==q)u[o][k]=u[o][k].replace(/#.*/,"")+"#"+b;m=setTimeout(d,a.hashchangeDelay)})()}};e.stop=function(){if(!r){m&&clearTimeout(m);m=0}};return e}()})(jQuery,this);(function(a){function u(d){a(d.css.toggle).click(function(){if(a(this).attr("class")==="gcpCommentsOnLink"){a(this).html("hide comments");a(this).attr("class","gcpCommentsOffLink");a(d.css.commentsBox).show();a(d.css.commentsBox).css("visibility","visible");a.gcpcookie("gcp.toggle.comments",null);a.gcpcookie("gcp.toggle.comments","true",{expires:7,path:"/"});E=true}else{a(this).html("show comments");a(this).attr("class","gcpCommentsOnLink");a(d.css.commentsBox).hide();a(d.css.commentsBox).css("visibility",
"hidden");a.gcpcookie("gcp.toggle.comments",null);a.gcpcookie("gcp.toggle.comments","false",{expires:7,path:"/"});E=false}});if(d.inline==="true"){var j=function(){window.location.href=a(this).attr("value")};a(d.css.sortBoxTop).change(j);a(d.css.sortBoxBottom).change(j)}else{a(d.css.sortBoxTop).change(function(){m.data("gcp-state",{cache:{}});o=a(this).attr("value");var b={};b[m.attr("id")]={p:k,s:o};a.bbq.pushState(b);return false});a(d.css.sortBoxBottom).change(function(){m.data("gcp-state",{cache:{}});
o=a(this).attr("value");var b={};b[m.attr("id")]={p:k,s:o};a.bbq.pushState(b);return false})}a(d.css.commentsBox+" "+d.css.reportLink).click(function(){if(confirm("Are you sure you want to report this comment?")){var b={channel_id:d.channel_id,comment_id:this.id.substr(1),devId:p,gcp_a:v,version:d.version};a.post(d.write_prefix+"/report_comment",b,function(f,l){if(l==="error")alert("We're sorry your report could not be saved due to technical problems.");else if(f.status==="OK")alert("Comment has been reported for review. Thank You!");
else f.status==="DUPLICATE_RECORD"?alert("You have already reported this comment."):alert("We're sorry your report could not be saved due to technical problems.")})}return false});a(d.css.commentsBox+" "+d.css.voteUpLink).click(function(){if(!z){q==="sns"?alert("You must sign-in to vote"):a("#"+d.authSelector).click();return false}var b={channel_id:d.channel_id,asset_id:this.id.substr(10),asset_type:"comment",rating_type:"up-down",rating:1,devId:p,gcp_a:v,get_rating:true,version:d.version};if(r!=
null)b=a.extend(b,r);a.post(d.write_prefix+"/add_rating",b,function(f,l){if(l==="error")alert("We're sorry your rating could not be added due to technical problems.");else if(f.status==="OK"){alert("Rating added successfully.");a("#gcpVoteUp-"+b.asset_id).addClass("votedComment");a("#gcpVoteUp-"+b.asset_id).text("("+f.ratings[0].count+")")}else f.status==="DUPLICATE_RECORD"?alert("You have already rated this comment."):alert("We're sorry your rating could not be added due to technical problems.")});
return false});a(d.css.commentsBox+" "+d.css.voteDownLink).click(function(){if(!z){q==="sns"?alert("You must sign-in to vote"):a("#"+d.authSelector).click();return false}var b={channel_id:d.channel_id,asset_id:this.id.substr(12),asset_type:"comment",rating_type:"up-down",rating:-1,devId:p,gcp_a:v,get_rating:true,version:d.version};if(r!=null)b=a.extend(b,r);a.post(d.write_prefix+"/add_rating",b,function(f,l){if(l==="error"){alert("We're sorry your rating could not be added due to technical problems.");
alert(l)}else if(f.status==="OK"){alert("Rating added successfully.");a("#gcpVoteDown-"+b.asset_id).addClass("votedComment");a("#gcpVoteDown-"+b.asset_id).text("("+f.ratings[0].downCount+")")}else f.status==="DUPLICATE_RECORD"?alert("You have already rated this comment."):alert("We're sorry your rating could not be added due to technical problems.")});return false});a(d.css.commentsBox+" "+d.css.replyDiv+" > "+d.css.replyButton).click(function(){if(t){a("#gcpCommentReply-"+t).html("");t=null}var b=
this.id.substr(9);a("#gcpCommentReply-"+b).html(F);var f=a("#gcpCommentReply-"+b).find(".gcpReplyIndicator");a(f).html(' <a id="gcpUndoReply" class="gcpUndoReply" href="javascript:void(0);">Undo</a>');f=a("#gcpCommentReply-"+b).find(".gcpReplyTo");a(f).val(b);y(a("#gcpCommentReply-"+b).find(".gcpCommentReplyForm"),a("#gcpCommentReply-"+b).find(".gcpCommentReplyBody"),d);t=b;a(a("#gcpCommentReply-"+b).find(".gcpUndoReply")).click(function(){a("#gcpCommentReply-"+b).html("");t=null});return false})}
function y(d,j,b){a(d).submit(function(){if(!z){q==="sns"?alert("You must sign-in to add a comment"):a("#"+b.authSelector).click();return false}var f=a(j).val();if(f===null||f===""){alert("Don't you have anything to say?");return false}f={channel_id:b.channel_id,topic_id:b.topic_id,devId:p,gcp_a:v,body:f,version:b.version};if(r!=null)f=a.extend(f,r);var l=a(b.css.replyToBox).val();if(l!=="")f.parent_comment_id=l;else k=1;a.post(b.write_prefix+"/add_comment",f,function(I,J){if(J==="error")alert("We're sorry your comment could not be added due to technical problems.");
else if(I.status==="OK"){alert("Comment added successfully");var K={m:"get_topic_comments",h:"comments",start:(k-1)*b.count,count:b.count,sort:o,channel_id:b.channel_id,topic_id:b.topic_id,version:b.version,comment_count_selector:D,dirty:"true",random:Math.random()};if(b.inline=="true"){a(b.css.commentBody).val("");a(b.css.undoReply).click();window.location.reload()}else a.get(b.read_prefix+"/comments_406.jsp",K,function(M,c){if(c==="error")a(b.css.commentsContainer).html("Comments are temporarily unavailable. We hope to be back soon.");
else{a(b.css.commentsContainer).html(M);a(b.css.commentBody).val("");a(b.css.undoReply).click();u(b);y(b.css.commentForm,b.css.commentBody,b)}})}else alert("We're sorry your comment could not be added due to technical problems.")});return false})}var p=null,v=null,z=false,o="old",k=1,D,F='<div id="gcpAddCommentsMain"><form method="post" name="gcp-comment-form" id="gcpCommentReplyForm" class="gcpCommentReplyForm" action="#"><div class="gcpFormErrors" id="gcpFormErrors"></div><div id="gcpCommentMain"><div><div id="gcpReplyIndicator" class="gcpReplyIndicator"></div><textarea rows="8" id="gcpCommentReplyBody" name="gcpCommentReplyBody" class="gcpCommentReplyBody"></textarea><input type="hidden" id="gcpReplyTo" name="reply_to" class="gcpReplyTo" /></div><div id="gcpCommentButtons"><input type="submit" value="Add Comment" id="gcpAddCommentButton"></div></div></form></div>',
t=null,w={max_reply_depth:1,sort:"old",read_prefix:"/gcpread",write_prefix:"/gcpwrite",count:20,version:1,authSelector:"authLink",authType:"multiauth",css:{toggle:"#gcpCommentsOffLink",commentsContainer:"#gcpMain",commentsBox:"#gcpCommentsContent",commentsList:"#gcpCommentsList",reportLink:".gcpReportLink",voteUpLink:".gcpVoteUpLink",voteDownLink:".gcpVoteDownLink",commentForm:"#gcpCommentForm",commentReplyForm:"#gcpCommentReplyForm",commentBody:"#gcpCommentBody",commentReplyBody:"#gcpCommentReplyBody",
replyDiv:".gcpReplyBtnItem",replyButton:".gcpReplyButton",replyIndicator:"#gcpReplyIndicator",undoReply:"#gcpUndoReply",replyToBox:"#gcpReplyTo",nextPage:".gcpNextPage",prevPage:".gcpPrevPage",mostRecent:"#gcpMostRecent",sortBoxTop:"#gcpSortMenuTop",sortBoxBottom:"#gcpSortMenuBottom"}},e,m=null,r,C=false,E=true,q;a.fn.comments=function(d,j){if(typeof d==="object"){e=d;d="init"}e=a.extend({},w,e,j);return this.each(function(){if(d==="init"){o=e.sort;D=e.comment_count_selector;q=e.authType;r={permalink:e.permalink,
title:e.topic_title,description:e.topic_description,create_topic:true,type:"article"};m=a(this);if(e.inline==="true"){C=true;u(e);y(e.css.commentForm,e.css.commentBody,e)}else{m.data("gcp-state",{cache:{}});a.each([e.css.prevPage,e.css.nextPage],function(b,f){a(f).live("click",function(){var l={};l[m.attr("id")]={p:a(this).attr("href").replace(/^[^#]*#/,""),s:o};a.bbq.pushState(l);return false})});a(window).bind("hashchange",function(){data=m.data("gcp-state");url=a.bbq.getState(m.attr("id"))||"";
if(data.url!==url){data.url=url;if(data=a.deparam.fragment()[m.attr("id")]){k=data.p;o=data.s}else{k=1;o=e.sort}var b=a.gcpcookie("gcp.toggle.comments");if(b===null||b==="")b=true;b={m:"get_topic_comments",start:(k-1)*e.count,count:e.count,sort:o,channel_id:e.channel_id,topic_id:e.topic_id,version:e.version,comment_count_selector:D,random:Math.random(),toggle_comments:b};if(a.gcpcookie("gcp.dirty"))b=a.extend({},b,{dirty:"true"});a.get(e.read_prefix+"/comments_406.jsp",b,function(f,l){if(l==="error")a(e.css.commentsContainer).html("Comments are temporarily unavailable. We hope to be back soon.");
else{m.html(f);u(e);y(e.css.commentForm,e.css.commentBody,e)}})}});a(window).trigger("hashchange")}}else if(d==="auth"){z=true;p=e.devId;v=e.authToken}else if(d==="unauth"){z=false;v=p=null}})};a.gcpcookie=function(d,j,b){if(typeof j!="undefined"){b=b||{};if(j===null){j="";b.expires=-1}var f="";if(b.expires&&(typeof b.expires=="number"||b.expires.toUTCString)){if(typeof b.expires=="number"){f=new Date;f.setTime(f.getTime()+b.expires*24*60*60*1E3)}else f=b.expires;f="; expires="+f.toUTCString()}var l=
b.path?"; path="+b.path:"/",I=b.domain?"; domain="+b.domain:"";b=b.secure?"; secure":"";document.cookie=[d,"=",encodeURIComponent(j),f,l,I,b].join("")}else{j=null;if(document.cookie&&document.cookie!=""){b=document.cookie.split(";");for(f=0;f<b.length;f++){l=jQuery.trim(b[f]);if(l.substring(0,d.length+1)==d+"="){j=decodeURIComponent(l.substring(d.length+1));break}}}return j}}})(jQuery);
