var Comments={init:function(){var a=$("findyoga-comments")||$("mb");if(!a){return}Comments.$el=a;Comments.$form=a.getElement("form");if(!a.hasClass("logged-in")){Comments.initLogin()}Comments.initReplies()},initLogin:function(e){if(!e){e=Comments.$form}if(!e){return}var b=e.getElement(".reply-toolbar");if(!b){return}var g=b.getElement(".reply-toolbar-logged-in"),d=b.getElement(".reply-toolbar-logged-out");var a=b.getElement(".fy.login"),h=b.getElement(".fb.login"),c=b.getElement(".fy.signup");a.addEvent("click",function(){Comments.$active=e;Comments.popup=new UI.Popup({action:"show popup",width:680,cssClass:"fy-popup signup-popup",fromSparkle:{path:"/Popups/Signup-Login",data:{show:"login",type:"profile",remote:true}},onRender:"Site.openedSignup",performOnRender:"Site.focusSignin"})});h.addEvent("click",function(){Site.showBlockout();Comments.$active=e;var i=(function(){g.show();d.hide();Comments.$form.retrieve("form").validateForm();Site.hideBlockout()});Facebook.login(Comments.loggedIn)});c.addEvent("click",function(){Comments.$active=e;Comments.popup=new UI.Popup({action:"show popup",width:680,cssClass:"fy-popup signup-popup",fromSparkle:{path:"/Popups/Comments/Signup",data:{show:"login",type:"profile",remote:true}},onRender:"Site.openedSignup",performOnRender:"Site.focusSignin"})});if(e.getElement(".reply-field")){var f=e.getElement(".reply-field").getElement("textarea");if(f){f.addEvent("click",function(){Comments.$active=e})}}},checkLogin:function(b){var d=b.html.clean(),a=(d.slice(0,4)=="fail"),c=(d.slice(0,7)=="success");if(a){$log("FY: Could not login to FindYoga using supplied details.");return}if(c){$log("FY: User successfully logged in.");Site.hideBlockout();Comments.loggedIn(true);return}},loggedIn:function(b){if(!b){alert("Sorry, we couldn't log you in.\n\nPlease contact us and let us know and we'll help you as soon as possible.");return}var a=Comments.$el.getElements(".reply-toolbar");a.each(function(c){var e=c.getElement(".reply-toolbar-logged-in"),d=c.getElement(".reply-toolbar-logged-out");e.setStyle("display","inline-block");d.hide()});if(Comments.popup){Comments.popup.close()}Site.switchHeader();Comments.$active.retrieve("form").validateForm()},initReplies:function(){var a=Comments.$el.getElements(".comment-container");if(!a){return}a.each(function(c){var d=c.getDataFromComment();if(!d){return}var b=c.getElement(".reply"),e=c.getElement(".reply-container");if(!b){return}b.addEvent("click",function(){b.hide();var f={path:"/Actions/Comments/Reply",data:{comment:d.comment}};UI.loadSparkle(f).then((function(h){e.set("html",h);var g=e.getElement("form");g.store("form",new UI.Form(g,{validationMode:"submit",hideHints:true,invalidFieldMessage:"Required",validFieldMessage:"Ok",focusField:"reply"}));var i=g.getElement(".cancel");i.addEvent("click",function(){b.show();e.empty()});Comments.initLogin(g)}.bind(this)))})})}};window.addEvent("domready",Comments.init);
