var lsCmtTreeClass=new Class({Implements:Options,options:{img:{path:"images/",openName:"open.gif",closeName:"close.gif"},classes:{visible:"lsCmtTree_visible",hidden:"lsCmtTree_hidden",openImg:"lsCmtTree_open",closeImg:"lsCmtTree_close"}},initialize:function(a){this.setOptions(a);this.make();this.aCommentNew=[];this.iCurrentShowFormComment=0;this.iCommentIdLastView=null;this.countNewComment=0;this.docScroller=new Fx.Scroll(document.getDocument());this.hideCommentForm(this.iCurrentShowFormComment)},make:function(){var b=this;var a=$$("img.folding");a.each(function(c,d){var e=c.getParent("div").getChildren("div.comment-children")[0];if(e&&e.getChildren("div.comment")[0]){b.makeImg(c)}else{c.setStyle("display","none")}})},makeImg:function(a){var b=this;a.setStyle("cursor","pointer");a.setStyle("display","inline");a.addClass(this.options.classes.closeImg);a.removeEvents("click");a.addEvent("click",function(){b.toggleNode(a)})},toggleNode:function(c){var a=c.hasClass(this.options.classes.closeImg);if(a){this.collapseNode(c)}else{this.expandNode(c)}},expandNode:function(a){var c=this;a.setProperties({"src":this.options.img.path+this.options.img.closeName});a.removeClass(this.options.classes.openImg);a.addClass(this.options.classes.closeImg);var b=a.getParent("div").getChildren("div.comment-children")[0];b.removeClass(c.options.classes.hidden);b.addClass(c.options.classes.visible)},collapseNode:function(a){var c=this;a.setProperties({"src":this.options.img.path+this.options.img.openName});a.removeClass(this.options.classes.closeImg);a.addClass(this.options.classes.openImg);var b=a.getParent("div").getChildren("div.comment-children")[0];b.removeClass(c.options.classes.visible);b.addClass(c.options.classes.hidden)},expandNodeAll:function(){var b=this;var a=$$("img."+this.options.classes.openImg);a.each(function(c,d){b.expandNode(c)})},collapseNodeAll:function(){var b=this;var a=$$("img."+this.options.classes.closeImg);a.each(function(c,d){b.collapseNode(c)})},injectComment:function(a,e,f){var d=new Element("div",{"class":"comment","id":"comment_id_"+e});d.set("html",f);if(a){this.expandNodeAll();var b=$("comment-children-"+a);var c=b.getParent("div").getChildren("img.folding")[0];this.makeImg(c);b.appendChild(d)}else{var b=$("comment-children-0");d.inject(b,"before")}},responseNewComment:function(g,d,a,e){var f=this;if(!e){var b=$$(".comment");b.each(function(j,i){var h=j.getChildren("div.content")[0];if(h){h.removeClass("new");h.removeClass("view")}})}var c=this.idCommentLast;d=$(d);d.setProperty("src",DIR_STATIC_SKIN+"/images/update_act.gif");(function(){JsHttpRequest.query(DIR_WEB_ROOT+"/include/ajax/commentResponse.php",{idCommentLast:c,idTopic:g},function(h,l){d.setProperty("src",DIR_STATIC_SKIN+"/images/update.gif");if(!h){msgErrorBox.alert("Error","Please try again later")}if(h.bStateError){msgErrorBox.alert(h.sMsgTitle,h.sMsg)}else{var j=h.aComments;if(j.length>0&&h.iMaxIdComment){f.setIdCommentLast(h.iMaxIdComment);var k=$("count-comments");k.set("text",parseInt(k.get("text"))+j.length);if($("block_stream_comment")&&lsBlockStream){lsBlockStream.toggle($("block_stream_comment"),"comment_stream")}}var i=0;if(e){i=f.countNewComment}else{f.aCommentNew=[]}if(a){f.setCountNewComment(j.length-1+i);f.hideCommentForm(f.iCurrentShowFormComment)}else{f.setCountNewComment(j.length+i)}j.each(function(n,m){if(!(a&&a==n.id)){f.aCommentNew.extend([n.id])}f.injectComment(n.idParent,n.id,n.html)});if(a&&$("comment_id_"+a)){f.scrollToComment(a)}}},true)}).delay(1000)},setIdCommentLast:function(a){this.idCommentLast=a},setCountNewComment:function(b){this.countNewComment=b;var a=$("new-comments");if(this.countNewComment>0){a.set("text",this.countNewComment);a.setStyle("display","block")}else{this.countNewComment=0;a.set("text",0);a.setStyle("display","none")}},goNextComment:function(){if(this.aCommentNew[0]){if($("comment_id_"+this.aCommentNew[0])){this.scrollToComment(this.aCommentNew[0])}this.aCommentNew.erase(this.aCommentNew[0])}this.setCountNewComment(this.countNewComment-1)},scrollToComment:function(c){this.docScroller.setOptions({duration:500,offset:{"x":0,"y":0}});var b=$("comment_content_id_"+c);var a=b.getDimensions().height/2-window.getSize().y/2;if(a>0){a=0}this.docScroller.start(0,b.getPosition().y+a);if(this.iCommentIdLastView){$("comment_content_id_"+this.iCommentIdLastView).removeClass("view")}$("comment_content_id_"+c).addClass("view");this.iCommentIdLastView=c},addComment:function(a,b){var c=this;a=$(a);JsHttpRequest.query(DIR_WEB_ROOT+"/include/ajax/commentAdd.php",{params:a},function(d,e){if(!d){c.enableFormComment();msgErrorBox.alert("Error","Please try again later")}if(d.bStateError){c.enableFormComment();msgErrorBox.alert(d.sMsgTitle,d.sMsg)}else{$("form_comment_text").disabled=true;c.responseNewComment(b,$("update-comments"),d.sCommentId,true)}},true);$("form_comment_text").addClass("loader")},enableFormComment:function(){$("form_comment_text").removeClass("loader");$("form_comment_text").disabled=false},addCommentScroll:function(a){this.aCommentNew.extend([a]);this.setCountNewComment(this.countNewComment+1)},toggleComment:function(c,b){var a=$("comment_content_id_"+b);if(!a){return false}var d=this;JsHttpRequest.query(DIR_WEB_ROOT+"/include/ajax/commentToggle.php",{idComment:b},function(e,f){if(!e){msgErrorBox.alert("Error","Please try again later")}if(e.bStateError){msgErrorBox.alert(e.sMsgTitle,e.sMsg)}else{msgNoticeBox.alert(e.sMsgTitle,e.sMsg);a.removeClass("old").removeClass("self").removeClass("new").removeClass("del");c.removeClass("delete").removeClass("repair");if(e.bState){a.addClass("del");c.addClass("repair")}else{c.addClass("delete")}c.set("text",e.sTextToggle)}},true)},toggleCommentForm:function(b){if(!$("reply_"+this.iCurrentShowFormComment)||!$("reply_"+b)){return}divCurrentForm=$("reply_"+this.iCurrentShowFormComment);divNextForm=$("reply_"+b);var a=new Fx.Slide(divCurrentForm);var c=new Fx.Slide(divNextForm);$("comment_preview_"+this.iCurrentShowFormComment).set("html","").setStyle("display","none");if(this.iCurrentShowFormComment==b){a.toggle();return}a.slideOut();divNextForm.set("html",divCurrentForm.get("html"));divCurrentForm.set("html","");divNextForm.setStyle("display","block");c.hide();c.slideIn();$("form_comment_text").setProperty("value","");$("form_comment_reply").setProperty("value",b);this.iCurrentShowFormComment=b},hideCommentForm:function(b){if($("reply_"+b)){this.enableFormComment();$("comment_preview_"+this.iCurrentShowFormComment).set("html","").setStyle("display","none");var a=new Fx.Slide("reply_"+b);a.hide()}},preview:function(){ajaxTextPreview("form_comment_text",false,"comment_preview_"+this.iCurrentShowFormComment)},goToParentComment:function(c){var d=c.href.substr(c.href.indexOf("#")+8);var a=$("comment_id_"+d);var b=c.getParent("div.comment");a.getElement(".goto-comment-child").removeClass("hidden");a.getElement(".goto-comment-child a").href="#comment"+b.id.substr(11);this.docScroller.setOptions({offset:{"y":0}});this.docScroller.toElement(a);return false},goToChildComment:function(c){var d=c.href.substr(c.href.indexOf("#")+8);var a=$("comment_id_"+d);var b=c.getParent("div.comment");b.getElement(".goto-comment-child").addClass("hidden");this.docScroller.setOptions({offset:{"y":0}});this.docScroller.toElement(a);return false}});var lsCmtTree;var formCommentSlide;window.addEvent("domready",function(){lsCmtTree=new lsCmtTreeClass({img:{path:DIR_STATIC_SKIN+"/images/"},classes:{openImg:"folding-open",closeImg:"folding"}})});
