YAHOO.namespace("supernifty");YAHOO.supernifty.comments=function(){var z="/comment_server.php";var p=null;var c=null;var k=null;var H="";var d=false;var G=-1;var r;var w=null;var t=function(){e({command:"authenticate"},c,"Checking login",s)};var x=function(){if(w){return w}else{return location.href}};var B=function(){if(typeof(comments_style)!="undefined"&&comments_style=="admin"){e({command:"admin"},k,null,F)}else{if(typeof(comments_style)=="undefined"||comments_style!="nolist"){e({command:"list",url:escape(x()),page:"0"},k,null,h)}}};var o=function(L){u();YAHOO.util.Event.preventDefault(L);return false};var u=function(){e({command:"add",url:escape(x()),message:document.getElementById("message_text").value},c,"Adding comment...",D)};var I=function(L){q();YAHOO.util.Event.preventDefault(L);return false};var q=function(){e({command:"register",url:escape(x())},c,"Registering...",l)};var m=function(L){return function(M){f(L);YAHOO.util.Event.preventDefault(M);return false}};var f=function(L){e({command:"delete",url:escape(x()),commentID:L},c,"Deleting...",i)};show_progress=function(N,L){N.innerHTML="<img src='http://static.supernifty.com.au/images/progress.gif' style='vertical-align: middle'/>"+L;var M=new YAHOO.util.ColorAnim(N,{backgroundColor:{to:"#ff9",from:"#f66"},duration:1});M.animate()};var C=function(N,L){N.innerHTML="<img src='http://static.supernifty.com.au/images/error.png' style='vertical-align: middle'/>"+L;var M=new YAHOO.util.ColorAnim(N,{backgroundColor:{to:"#ff9",from:"#f66"},duration:1});M.animate()};var g=function(N,L){N.innerHTML=L;var M=new YAHOO.util.ColorAnim(N,{backgroundColor:{to:"#fee",from:"#f66"},duration:1});M.animate()};var y=function(N,L){if(L!=N.innerHTML){N.innerHTML=L;var M=new YAHOO.util.ColorAnim(N,{backgroundColor:{to:"#fff",from:"#f66"},duration:0.1});M.animate()}};var b=function(){if(typeof(comments_style)=="undefined"||comments_style=="chat"){return"<div id='comments_add_header'>Say something</div><form id='comment_form'><textarea id='message_text'></textarea><br/><input type='submit' value='Add Message'/></form>"}else{if(comments_style=="admin"){return""}else{return"<div id='comments_add_header'>Leave a comment</div><form id='comment_form'><textarea id='message_text'></textarea><br/><input type='submit' value='Add Message'/></form>"}}};var s=function(L){if(L.status=="ok"){H=L.nickname;d=true;g(c,b());YAHOO.util.Event.addListener("comment_form","submit",o)}else{g(c,"<div id='comments_add_header'>To leave a comment, please <a href='/login.php?target="+escape(x())+"'>login</a></div>")}};var J=function(M){if(M==0){return"a moment"}if(M<60){return M+" second"+(M==1?"":"s")}if(M<3600){var L=Math.round(M/60);return L+" minute"+(L==1?"":"s")}if(M<87600){var N=Math.round(M/3600);return N+" hour"+(N==1?"":"s")}if(M<87600*30){var O=Math.round(M/87600);return O+" day"+(O==1?"":"s")}if(M<87600*365){var L=Math.round(M/87600/30);return L+" month"+(L==1?"":"s")}return"over a year"};var K=function(P,M){var L="";for(var N=0;N<P.length;N++){if(M){var O="comments_delete_"+P[N]["id"];L+='<div class="comments_item_header"><img src="http://www.gravatar.com/avatar.php?gravatar_id='+P[N]["email"]+"&size=32&default="+escape("http://static.supernifty.com.au/images/user_gray.png")+'" style="vertical-align: middle"/>'+P[N]["nickname"]+" said "+J(P[N]["created"])+' ago:&nbsp;&nbsp;<a href="nojs.php" id="'+O+'">Delete</a></div>'}else{L+='<div class="comments_item_header"><img src="http://www.gravatar.com/avatar.php?gravatar_id='+P[N]["email"]+"&size=32&default="+escape("http://static.supernifty.com.au/images/user_gray.png")+'" style="vertical-align: middle"/>'+P[N]["nickname"]+" said "+J(P[N]["created"])+" ago:</div>"}L+=P[N]["message"]}return L};var A=function(N){for(var L=0;L<N.length;L++){var M="comments_delete_"+N[L]["id"];YAHOO.util.Event.addListener(M,"click",m(N[L]["id"]))}};var h=function(M){if(M.status=="ok"){var N=M.list;var L="";if(N.length>0){if(N[0]["id"]!=G){G=N[0]["id"];L=K(N,M.owner=="1");y(k,L);if(M.owner=="1"){A(N)}}}else{y(k,L)}}else{if(M.status=="error"&&M.detail=="page not registered"){y(k,"You must register this page to accept comments. <a id='comment_register' href='/nojs.php'>register now</a>");YAHOO.util.Event.addListener("comment_register","click",I)}else{C(k,M.detail)}}};var a=function(L){return function(M){var N=document.getElementById(L);if(N.style.display=="block"){N.style.display="none"}else{N.style.display="block"}YAHOO.util.Event.preventDefault(M);return false}};var F=function(M){if(M.status=="ok"){var L="";var O=M.list;for(var N=0;N<O.length;N++){L+='<a href="'+O[N]["url"]+'">'+O[N]["url"]+"</a> "+O[N]["comments"].length+" comment"+(O[N]["comments"].length==1?"":"s");if(O[N]["comments"].length>0){L+=" changed "+J(O[N]["comments"][0]["created"])+" ago"}L+='&nbsp;<a id="comment_block_show_'+N+'" href="nojs.php">Show</a><br/><div id="comment_block_'+N+'" style="display: none">'+K(O[N]["comments"],true)+"</div><br/>"}y(k,L);for(var N=0;N<O.length;N++){YAHOO.util.Event.addListener("comment_block_show_"+N,"click",a("comment_block_"+N));A(O[N]["comments"])}}else{C(k,M.detail)}};var D=function(L){if(L.status=="ok"){if(typeof(comments_style)=="undefined"||comments_style!="nolist"){g(c,"<img src='http://static.supernifty.com.au/images/accept.png'/>Your comment was added!<br/>"+b())}else{g(c,"<img src='http://static.supernifty.com.au/images/accept.png'/>Your comment was added - it will be displayed in a moment.<br/>"+b())}YAHOO.util.Event.addListener("comment_form","submit",o);B()}else{C(c,L.detail)}};var i=function(L){if(L.status=="ok"){g(c,"<img src='http://static.supernifty.com.au/images/accept.png'/>Comment deleted.<br/>"+b());YAHOO.util.Event.addListener("comment_form","submit",o);G=-1;B()}else{C(c,L.detail)}};var l=function(L){if(L.status=="ok"){g(c,"<img src='http://static.supernifty.com.au/images/accept.png'/>The page was registered!<br/>"+b());YAHOO.util.Event.addListener("comment_form","submit",o);B()}else{if(L.detail=="not logged in"){g(c,"<div id='comments_add_header'>To register this page to accept comments, please first <a href='/login.php?target="+escape(x())+"'>login</a></div>")}else{C(c,L.detail)}}};var e=function e(N,L,M,O){if(M){show_progress(L,M)}YAHOO.util.Connect.asyncRequest("POST",z,{success:v(L,O),failure:n(L)},"json="+YAHOO.lang.JSON.stringify(N))};var v=function(L,M){return function(O){try{M(YAHOO.lang.JSON.parse(O.responseText))}catch(N){C(L,"Error: "+N.name+": "+N.message);alert(O.responseText)}}};var n=function(L){return function(){C(L,"Error: Failed to connect to server.")}};var E=function(){if(!d){t()}B()};var j=function(){p=document.getElementById("comments");c=document.createElement("div");c.setAttribute("id","comments_add");p.appendChild(c);p.appendChild(document.createElement("br"));if(typeof(comments_style)=="undefined"||comments_style!="nolist"){k=document.createElement("div");k.setAttribute("id","comments_list");p.appendChild(k)}E()};return{build:function(){E()},override_url:function(L){w=L;E()},init:function(){j();E()}}}();YAHOO.util.Event.onAvailable("comments",YAHOO.supernifty.comments.init);

