var GComments=GComments||{};GComments.Commenter=function(c){this._textarea=null;this._post_button=null;this._form=null;this._config={container:null,max_length:210,placeholder:gettext("comments"),new_on_top:false,im_style:false,callback:function(){}};$.extend(this._config,c);var b=$(this._config.container);this._textarea=this._config.container.find("textarea");this._post_button=this._config.container.find(".btn_post");this._form=this._config.container.find("form");this._delete_btns=this._config.container.find(".close_btn_m");var a=b.attr("allow_comment");if(!parseInt(a)){this._textarea.remove();return false}this._form.submit($.proxy(function(){this._postComment();return false},this));this._textarea.attr("placeholder",this._config.placeholder);this._textarea.click($.proxy(this._clickTextarea,this));this._post_button.click($.proxy(this._clickPostBtn,this));this._textarea.blur($.proxy(this._blurTextarea,this));this._textarea.change($.proxy(this._handleOverflow,this));this._textarea.bind("keypress",$.proxy(this._handleKeyPress,this));this._textarea.bind("input paste",$.proxy(this._handleOverflow,this));$(this._delete_btns.selector).live("click",{$this:this},this._clickDeleteBtn);if(_.size(this._config.container.siblings(".show_likes").children())>0){this._form.addClass("on")}if(this._config.im_style){this._config.container.find("ul li:nth-child(5n+1)").find(".time_box").css("display","block");var d=this._config.container.find(".comment_list");setTimeout(function(){d.prop({scrollTop:d.prop("scrollHeight")})},100)}if(this._config.container.find("li").length>0){this._config.container.find(".no_comment_msg").css("display","none")}};GComments.Commenter.prototype={_removeTextarea:function(){this._textarea.remove()},_disabledTextarea:function(){this._textarea.attr("disabled",true);this._textarea.val(gettext("You can't comment on this."))},_clickTextarea:function(){this._textarea.val((this._textarea.val()==this._config.placeholder)?"":this._textarea.val());$.proxy(this._showPostButton,this)();$.proxy(this._handleOverflow,this)()},_clickDeleteBtn:function(b){var a=$(this).attr("class").split(" ")[1];var c=b.data.$this;confirmTxt(gettext("Delete this comment?"),{callback_click_yes:function(){c._handleDelete(a)}})},_blurTextarea:function(){if(!this._textarea.val()){this._hidePostButton();this._textarea.animate({height:"15px"},200,function(){})}},_showPostButton:function(){this._textarea.autogrow()},_hidePostButton:function(){},_handleKeyPress:function(b){var a=(b.keyCode?b.keyCode:b.which);if(a==13){if(b.shiftKey){}else{this._postComment();this._textarea.blur();return false}}else{$.proxy(this._handleOverflow,this)()}},_clickPostBtn:function(){this._postComment();this._textarea.val("");this._textarea.blur();return false},_handleOverflow:function(){if(this._textarea.val().length>this._config.max_length){this._textarea.val(this._textarea.val().substring(0,this._config.max_length))}},_postComment:function(){var a=this._form.attr("action");var b=this._form.serializeObject();b.view_session_id=gViewSessionID;$.ajax({type:"POST",url:a,data:b,success:$.proxy(this._handleSuccess,this),error:$.proxy(this._handleError,this),dataType:"json"})},_handleSuccess:function(b){if(!b.success){this._handleFailure(b);return}this._hidePostButton();this._textarea.animate({height:"15px"},200,function(){});this._textarea.val("");var c=$(b.html).hide();this._config.container.find(".nothing_data.comment").css("display","none");if(this._config.im_style){c=$(b.html_im).hide();c.removeClass("pic_align_left");c.addClass("pic_align_right");c.appendTo(this._config.container.find(".comment_list ul")).show();this._config.container.find(".comment_list").prop({scrollTop:this._config.container.find(".comment_list").prop("scrollHeight")});this._textarea.val("");this._textarea.focus()}else{if(this._config.new_on_top){c.prependTo(this._config.container.find(".comment_list")).fadeIn("slow")}else{c.insertBefore(this._form).fadeIn("slow")}}var a=this._config.container.find(".all_comment_count");if(a.length>0){var a=parseInt(a.text(),10);this._config.container.find(".all_comment_count").text(a+1)}this._config.callback()},_handleDelete:function(c){var a="/gcomments/ajax/delete_comment/";var b=c;var d={comment_id:b};$.ajax({type:"POST",url:a,data:d,success:$.proxy(this._handleSuccessDelete,this),error:$.proxy(this._handleError,this),dataType:"json"})},_handleSuccessDelete:function(d){var c=this._config.container.find(".comment_box."+d.comment_id);var a=c.length;c.fadeOut(200,function(){c.remove()});var b=parseInt(this._config.container.find(".all_comment_count").text(),10);this._config.container.find(".all_comment_count").text(b-a);if(b<=0){this._config.container.find(".comment_box.view_all_comments").remove()}},_handleFailure:function(a){},_handleError:function(a,c,b){if(a.status==400){autoShowDialogAjax({url:"/ajaxloginpopup/",nail:140,tpye:"GET",data:"",dataType:"html",cache:false,callback:function(){},callback_close:function(){}});return false}},_display_normal:function(b){var a=$("#gulu_template_commentbox")}};GComments.comment=function(b){var a=b.parents(".wall_item").find("textarea");b.parents(".wall_item").find(".comment_form").addClass("on");a.val("").focus()};
