/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.4.2
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2018 vBulletin Solutions Inc. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/
window.vBulletin=window.vBulletin||{};window.vBulletin.phrase=window.vBulletin.phrase||{};window.vBulletin.phrase.precache=window.vBulletin.phrase.precache||[];window.vBulletin.phrase.precache=$.merge(window.vBulletin.phrase.precache,["saving"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["postminchars","commentminchars"]);var galleryData={mediaTypeFilter:false,currentMediaPage:Number($("#mediaCurrentPage").val())||1,currentGalleryPage:1,currentNodeId:0,currentUserId:0,profileMediaDetailContainer:false,currentDateFilter:"time_lastmonth"};var $mediaTab=$("#media-tab"),allowHistory,filterHistory,hash;window.vBulletin.media=window.vBulletin.media||{};(function(A){var B=["#media-tab"];if(!vBulletin.pageHasSelectors(B)){return false}window.vBulletin.media.calculatePhotosPerPage=function(D){D=D||50;var C=A("#profileMediaDetailContainer").is(":visible");if(!C){A("#profileMediaDetailContainer").removeClass("h-hide")}var E=Math.floor(A("#profileMediaDetailContainer").width()/128);if(!C){A("#profileMediaDetailContainer").addClass("h-hide")}return(D%E==0||D<=E)?D:D-(D%E)};A(document).ready(function(){A(document).off("click","#mediaList .albumLink").on("click","#mediaList .albumLink",loadGallery);var C=false;$mediaTab.off("click",".profile-media-createvideo, .profile-media-upload").on("click",".profile-media-createvideo, .profile-media-upload",function(F){var E=A(this).hasClass("profile-media-upload")?"gallery":"video";if(!C){C=A(F.target).closest(".ui-widget-content").find(".profileMediaEditContainer").dialog({modal:true,autoOpen:false,width:800,title:vBulletin.phrase.get("profile_media"),resizable:false,closeOnEscape:false,showCloseButton:false,dialogClass:"dialog-container dialog-box edit-media-upload-dialog js-profile-media",close:function(){A(document).data("gallery-container",null)}});vBulletin.ckeditor.initEditor(C.find(".js-ckeditor-init-on-focus"));vBulletin.upload.initializePhotoUpload(C)}C.off("dialogopen").on("dialogopen",function(G,H){C.find('.b-toolbar__item[data-panel="b-content-entry-panel__content--{0}"]:not(.b-toolbar__item--active)'.format(E)).trigger("click");vBulletin.ckeditor.initEditorComponents(C);A(document).data("gallery-container",A(this).find(".b-content-entry-panel__content--"+E))}).dialog("open")});$mediaTab.off("click","#profileMediaDetailContainer .more-gallery").on("click","#profileMediaDetailContainer .more-gallery",getMorePhotos);$mediaTab.off("click",".profile-media-backbtn").on("click",".profile-media-backbtn",function(F){A("#profileMediaDetailContainer").addClass("h-hide");A("#mediaPreviousPage").closest(".pagenav-controls-container").removeClass("h-hide");A("#profileMediaContainer").removeClass("h-hide");A(".media-tab .profile-toolbar .toolset-left > li").addClass("h-hide").has(".profile-media-upload, .profile-media-createvideo").removeClass("h-hide");galleryData.currentDateFilter=A(this).closest(".conversation-toolbar-wrapper").find(".toolbar-filter-overlay input[name=filter_time]:checked").val();A(".profile-toolbar .media-toolbar-filter").addClass("h-hide");A(this).closest(".conversation-toolbar-wrapper").find(".filtered-by").addClass("h-hide").find(".filter-text-wrapper").empty();var E={totalpages:Number(A("#mediaList").data("totalpages")),totalcount:Number(A("#mediaList").data("totalcount")),currentpage:galleryData.currentMediaPage};setPagination(E)});$mediaTab.off("change","#mediaCurrentPage").on("change","#mediaCurrentPage",goMediaPage);$mediaTab.off("click","#mediaPreviousPage, #mediaNextPage").on("click","#mediaPreviousPage, #mediaNextPage",goMediaPage);galleryData.profileMediaDetailContainer=A("#profileMediaDetailContainer").clone();var D=".js-album-detail .js-post__content-wrapper .js-content-entry form";A(document).off("afterSave",D).on("afterSave",D,function(F,E){loadGalleryById(galleryData.currentFilter);return false});A(document).off("afterCancel",D).on("afterCancel",D,function(E){A(E.currentTarget).closest(".js-album-detail").find(".conversation-body, .profile-media-uploadphotos, .photo-preview").removeClass("h-hide-imp");return true});A(document).off("afterSave",".js-profile-media .js-content-entry form").on("afterSave",".js-profile-media  .js-content-entry form",function(H,G){var J=A(".b-toolbar__item--active",this).data("panel");if(J=="b-content-entry-panel__content--gallery"){var E=A("#mediaList"),I=Number(E.data("totalpages")),K=Number(E.data("totalcount")),F=(K%vBulletin.media.ALBUMS_PERPAGE)==0?I+1:I;if(G.alert){openAlertDialog({title:vBulletin.phrase.get("media"),message:vBulletin.phrase.get(G.alert),iconType:"alert"})}loadMediaPage(F)}else{loadMediaPage(1)}return false});if($mediaTab.length){allowHistory=$mediaTab.find(".conversation-toolbar-wrapper").data("allow-history")=="1";filterHistory=new vBulletin.history.instance(allowHistory);hash=$mediaTab.closest(".canvas-widget").find(".js-module-top-anchor").attr("id");$mediaTab.off("click",".media-toolbar-filter").on("click",".media-toolbar-filter",function(E){A(".filter-wrapper",this).toggleClass("selected");A(".arrow .vb-icon",this).toggleClass("vb-icon-triangle-down-wide vb-icon-triangle-up-wide");A(E.target).closest(".conversation-toolbar-wrapper").find(".toolbar-filter-overlay").slideToggle("slow",function(){var F="media_filter";if(A(this).is(":visible")){A("body").off("click."+F).on("click."+F,function(I){if(A(I.target).closest(".toolbar-filter-overlay").length==0&&A(I.target).closest(".toolbar-filter").length==0){A("body").off("click."+F);A(".media-toolbar-filter").trigger("click")}});var H={};var G=vBulletin.isScrolledIntoView(this,H);if(!G){A("html,body").animate({scrollTop:"+="+Math.abs(H.bottom)},"fast")}}else{A("body").off("click."+F)}})});A("form.media-filter-overlay",$mediaTab).trigger("reset");$mediaTab.off("change",".media-filter-overlay input[type=radio]").on("change",".media-filter-overlay input[type=radio]",function(L,J){var F;if(!filterHistory.isEnabled()&&allowHistory){F=vBulletin.makePaginatedUrl(location.href,1);location.href=vBulletin.makeFilterUrl(F,this.name,this.value,I,hash);return true}galleryData.currentDateFilter=this.value;var G=fetchMediaFilter(A(L.target));var I=A(".media-tab");if(I.data("perpage")){G.perpage=I.data("perpage")}loadGalleryById(G,true,0,I.data("callbacks"));if(!A(this).data("bypass-filter-display")){vBulletin.conversation.displaySelectedFilterText(this,this.value)}if(filterHistory.isEnabled()&&!J){var K=vBulletin.getSelectedFilters(A("form.toolbar-filter-overlay",I)),O=this.name,E=this.value,N=A(".conversation-toolbar-wrapper .filtered-by",I),H=I.data("url-path")?I.data("url-path"):"#"+I.attr("id"),M={from:"filter",page:1,tab:H,filters:K,filtervalue:E,filtername:O};if(!N.data("reset")){F=vBulletin.makePaginatedUrl(location.href,1);F=vBulletin.makeFilterUrl(F,O,E,I)}else{F=location.pathname.replace(/\/page[0-9]+/,"")}filterHistory.pushState(M,document.title,F);N.data("reset",null)}});$mediaTab.off("click",".filtered-by .x").on("click",".filtered-by .x",function(G){var E=A(this).closest(".filtered-by"),I=A(this).closest(".filter-text"),F=I.data("filter-name");if(!filterHistory.isEnabled()&&allowHistory){location.href=vBulletin.makeFilterUrl(location.href,F,I.data("filter-value"),$mediaTab,hash);return false}$defaultSelectedFilter=A(".toolbar-filter-overlay .filter-options input[name={0}]".format(F),$mediaTab).prop("checked",false).filter(".js-default-checked");I.remove();var H=E.find(".filter-text").length;if(H==0){E.addClass("h-hide");E.data("reset",true)}else{if(H==1){E.find(".clear-all").addClass("h-hide")}}if($defaultSelectedFilter.length==1){$defaultSelectedFilter.data("bypass-filter-display",true);$defaultSelectedFilter.trigger("click");$defaultSelectedFilter.data("bypass-filter-display",null)}})}})})(jQuery);doMediaFilters=function(A){$(".profMediaFilterRow").removeClass("filterSelected");$(A.target).addClass("filterSelected");if($(A.target).hasClass("profMediaFilterAllTypes")){galleryData.mediaTypeFilter=false}else{if($(A.target).hasClass("profMediaFilterGallery")){galleryData.mediaTypeFilter="gallery"}else{if($(A.target).hasClass("profMediaFilterVideo")){galleryData.mediaTypeFilter="video"}}}loadMediaPage(1)};loadMediaPage=function(A){$("body").css("cursor","wait");var B=$(".js-profile-media-container",$mediaTab);$.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/render/profile_media_content",data:({userid:B.data("user-id"),pageno:A,perpage:B.data("perpage")}),type:"POST",dataType:"json",success:function(C){if(C.errors){openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get(C.errors[0][0]),iconType:"error"});console.log("/ajax/render/profile_media_content failed, error: "+JSON.stringify(C))}else{console.log("/ajax/render/profile_media_content successful");$("#mediacontent").html(C);$("#profileMediaDetailContainer").empty();$("#mediacontent").removeClass("h-hide");$("#profileMediaContainer").removeClass("h-hide");$(".media-tab .profile-toolbar .toolset-left > li").addClass("h-hide").has(".profile-media-upload, .profile-media-createvideo").removeClass("h-hide");$("#mediaPreviousPage").closest("pagenav-controls").removeClass("h-hide");$("#profileMediaDetailContainer").addClass("h-hide");$("#profileMediaContainer").removeClass("h-hide");galleryData.currentMediaPage=A;var D={totalpages:Number($("#mediaList").data("totalpages")),totalcount:Number($("#mediaList").data("totalcount")),currentpage:A};setPagination(D);if(!vBulletin.isScrolledIntoView($("#profileTabs .profile-tabs-nav"))){$("html,body").animate({scrollTop:$("#profileTabs .profile-tabs-nav").offset().top},"slow")}}},error:function(E,D,C){console.log("/ajax/render/profile_media_content failed, error: "+C);console.log("response:"+E.responseText);console.log("status:"+D);console.log("code:"+E.status);openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get("unable_to_contact_server_please_try_again"),iconType:"error"})},complete:function(){$("body").css("cursor","auto")}})};goMediaPage=function(C){var B=this.id;if($("#profileMediaDetailContainer").is(":visible")){gotoGalleryPage(C);return false}if(B=="mediaCurrentPage"){var D=parseInt($("#mediaCurrentPage").val());if(D>0&&D<=parseInt($("#mediaPageCount").html())){loadMediaPage(D);pushHistoryState(D)}else{$("#mediaCurrentPage").val(galleryData.currentMediaPage)}}else{if(B=="mediaPreviousPage"){if(galleryData.currentMediaPage>1){var A=galleryData.currentMediaPage-1;loadMediaPage(A);pushHistoryState(A)}else{$("#mediaPreviousPage").addClass("h-disabled")}}else{if(B=="mediaNextPage"){if(galleryData.currentMediaPage<parseInt($("#mediaPageCount").html())){var A=galleryData.currentMediaPage+1;loadMediaPage(A);pushHistoryState(A)}else{$("#mediaNextPage").addClass("h-disabled")}}}}return false};var pushHistoryState=function(A){var C=vBulletin.makePaginatedUrl(location.href,A);if(filterHistory.isEnabled()){var B={from:"media_filter",page:A||1,tab:$mediaTab.data("url-path")?$mediaTab.data("url-path"):"#"+$mediaTab.attr("id")};filterHistory.pushState(B,document.title,C)}else{if(allowHistory){location.href=C}}};vBulletin.media.setHistoryStateChange=function(A){if(A){allowHistory=$mediaTab.find(".conversation-toolbar-wrapper").data("allow-history")=="1";filterHistory=new vBulletin.history.instance(allowHistory)}if(filterHistory.isEnabled()){filterHistory.setStateChange(function(F){var E=filterHistory.getState();if(E.data.from=="media_filter"){filterHistory.log(E.data,E.title,E.url);var B=$mediaTab.closest(".ui-tabs"),C=B.find(".ui-tabs-nav > li").filter('li:has(a[href*="#{0}"])'.format($mediaTab.attr("id")));if(C.hasClass("ui-tabs-active")){loadMediaPage(E.data.page)}else{var D=C.index();vBulletin.selectTabByIndex.call(B,D)}}},"media_filter")}};gotoGalleryPage=function(C){if(!galleryData.currentNodeId&&!galleryData.currentUserId){return false}var A=C.target.id;if(A=="mediaCurrentPage"){targetPage=parseInt($("#mediaCurrentPage").val());if(targetPage>0&&targetPage<=parseInt($("#mediaPageCount").html())){var B={nodeid:galleryData.currentNodeId,userid:galleryData.currentUserId,pageno:targetPage,perpage:vBulletin.media.calculatePhotosPerPage(vBulletin.media.TARGET_PHOTOS_PERPAGE),datefilter:galleryData.currentDateFilter};loadGalleryById(B)}else{$("#mediaCurrentPage").val(galleryData.currentGalleryPage)}}else{if(A=="mediaPreviousPage"){if(galleryData.currentGalleryPage>1){var B={nodeid:galleryData.currentNodeId,userid:galleryData.currentUserId,pageno:galleryData.currentGalleryPage-1,perpage:vBulletin.media.calculatePhotosPerPage(vBulletin.media.TARGET_PHOTOS_PERPAGE),datefilter:galleryData.currentDateFilter};loadGalleryById(B)}else{$("#mediaPreviousPage ").addClass("h-disabled")}}else{if(A=="mediaNextPage"){if(galleryData.currentGalleryPage<parseInt($("#mediaPageCount").html())){var B={nodeid:galleryData.currentNodeId,userid:galleryData.currentUserId,pageno:galleryData.currentGalleryPage+1,perpage:vBulletin.media.calculatePhotosPerPage(vBulletin.media.TARGET_PHOTOS_PERPAGE),datefilter:galleryData.currentDateFilter};loadGalleryById(B)}else{$("#mediaNextPage").addClass("h-disabled")}}}}return false};setPagination=function(A){var B=$(".media-tab .pagenav-controls-container")[(A.totalpages>1)?"removeClass":"addClass"]("h-hide");if(B.is(":visible")){$("#mediaPreviousPage")[(A.currentpage<=1)?"addClass":"removeClass"]("h-disabled");$("#mediaNextPage")[(A.currentpage>=A.totalpages)?"addClass":"removeClass"]("h-disabled");$("#mediaCurrentPage").val(A.currentpage);$("#mediaPageCount").text(A.totalpages)}};loadGalleryById=function(B,E,F,H){var C=$("#profileMediaDetailContainer"),D={nodeid:galleryData.currentNodeId,userid:galleryData.currentUserId,channelid:0,pageno:1,dateFilter:galleryData.currentDateFilter,albumid:0};B=$.extend({},D,B);if(!isNaN(B.nodeid)){$("body").css("cursor","wait");var I;if(B.nodeid==-1){I="profile_media_videolist"}else{I="profile_textphotodetail"}if(C.closest(".media-tab").length==0){$(".media-tab").append(galleryData.profileMediaDetailContainer)}$("#profileMediaContainer").closest(".tab").find("li.list-item-gallery").remove();var A=vBulletin.getAjaxBaseurl()+"/ajax/render/"+I;var G={nodeid:B.nodeid,userid:B.userid,channelid:B.channelid,pageno:B.pageno,albumid:B.albumid,viewMore:F};if(B.dateFilter){G.dateFilter=B.dateFilter}if(B.perpage){G.perpage=B.perpage}$.ajax({url:A,type:"POST",data:G,dataType:"json",success:function(J){if(J.errors){openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get(J.errors[0][0]),iconType:"error"});if(H&&typeof H.error=="function"){H.error()}}else{galleryData.currentNodeId=B.nodeid;galleryData.currentUserId=B.userid;galleryData.currentGalleryPage=B.pageno;if(F){$(".album-detail .photo-preview").append(J);$(".more-gallery",C)[(galleryData.currentGalleryPage<$(".album-detail").data("totalpages"))?"removeClass":"addClass"]("h-hide-imp")}else{C.html(J);C.addClass("list-item").attr("data-nodeid",B.nodeid);$("#profileMediaContainer").addClass("h-hide");$(".media-tab .profile-toolbar .toolset-left > li").removeClass("h-hide").has(".profile-media-upload, .profile-media-createvideo").addClass("h-hide");C.removeClass("h-hide");$("#mediaPreviousPage").closest(".pagenav-controls-container").addClass("h-hide");$(".profile-media-uploadphotos",C).click(loadPhotoUploader);if(B.perpage){$(".media-tab").data("perpage",B.perpage).data("callbacks",H)}}}if(B.nodeid==-1){var K={totalpages:Number($(".media-video-list",C).data("totalpages")),totalcount:Number($(".media-video-list",C).data("totalcount")),currentpage:galleryData.currentGalleryPage};setPagination(K)}if(!E){}$(".profile-toolbar .media-toolbar-filter").removeClass("h-hide");if(H&&typeof H.success=="function"){H.success()}},error:function(L,K,J){console.log("/ajax/render/{0} failed, error: {1}".format(I,J));openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get("unable_to_contact_server_please_try_again"),iconType:"error"});if(H&&typeof H.error=="function"){H.error()}},complete:function(){$("body").css("cursor","auto");if(H&&typeof H.complete=="function"){H.complete()}}})}};loadPhotoUploader=function(C){$(document).data("gallery-container",$(this).closest(".album-detail"));var A=vBulletin.upload.getUploadedPhotosDlg(false);var B=A.data("nodeid");if(!B||isNaN(parseInt(B))){return }$.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/render/media_addphotos",data:{nodeid:B},type:"POST",dataType:"json",success:function(D){if(D.errors){openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get(D.errors[0][0]),iconType:"warning",onAfterClose:function(){A.dialog("close")}})}else{A.html(D);vBulletin.upload.initializePhotoUpload(A.parent());A.find(".js-save-button").off("click").on("click",saveGalleryPhotos);A.find(".js-cancel-button").off("click").on("click",function(E){A.dialog("close")});vBulletin.upload.relocateLastInRowClass(A.find(".photo-item-wrapper"));if($(".photo-display .photo-item-wrapper:not(.h-hide)",A).length>0){vBulletin.upload.changeButtonText($(".b-button--upload .js-upload-label",A),vBulletin.phrase.get("upload_more"));$(".js-save-button",A).show()}else{$(".js-save-button",A).hide()}A.dialog("open");vBulletin.upload.adjustPhotoDialogForScrollbar(A)}},error:function(F,E,D){console.log("/ajax/render/media_addphotos failed, error: "+D);openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get("unable_to_contact_server_please_try_again"),iconType:"error",onAfterClose:function(){A.dialog("close")}})}})};loadGallery=function(B){var A=fetchMediaFilter($(this));A.pageno=1;A.perpage=vBulletin.media.calculatePhotosPerPage(vBulletin.media.TARGET_PHOTOS_PERPAGE);galleryData.currentDateFilter=$(this).closest(".js-profile-media-container").find(".toolbar-filter-overlay input[name=filter_time]:checked").val();galleryData.currentFilter=A;loadGalleryById(A)};getMorePhotos=function(D){var C=$(".media-tab").data("perpage");var B=$(".media-tab").data("callbacks");var A=fetchMediaFilter($(this));A.pageno=galleryData.currentGalleryPage+1;if(C){A.perpage=C}loadGalleryById(A,false,1,B)};saveGalleryPhotos=function(D){var C=$(D.target).closest(".profile-media-photoupload-dialog"),A=$(D.target).closest("form");if(A.length>0){$(D.target).closest(".photo-display-container").find(".photo-item-wrapper:not(.h-hide)").each(function(E,G){var F=parseInt($(G).find(".filedataid").val());if(!isNaN(F)){A.append('<input type="hidden" name="filedataid[]" value="'+F+'"/>');$('<input type="hidden" name="title_'+F+'" />').val($(G).find("textarea").val()).appendTo(A)}});var B=$("button",A).prop("disabled",true);$.ajax({url:A.attr("action"),data:A.serializeArray(),type:"POST",success:function(E){if(E.errors){if(typeof (E.errors[0])=="undefined"){openAlertDialog({title:vBulletin.phrase.get("media"),message:vBulletin.phrase.get(E.errors),iconType:"error"})}else{openAlertDialog({title:vBulletin.phrase.get("media"),message:vBulletin.phrase.get(E.errors[0]),iconType:"error"})}}else{C.dialog("close");loadMediaPage(galleryData.currentMediaPage)}},error:function(G,F,E){console.log(A.attr("action")+" failed, error: "+E);openAlertDialog({title:vBulletin.phrase.get("profile_media"),message:vBulletin.phrase.get("invalid_server_response_please_try_again"),iconType:"error"})},complete:function(){B.prop("disabled",false)}})}else{C.dialog("close")}};fetchMediaFilter=function(A){var C;if($("#profileMediaContainer").is(":visible")){C=$("#profileMediaContainer")}else{if($("#profileMediaDetailContainer").is(":visible")){C=$("#profileMediaDetailContainer")}}var B={nodeid:parseInt(A.data("nodeid"),10)||parseInt(C.attr("data-nodeid"),10),userid:parseInt(C.data("userid"),10),channelid:parseInt(C.data("channelid"),10),dateFilter:galleryData.currentDateFilter,albumid:parseInt(A.data("albumid"),10)};if(isNaN(B.channelid)){B.channelid=0}if(isNaN(B.nodeid)){B.nodeid=0}if(B.nodeid>0){B.userid=0}else{if(isNaN(B.userid)){B.userid=0}}if(isNaN(B.albumid)){B.albumid=0}return B};