/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.1.9 Patch Level 4
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2016 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,["cancel","changed_extra_css_warning","error_loading_css","error_setting_theme","loading_themes","no_preview_available","revert","revert_extra_css_warning","save_and_continue","success","there_are_no_themes_installed","confirm_action"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["styleid"]);(function(L){var J=false,K,U,S=0,Y=function(h){var g=this;vBulletin.assertUserHasAdminPermission("canusesitebuilder",g,function(){E.call(g)});return false},E=function(g,l){var k=L(this),j=L(document.body),i=!k.hasClass("selected"),h=true;if(typeof g!="undefined"){i=!!g}if(typeof l!="undefined"){h=!!l}b(!i,k);if(i){F();D();L(".js-style-panel").css("display","none").removeClass("h-hide").slideDown("400",A)}else{L(".js-style-panel").slideUp("fast",function(){if(!h){return }var m=window.location.href;if(m.indexOf("adminAction=stylePanel&")!=-1){m=m.replace("adminAction=stylePanel&","")}else{m=m.replace("?adminAction=stylePanel","")}if(m!=window.location.href){window.location.href=m}else{window.location.reload(true)}})}},B=function(g){E(false,g)},b=function(g,i){var h=function(j){this.blur();j.stopPropagation();return false};if(g){L("#main-navbar .main-nav a, #main-navbar .secondary-nav .sb-menu a").removeClass("selected").closest("li").removeClass("h-disabled");L("#main-navbar .secondary-nav li").removeClass("h-disabled");i.removeClass("selected").closest("li").removeClass("h-disabled");L(document).off("focus click mousedown","#main-navbar .h-disabled a",h)}else{L("#main-navbar .main-nav a, #main-navbar .secondary-nav .sb-menu a").removeClass("selected").closest("li").addClass("h-disabled");L("#main-navbar .secondary-nav li").addClass("h-disabled");i.addClass("selected").closest("li").removeClass("h-disabled");L(document).on("focus click mousedown","#main-navbar .h-disabled a",h)}},D=function(){},a=function(h,i){var g=L(".js-theme-selector__list:visible .js-theme-selector__theme-radio:checked").val();vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/style/setDefaultStyle",data:{styleid:g},error_phrase:"error_setting_theme",success:function(){var j=new Date();j.setDate(j.getDate()+365);L.cookie(pageData.cookie_prefix+"userstyleid",g,{path:pageData.cookie_path,domain:pageData.cookie_domain,expires:j});if(typeof i=="undefined"||i){B(true)}}});return false},T=function(g){B(false);return false},e=function(g){c(K.getValue(),null,S)},I=function(g){openConfirmDialog({title:vBulletin.phrase.get("revert"),message:vBulletin.phrase.get("revert_extra_css_warning"),iconType:"warning",onClickYes:function(h){U="";K.setValue("");c("",V,S)}});return false},P=function(g){B(true);return false},N=function(g){K.setValue(U)},C=function(k,g,l){if(!g&&k&&k.target){var g=L(k.target).closest(".js-theme-selector__theme").data("preview-url")}if(!l){var l=L(k.target).closest(".js-theme-selector__list")}var j=l.closest(".js-panel").find(".js-theme-selector__theme-preview"),i,h=j.find("> img, > p");if(j.length!=1){return }if(g){i=L("<img />").prop("src",g)}else{i=L("<p />").addClass("b-theme-selector__theme-preview-message").text(vBulletin.phrase.get("no_preview_available"))}if(h.is("p")&&i.is("p")){h.fadeTo(200,"0.5",function(){L(this).fadeTo(400,1)})}else{h.css("zIndex","2");i.css("zIndex","1").hide();j.append(i);h.fadeOut({duration:300,queue:false,complete:function(){L(this).remove()}});i.fadeIn({duration:600,queue:false})}},d=function(){var g=L(this);g.closest(".js-theme-selector__list").find(".js-theme-selector__theme").removeClass("b-theme-selector__theme--selected js-theme-selector__theme--selected");g.closest(".js-theme-selector__theme").addClass("b-theme-selector__theme--selected js-theme-selector__theme--selected")},Z=function(q,l,h){var k=this,j="js-theme-selector__theme b-theme-selector__theme h-margin-right-xl",m=L('<input type="radio" name="styleid" value="'+k.styleid+'" />').addClass("js-theme-selector__theme-radio b-theme-selector__theme-radio h-margin-none h-margin-right-s"),o=L("<label />").prop("title",k.title),n=L("<div />").addClass("h-margin-s h-margin-bottom-none b-theme-selector__theme-title").text(k.title.length>30?k.title.substr(0,20)+" ...":k.title),g=L("<img />").addClass("h-margin-s h-margin-bottom-m").prop("src",k.iconurl),i=L("<div />").addClass("b-theme-selector__theme-thumbnail");var p=function(r){var s=new Image();s.src=r};p(k.iconurl);p(k.previewurl);if(l==k.styleid){m.prop("checked","checked");m.attr("checked","checked");C({},k.previewurl,q);j+=" js-theme-selector__theme--selected b-theme-selector__theme--selected"}i.append(g);n.prepend(m);o.append(i).append(n);L("<div />").addClass(j).data("preview-url",(k.previewurl||"")).append(o).appendTo(q);f.call(g.get(0),2)},f=function(q){var k=L(this);k.css({maxWidth:"none",maxHeight:"none"});var j=k.outerWidth()||0,r=k.outerHeight()||0,g=j>r?"height":"width",s,m,h,n=false;if(j>0&&r>0){var p=false;if(g=="width"&&j>100){s=100/j;m=j*s;h=r*s;p=true}else{if(g=="height"&&r>100){s=100/r;m=j*s;h=r*s;p=true}else{}}if(p){k.removeClass("h-margin-s h-margin-bottom-m").css({maxWidth:m,maxHeight:h});var l=k.parent();var o=L("<div />").addClass("b-theme-selector__image-resize-wrapper h-margin-s h-margin-bottom-m").css({width:100,height:100,overflow:"hidden"});o.append(k);l.append(o);n=true}}else{}if(!n){k.css({maxWidth:"100px",maxHeight:"100px"});if(q>0){var i=this;window.setTimeout(function(){f.call(i,--q)},100)}else{var i=this;k.off("load").on("load",function(){f.call(i,--q)})}}},H=function(h,l){var j,k=0,g=vBulletin.options.get("styleid");l.html("");if(h&&h.themes){L.each(h.themes,function(){Z.apply(this,[l,g,k]);++k})}if(!k){L("<div />").addClass("b-theme-selector__message").text(vBulletin.phrase.get("there_are_no_themes_installed")).appendTo(l)}else{Q(l,k)}},Q=function(g,j){var h=g.find(".js-theme-selector__theme").first().outerWidth(true),i=h*j;g.width(i);g.closest(".js-theme-selector__container").tinyscrollbar({sizethumb:14,axis:"x"});G(g)},G=function(l){var h=l.find(".js-theme-selector__theme--selected");if(h.length==1){var n=l.find(".js-theme-selector__theme"),o=n.first().outerWidth(true),g=n.length,m=parseInt(h.position().left,10),q=o*g,k=l.position().left,t=Math.round(k)*-1,r=l.closest(".js-theme-selector__container"),p=r.innerWidth(),j=p+t-o,i=0;if(m<t){i=m-t}else{if(j<m){i=m-j}}if(i!=0){var s=t+i;r.tinyscrollbar_update(s)}}},M=function(j,k,h){var i=L(this).closest(".js-theme-selector__theme"),g=i.find(".js-theme-selector__theme-radio");if(i.is(".js-theme-selector__theme--selected")){return }g.attr("checked","checked");d.call(this);C.call(this,j);G(k);if(h.liveUpdate){a.call(this,j,false)}},W=function(h){var g={liveUpdate:false,container:document};h=L.extend({},g,h);var j=L(".js-theme-selector__list",h.containerSelector);function i(k){M.call(this,k,j,h)}j.off("change",".js-theme-selector__theme-radio").on("change",".js-theme-selector__theme-radio",i);j.off("click",".js-theme-selector__theme label img").on("click",".js-theme-selector__theme label img",i);vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/style/getThemeInfo",error:function(){vBulletin.makeErrorAlertCallback("error","error_fetching_themes")();var k=L("<div />").addClass("b-theme-selector__message").text(vBulletin.phrase.get("error_fetching_themes"));j.html(k)},success:function(k){H.apply(this,[k,j])}})},R=function(g){if(isNaN(parseFloat(L(g.target).val()))){return false}currentText=K.getValue();if(U!=K.getValue()){X()}else{V()}},V=function(){$select=L(".js-style-panel #admin-stylepanel-csseditor .js_stylepanel_selectStyle");L.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/api/template/fetchBulk",type:"POST",dataType:"json",data:{template_names:{0:"css_additional.css"},styleid:$select.val(),type:"uncompiled"},success:function(g){if(g!=null){console.log(g);if(g&&!g.errors){if(typeof (g["css_additional.css"])=="undefined"){U=""}else{U=g["css_additional.css"]}K.setValue(U)}else{if(L.isArray(g.errors)&&g.errors.length>0){K.setValue("")}}}S=$select.val()},error:function(){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("error_loading_css"),iconType:"error"})}})},X=function(){openConfirmDialog({title:vBulletin.phrase.get("confirm_action"),message:vBulletin.phrase.get("changed_extra_css_warning"),iconType:"warning",buttonLabel:{yesLabel:vBulletin.phrase.get("save_and_continue"),noLabel:vBulletin.phrase.get("cancel")},onClickYes:function(g){c(K.getValue(),V,S)},onClickNo:function(g){L(".js-style-panel #admin-stylepanel-csseditor .js_stylepanel_selectStyle").val(S)}})},c=function(i,h,g){L.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/api/template/saveAdditional",type:"POST",data:{text:i,styleid:g},dataType:"json",success:function(j){U=i;if(L.isArray(j.errors)&&j.errors.length>0){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("error_saving_css"),iconType:"error"})}else{if(typeof (h)=="function"){openAlertDialog({title:vBulletin.phrase.get("success"),message:vBulletin.phrase.get("css_saved"),iconType:"success",onBeforeClose:function(){h()}})}else{openAlertDialog({title:vBulletin.phrase.get("success"),message:vBulletin.phrase.get("css_saved"),iconType:"success"})}}},error:function(){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("error_saving_css"),iconType:"error"})}})},A=function(){function g(){if(typeof (K)=="undefined"){K=CodeMirror.fromTextArea(L(".sb-style-panel_cssextraedit").get(0),{mode:"css",lineNumbers:true});U="";L(".js-style-panel #admin-stylepanel-csseditor .js_stylepanel_selectStyle").change();L(".sb-style-panel .tab-item a").off("click",g)}}L(".sb-style-panel .tab-item a").off("click",g).on("click",g);if(L(".js-style-panel .js-admin-stylepanel-csseditor").is(":visible")){g()}},F=function(){if(J){return }L(".js-style-panel .tabs").tabs();L(document).off("click",".js-style-panel #admin-stylepanel-themes .action-buttons .save").on("click",".js-style-panel #admin-stylepanel-themes .action-buttons .save",a);L(document).off("click",".js-style-panel #admin-stylepanel-themes .action-buttons .cancel").on("click",".js-style-panel #admin-stylepanel-themes .action-buttons .cancel",T);L(document).off("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .revert").on("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .revert",I);L(document).off("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .cancel").on("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .cancel",N);L(document).off("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .close").on("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .close",P);L(document).off("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .save").on("click",".js-style-panel #admin-stylepanel-csseditor .action-buttons .save",e);L(document).off("change",".js-style-panel #admin-stylepanel-csseditor .js_stylepanel_selectStyle").on("change",".js-style-panel #admin-stylepanel-csseditor .js_stylepanel_selectStyle",R);if(L(".js-style-panel .js-theme-selector__container").length==1){W({liveUpdate:false,containerSelector:".js-style-panel"})}if(L(".js-style-panel .js-admin-stylepanel-csseditor").length==1){A()}J=true},O=function(){L(function(){L(document).off("click","#main-navbar .sb-menu:not(.h-disabled) #lnkStylePanel").on("click","#main-navbar .sb-menu:not(.h-disabled) #lnkStylePanel",Y);if(typeof (pageData.adminAction)!="undefined"&&pageData.adminAction=="stylePanel"){L("#lnkStylePanel").click()}})};window.vBulletin=window.vBulletin||{};window.vBulletin.sitebuilder=window.vBulletin.sitebuilder||{};window.vBulletin.sitebuilder.initThemesInQuickConfig=function(){W({liveUpdate:true,containerSelector:".js-config-site-panel"})};O()})(jQuery);