var APPLICATION=APPLICATION||{};APPLICATION.BOOKSHOP={IsMobileGenreList:$("body").width()<768,BINDINGS:{BindBookCoverLink:function(){$(".cover-image-overlay").on("click",function(){var n=$("#view-book-cover-modal"),t=$(this).parents(":eq(2)").find(".view-cover-link").text().indexOf("Back")>=0,i=t?"View Back Cover":"View Front Cover";APPLICATION.BOOKSHOP.FUNCTIONS.RequestBookCover(n.find(".front-cover"),$(".cover-image .front-cover").attr("src")+"Large");APPLICATION.BOOKSHOP.FUNCTIONS.RequestBookCover(n.find(".back-cover"),$(".cover-image .back-cover").attr("src")+"Large");n.find(".front-cover").toggle(t);n.find(".back-cover").toggle(!t);n.find(".view-cover-wrapper .view-cover-link").text(i).attr("title",i);n.find(".modal-header").text(t?"Front Cover":"Back Cover");MODAL.DOM.OpenModal({modalElementId:"#view-book-cover-modal"})});$(".view-cover-wrapper .view-cover-link").off("click").on("click",function(){var i=$("#view-book-cover-modal"),r=$(this).parents(":eq(1)"),n=$(this).text().indexOf("Back")>=0,t=n?"View Front Cover":"View Back Cover";return r.find(".back-cover").toggle(n),r.find(".front-cover").toggle(!n),$(this).text(t).attr("title",t),i.find(".view-cover-wrapper .view-cover-link").text(t).attr("title",t),i.find(".modal-header").text(n?"Back Cover":"Front Cover"),!1})},BindSectionClick:function(){$("div.section-name").off("click").on("click",function(){return $(this).find("i").hasClass("icon-down-open-1")?$(this).find("i").removeClass("icon-down-open-1").addClass("icon-up-open-1"):$(this).find("i").removeClass("icon-up-open-1").addClass("icon-down-open-1"),$("body").width()<=667&&$(this).next(".article-content").toggle(),!1})},BindPreviewCarouselButton:function(){$("#seeinside-pageimages-modal .preview-carousel-button").off("click").on("click",function(n){var t={previewImg:$("#seeinside-pageimages-modal .modal-content .preview-image-wrapper img:first"),previewImgCount:$("#seeinside-pageimages-modal .modal-content .preview-image-wrapper img").length,previewImgModal:$("#seeinside-pageimages-modal .modal-content"),slideSpeed:150,dropShadow:2},u=t.previewImgModal.scrollTop(),e=parseInt(t.previewImg.css("margin-bottom").replace("px",""))+t.dropShadow,i=t.previewImg.height()+e,o=Math.round(u/i)+parseInt(1),f=$(this),r;f.hasClass("next-preview-page")?t.previewImgModal.animate({scrollTop:i*o},t.slideSpeed):f.hasClass("prev-preview-page")&&(r=Math.ceil(u/i)-parseInt(1),Math.round(u)===Math.round(i*r)?t.previewImgModal.animate({scrollTop:i*(r-1)},t.slideSpeed):t.previewImgModal.animate({scrollTop:i*r},t.slideSpeed));n.preventDefault()})},BindGenreTopItem:function(){if(AVL.UTILITIES.FUNCTIONS.IsMobile())$(".genre-nav #genre-nav ul li:first-of-type").off("click").on("click",function(n){$("#genre-nav .toggle").is(":visible")?(APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(0,"genre-name"),$("#genre-nav .toggle").hide(),$("#books").is(":Visible")&&$("#genres-page aside:not(#genre-nav)").hide()):(APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(6,"genre-name"),$("#genre-nav .toggle").show().css("display","inline-block"),$("#genres-page aside:not(#genre-nav)").show());n.preventDefault()})},BindSubGenreTopItem:function(){if(AVL.UTILITIES.FUNCTIONS.IsMobile())$("#genres-page aside:not(#genre-nav) h2").off("click").on("click",function(n){$("#books").is(":Visible")&&($(".genre-nav #subgenre-list .toggle").is(":visible")?(APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(0,"subgenre-name"),$(".genre-nav #subgenre-list .toggle").hide()):(APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(6,"subgenre-name"),$(".genre-nav #subgenre-list .toggle").show().css("display","inline-block")),n.preventDefault())})},BindWindowLoad:function(n,t,i){$(n).each(function(){var t=$(this),n=$("<img alt='Book Cover'>").css("display","none");n.on("load",function(){t.hide().replaceWith(n);n.addClass(i).fadeIn(100)});n.attr("src",t.attr("data-src"))})}},FUNCTIONS:{GenreListLength:function(n){return n==null?APPLICATION.BOOKSHOP.IsMobileGenreList?0:9:n?APPLICATION.BOOKSHOP.IsMobileGenreList?6:9:null},CheckEbookOnly:function(){$("#linked-formats-list li").length===1&&$("#linked-formats-list li label").text().indexOf("eBook")>=0&&$(".view-cover-wrapper .view-cover-link").hide()},RequestBookCover:function(n,t){if(n.attr("src")===""){var i=new XMLHttpRequest;i.open("GET",t,!0);i.onload=function(){if(i.readyState===4&&i.status===200){var r=i.getAllResponseHeaders();n.attr("src",t);t.indexOf("Back")>0&&r.indexOf("hasbackcover: false")<0&&$(".view-cover-wrapper").show();t.indexOf("Large")>0&&setTimeout(function(){$(".cover-loading-message").hide();$("#view-book-cover-modal .book-img").removeClass("book-img-loading")},1e3)}else n.attr("src","../CommonControls/Universal/Bookshop/IMG/NoBookCover.jpg")};i.onerror=function(){return};i.send(null)}},SetBackCovers:function(){var n=$(".cover-image .front-cover").attr("src").replace("=Front","=Back");APPLICATION.BOOKSHOP.FUNCTIONS.RequestBookCover($(".cover-image .back-cover"),n)},UpdateGenreList:function(n,t){var r=document.getElementsByClassName(t),i,u;for(n==null&&(n=r.length),i=0;i<r.length;i++)i>n?r[i].style.display="none":(u=r[i].getElementsByClassName("count")[0].innerText,parseFloat(u)>0?r[i].style.display="flex":(r[i].style.display="none",n++))},ToggleGenre:function(n,t){return n.innerText.indexOf("Show Less")==0?(n.innerHTML="Show More <i class='icon-down-open-1'><\/i>",n.title="Show More",APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(APPLICATION.BOOKSHOP.FUNCTIONS.GenreListLength(!0),t)):(n.innerHTML="Show Less <i class='icon-up-open'><\/i>",n.title="Show Less",APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(null,t)),!1},ToggleSubGenre:function(n){var t=$(".genre-nav aside:last-of-type"),i=$(".subgenre-content"),r=$(".genre-content");return n.innerText.indexOf("Show More")==0?(t.hide(),i.show(),r.hide(),APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(null,"subgenre-name"),$("#genre-buttons").hide(),n.textContent="Show Less"):n.innerText.indexOf("Show Less")==0&&(t.show(),i.hide(),r.show(),APPLICATION.BOOKSHOP.FUNCTIONS.UpdateGenreList(APPLICATION.BOOKSHOP.FUNCTIONS.GenreListLength(!0),"subgenre-name"),$("#genre-buttons").show(),n.textContent="Show More"),!1},GetCurrentGenrePageCount:function(){$genreSubCountCurrent=$("#lblSubGenreCountCurrent");var n=$genreSubCountCurrent.text();return n!=""?$currentTitleCount=parseInt(n):($genreCountCurrent=$("#lblGenreCountCurrent"),$currentTitleCount=parseInt($genreCountCurrent.text())),Math.ceil($currentTitleCount/20)}}}