document.addEventListener("DOMContentLoaded",function(){function a(a){url_str="url(media/bg/bg"+a+".jpg)",console.log(url_str),void 0===a|!a?(document.getElementById("canvasContainer").style.display="block",document.getElementById("body").style.display.backgroundImage="none",document.getElementById("resetBackgroundBtn").style.display="none"):(document.getElementById("canvasContainer").style.display="none",document.getElementById("body").style.backgroundImage=url_str)}function b(){var a=localStorage.getItem("background_image_file");document.getElementById("canvasContainer").style.display="none",document.getElementById("body").style.backgroundImage="url("+a+")","none"===document.getElementById("resetBackgroundBtn").style.display&&(document.getElementById("resetBackgroundBtn").style.display="inline-block")}var d=document.getElementById("resetBackgroundBtn"),f=localStorage.getItem("background_id");"yes"==localStorage.getItem("use_own_background_image")?(d.style.display="inline-block",b()):a(f),console.log("Filling options");for(var g,h=0,j=linkMenuOrder.length;h=m;m++){var n="media/bg-thumbs/bg"+m+".jpg",h=bg_thumb.cloneNode(!0);h.classList.remove("template"),h.style.backgroundImage="url("+n+")",h.setAttribute("data-id",m),bg_list.appendChild(h)}var l=function(){f="",localStorage.setItem("background_id",f),document.getElementById("thumbTemplate").classList.remove("active"),a(f),"yes"===localStorage.getItem("use_own_background_image")&&(localStorage.setItem("use_own_background_image","no"),localStorage.setItem("background_image_file",""))};document.getElementById("customBgBtnToggle").addEventListener("click",function(){document.getElementById("customBackgrounds").classList.toggle("active")});var o=document.querySelectorAll(".thumb");Array.from(o).forEach(function(c){c.addEventListener("mouseover",function(){bg_container.classList.contains("active")&&a(this.getAttribute("data-id"))}),c.addEventListener("mouseleave",function(){bg_container.classList.contains("active")&&("yes"===localStorage.getItem("use_own_background_image")?b():a(f))}),c.addEventListener("click",function(){if(bg_container.classList.contains("active")){f=this.getAttribute("data-id"),localStorage.setItem("background_id",f);for(let a of this.parentNode.children)a.classList.remove("active");this.classList.add("active"),d.style.display="inline-block"}localStorage.setItem("use_own_background_image","no"),localStorage.setItem("background_image_file","")})}),d.addEventListener("click",function(){l()}),globalResetBackground=l,document.getElementById("customBackgroundFile").addEventListener("change",function(){var a=this.files[0];if(0>a.type.indexOf("image"))return void alert("Sorry, that is an invalid file type");var b=new FileReader;b.onload=function(){var a=b.result;try{localStorage.setItem("background_image_file",a),localStorage.setItem("use_own_background_image","yes"),document.getElementById("canvasContainer").style.display="none",document.getElementById("body").style.backgroundImage="url("+a+")",d.style.display="inline-block",document.getElementById("customBackgrounds").classList.toggle("active"),lockSidebar=!1,closeNav()}catch(a){("QuotaExceededError"===a.name||"NS_ERROR_DOM_QUOTA_REACHED"===a.name)&&alert("Sorry, that image is too large for this browser.")}},b.readAsDataURL(a)})});