$(document).ready(function(){lightBox.setupLightboxEventHandlers();rollCall.setupRollcallEventHandlers();inviteFriends.setUpEventHandlersForInviteFriendsLightbox();lightBox.addClassToMakeHoverEffectsWorkOnNonTouchDevices()});var lightBox={setupLightboxEventHandlers:function(){$(".closeLightBoxButton").on("click",function(n){lightBox.hideLightBox();n.preventDefault()});$(window).resize(function(){lightBox.setHeightOfLightboxInRelationToWindowHeight();lightBox.verticallyCenterLightBox()});var n=27;$(document).keyup(function(t){t.keyCode==n&&($("#LightBox").hasClass("hidden")||lightBox.hideLightBox())})},hideLightBox:function(){$("#LightBox").addClass("hidden");$("#RollcallContent").addClass("hidden");$("#InviteFriendsContent").addClass("hidden");lightBox.toggleScrollingOfContentBehindLightbox()},addClassToMakeHoverEffectsWorkOnNonTouchDevices:function(){"ontouchstart"in document.documentElement||$("body").addClass("touch-unavailable")},toggleScrollingOfContentBehindLightbox:function(){var t=-(document.documentElement.scrollTop||document.body.scrollTop)+"px",n=parseInt($("body").css("top"));$("body").toggleClass("stop-scrolling");$("body").css({top:t});document.documentElement.scrollTop=-n;document.body.scrollTop=-n;lightBox.toggleBodyScrollingForTouchDevices()},toggleBodyScrollingForTouchDevices:function(){if($("#LightBox").css("display")=="block"){$("section").on("touchmove",function(n){n.stopPropagation()});$("body").on("touchmove",function(n){n.preventDefault()})}else $("section").off("touchmove"),$("body").off("touchmove")},setHeightOfLightboxInRelationToWindowHeight:function(){$(".lightbox").width()<=216?$(".lightbox-content").height($(window).height()-175):$(".lightbox-content").height($(window).height()-300)},verticallyCenterLightBox:function(){var t=120,n=-($("#RollcallContent section").height()+t)/2;$("#RollcallContent").css("margin-top",n+"px");n=-($("#InviteFriendsContent section").height()+t)/2;$("#InviteFriendsContent").css("margin-top",n+"px")},getEventIdFromQueryString:function(){var n=window.location.pathname;return n.substring(n.lastIndexOf("/")+1).replace("#","")},createProfileImageTag:function(n){var t=n.ProfileImage;return t||(t="default.jpg"),$("<img>").attr("src","/images/user/av/"+t)},hideFooterButton:function(n){lightBox.hideItem($(n+".but"))},hideItem:function(n){$(n).css({display:"none"})}},inviteFriends={setUpEventHandlersForInviteFriendsLightbox:function(){$("#ShowInviteFriendsLightbox").on("click",function(n){inviteFriends.displayInviteFriendsLightBox();n.preventDefault()});$("#InviteSelectedButton").on("click",function(n){inviteFriends.inviteSelectedUsers();n.preventDefault()})},displayInviteFriendsLightBox:function(){$("#LightBox").toggleClass("hidden");$("#InviteFriendsContent").toggleClass("hidden");lightBox.toggleScrollingOfContentBehindLightbox();$("#InviteFriendsContent").data("loaded")===!1&&(inviteFriends.populateFriendsAlreadyAttendingHeading(),inviteFriends.loadFriendsUserCanInvite());lightBox.setHeightOfLightboxInRelationToWindowHeight();lightBox.verticallyCenterLightBox()},populateFriendsAlreadyAttendingHeading:function(){var t=parseInt($("#FriendsFavouriteCount").text())||0,n;t==0?$("#FriendsAlreadyAttendingHeading").hide():(n=$("#FriendsAlreadyAttendingHeading").text(),n=t+" "+n,t==1&&n.replace("friends","friend"),$("#FriendsAlreadyAttendingHeading").text(n))},loadFriendsUserCanInvite:function(){var n=lightBox.getEventIdFromQueryString();inviteFriends.updateInformationLabel("Loading friends you can invite...");$.getJSON("/event-invite.aspx?event="+n+"&type=1").done(function(n){inviteFriends.userHasFriends(n)?inviteFriends.updateLightboxWithInvitableFriends(n):inviteFriends.showUserThereAreNoFriendsToInvite();$("#InviteFriendsContent").data("loaded",!0);inviteFriends.updateInformationLabel("")})},userHasFriends:function(n){return n.friends.length>0},showUserThereAreNoFriendsToInvite:function(){$("#InviteOtherFriendsHeading").text("None of your friends are available to be invited to this event");lightBox.hideFooterButton(".invite-friends")},updateLightboxWithInvitableFriends:function(n){inviteFriends.addUsersToDomOnCallback(n);inviteFriends.addMultipleSelectionFunctionalityBasedOnEventLocation(n);inviteFriends.resizeAndPositionLightbox();$("li.notAvailableToInvite").on("mouseover",function(){inviteFriends.updateInformationLabel("Already invited")});$("li.notAvailableToInvite").on("mouseleave",function(){inviteFriends.updateInformationLabel("")})},updateInformationLabel:function(n){var t=$("#Information");t.text(n);n===""?t.addClass("hidden"):t.removeClass("hidden")},addUsersToDomOnCallback:function(n){var t=$("#InviteOthersList");$(n.friends).each(function(n,i){inviteFriends.createListItemShowingMembersToInvite(i).appendTo(t)})},addMultipleSelectionFunctionalityBasedOnEventLocation:function(n){n.friends.length>10?$("#SelectFriendsInEventAreaDiv").html('<a href="" id="SelectFriendsInAreaButton">Select friends in '+n.areaname+"<\/a>"):$("#SelectFriendsInEventAreaDiv").hide();$("#SelectFriendsInAreaButton").on("click",function(t){$(".availableToInvite").each(function(t,i){$(i).data("areaid")==n.areaid&&$(i).addClass("selectedToInvite")});lightBox.hideItem($("#SelectFriendsInEventAreaDiv"));t.preventDefault()})},resizeAndPositionLightbox:function(){lightBox.setHeightOfLightboxInRelationToWindowHeight();lightBox.verticallyCenterLightBox();inviteFriends.addClickHandlersToInvitableUsers()},addClickHandlersToInvitableUsers:function(){$(".availableToInvite").on("click",function(n){$(this).toggleClass("selectedToInvite");n.preventDefault()})},createListItemShowingMembersToInvite:function(n){var t=$('<li data-userId="'+n.userid+'" data-areaId="'+n.areaid+'">');return n.invite=="0"?$(t).addClass("availableToInvite"):$(t).addClass("notAvailableToInvite"),lightBox.createProfileImageTag(n).appendTo(t),inviteFriends.createUserNameSpan(n).appendTo(t),t},createUserNameSpan:function(n){return $("<span>"+n.username+"<\/span>")},inviteSelectedUsers:function(){var n=$(".selectedToInvite");if(n.length===0){inviteFriends.updateInformationLabel("Please select some friends to invite");return}inviteFriends.updateInformationLabel("Sending invites...");inviteFriends.postSelectedUsersToWebservice(n)},postSelectedUsersToWebservice:function(n){$.ajax({type:"POST",url:"/event-invite.aspx",data:{type:"2",event:lightBox.getEventIdFromQueryString(),invites:inviteFriends.createCsvStringOfUserIdsToInvite(n)},dataType:"json"}).success(function(){$(n).removeClass("selectedToInvite");$(n).removeClass("availableToInvite");$(n).addClass("notAvailableToInvite");inviteFriends.updateInformationLabel("Invites sent")}).fail(function(){inviteFriends.updateInformationLabel("Failed to send invites to users")})},createCsvStringOfUserIdsToInvite:function(n){var i=$(n).length,t="";return $(n).each(function(n,r){t+=$(r).data("userid");n<i-1&&(t+=",")}),t}},rollCall={setupRollcallEventHandlers:function(){$("#ShowRollCallLightbox").on("click",function(n){$("#LightBox").toggleClass("hidden");$("#RollcallContent").toggleClass("hidden");$("#RollcallContent").data("initial-load-complete")||rollCall.loadDataFirstTimeRollcallIsOpened();lightBox.toggleScrollingOfContentBehindLightbox();lightBox.setHeightOfLightboxInRelationToWindowHeight();lightBox.verticallyCenterLightBox();n.preventDefault()});$("#LoadMoreButton").on("click",function(n){rollCall.loadBatchOfNonFriends();n.preventDefault()})},loadDataFirstTimeRollcallIsOpened:function(){$("#LoadMoreButton").text("Loading...");rollCall.populateHeadersWithNumericValues();rollCall.loadFriends();rollCall.loadBatchOfNonFriends(!0);$("#RollcallContent").data("initial-load-complete","true");$("section#Rollcall").scrollTop(0)},populateHeadersWithNumericValues:function(){var i=$("#FriendsFavouriteCount").text().replace(",",""),r=$("#MembersFavouriteCount").text().replace(",",""),n=parseInt(i)||0,t=parseInt(r)-n||0;$("#MembersAttendingCount").text(n+t);rollCall.populateFriendsAttendingCountLabel(n);$("#NonFriendsAttendingCount").text(t+" "+$("#NonFriendsAttendingCount").text())},populateFriendsAttendingCountLabel:function(n){if(n==0){$("#FriendsAttendingCount").hide();return}if(n==1){var t=$("#FriendsAttendingCount").text().replace("friends","friend");$("#FriendsAttendingCount").text(t)}$("#FriendsAttendingCount").text(n+" "+$("#FriendsAttendingCount").text())},hideLoadMoreButtonIfNoMoreNonFriendsToLoad:function(){var n=rollCall.getNumberOfNonFriendsCurrentlyDisplayedOnThePage(),t=rollCall.getTotalNumberOfMembersAttending();n>=t&&lightBox.hideFooterButton(".rollcall")},getNumberOfNonFriendsCurrentlyDisplayedOnThePage:function(){return parseInt($("section#Rollcall").data("non-friends-displayed-so-far"))},getTotalNumberOfMembersAttending:function(){return parseInt($("#MembersAttendingCount").text())},loadFriends:function(){var n=$("#FriendsAttending"),t=lightBox.getEventIdFromQueryString();$("#LoadMoreButton").text("Loading...");$.getJSON("/WebServices/Rollcall.ashx?friends=true&eventId="+t).done(function(t){rollCall.addUsersToDomOnCallback(t,n)})},loadBatchOfNonFriends:function(n){var t=128,r=$("#NonFriendsAttending"),u=lightBox.getEventIdFromQueryString(),i=rollCall.getNumberOfNonFriendsCurrentlyDisplayedOnThePage();$("#LoadMoreButton").text("Loading...");$.getJSON("/WebServices/Rollcall.ashx?friends=false&eventId="+u+"&startRowNo="+i+"&pageSize="+t).done(function(t){rollCall.addUsersToDomOnCallback(t,r);$("#LoadMoreButton").text("Load more");n||rollCall.scrollToBottomOfMembersList();rollCall.hideLoadMoreButtonIfNoMoreNonFriendsToLoad()});$("section#Rollcall").data("non-friends-displayed-so-far",i+t)},addUsersToDomOnCallback:function(n,t){$(n).each(function(n,i){rollCall.createListItemShowingAttendingMember(i).appendTo(t)});lightBox.setHeightOfLightboxInRelationToWindowHeight();lightBox.verticallyCenterLightBox()},createListItemShowingAttendingMember:function(n){var t=$("<li>");return lightBox.createProfileImageTag(n).appendTo(t),rollCall.createUserNameHyperlink(n).appendTo(t),t},scrollToBottomOfMembersList:function(){var n=$("#NonFriendsAttending").height();$("section#Rollcall").scrollTop(n)},createUserNameHyperlink:function(n){return $("<a>").attr("href","/profile/"+n.Username.toLowerCase()).text(n.Username)}}