var login_form_visible=false;function toggleLoginForm(b){var a=$("#signin_float");if(login_form_visible){a.fadeOut()}else{a.fadeIn()}login_form_visible=!login_form_visible};var commentFormHtml='<br/><form action="javascript:void(null)" onsubmit="commentsComponent.submitForm( this ); return false;">';commentFormHtml+='<textarea cols="60" rows="6" name="comment[comment]"></textarea>';commentFormHtml+="<br/>";commentFormHtml+='<input type="hidden" name="comment[commentable_id]" value="%commentableId%" />';commentFormHtml+='<input type="submit" value="Post comment" /> <a href="javascript:void(null)" onclick="commentsComponent.hideForm(%commentableId%);">Cancel</a>';commentFormHtml+="</form>";var commentReplyFormHtml='<form action="javascript:void(null)" onsubmit="commentsComponent.submitForm( this ); return false;">';commentReplyFormHtml+='<textarea cols="60" rows="6" name="comment[comment]"></textarea>';commentReplyFormHtml+="<br/>";commentReplyFormHtml+='<input type="hidden" name="comment[parent_id]" value="%parentId%" />';commentReplyFormHtml+='<input type="submit" value="Post comment" /> <a href="javascript:void(null)" onclick="commentsComponent.hideReplyForm();">Cancel</a>';commentReplyFormHtml+="</form>";var currentFormId;var invalidCommentAttributes=[];var commentsComponent={showForm:function(b){var a=$("#comment_form_"+b);a.html(commentFormHtml.replace("%commentableId%",b).replace("%commentableId%",b));a.show()},hideForm:function(b){var a=$("#comment_form_"+b);a.hide()},showReplyForm:function(a,c){commentsComponent.hideForm();var b=$("#comment_form_"+a);b.html(commentReplyFormHtml.replace("%parentId%",a));b.show();var c=$("#comment_link_"+a);c.hide();currentFormId=a},hideReplyForm:function(b){if(currentFormId){var a=$("#comment_form_"+currentFormId);a.html("");var b=$("#comment_link_"+currentFormId);b.show()}},submitForm:function(b){b=$(b);var c=$(b.find("input[type=submit]")[0]);c.attr("disabled",true);var a=commentPostData;a+=("&"+b.serialize());commentsComponent._resetInvalidAttributes();$.ajax({url:"/comments/create",type:"POST",data:a,dataType:"json",success:function(d){if(d.success){window.location.reload()}else{c.attr("disabled",false);invalidCommentAttributes=d.invalid_attrs;commentsComponent._highlighInvalidAttributes()}}})},_highlighInvalidAttributes:function(){jQuery.each(invalidCommentAttributes,function(b,a){$("#attr_"+a).addClass("error")})},_resetInvalidAttributes:function(){jQuery.each(invalidCommentAttributes,function(b,a){$("#attr_"+a).removeClass("error")})}};var tagComponent={add:function(){var a=tagPostData;jQuery.extend(a,{"tag[title]":$("input#tag").attr("value")});$("input#tag").attr("value","");$.ajax({url:"/tags/create",global:false,type:"POST",data:a,dataType:"json",success:function(b){tagComponent.showTags(b.tags)}})},remove:function(c,b){var a=tagPostData;jQuery.extend(a,{"tag[name]":b});$.ajax({url:"/tags/destroy",global:false,type:"POST",data:a,dataType:"json",success:function(d){tagComponent.showTags(d.tags)}})},showTags:function(a){var b="";if(a.length==0){b="Oops. No tags."}else{jQuery.each(a,function(d,e){var c="/tags/create".replace("dummy",d);b+='<a href="#" onclick="tagComponent.remove(this, \''+d+"');\">";b+='<img src="/assets/images/icons/delete.gif" alt="Remove tag" height="12" />';b+='</a> <a href="'+c+'">'+e+"</a> <br/>"})}$("div#tags").html(b)}};
