$(function(){var n={init:function(){this.attachListeners();this._filterApplied=!1;this.applyFilterFromHash();this._filterApplied||this.applyFilterFromQuerystring();this._filterApplied||this.applyVehicleFitmentFilters();this._filterApplied||this.applyFilterFromCookie();this._filterApplied||this.applyPreSelectedFilters();this._filterApplied||$(".required_filters_container").removeClass("hidden");this.updateSectionCopy()},attachListeners:function(){var n=this;$(".subcategory_landing .filters [data-filter]").click(function(t){var u,f,i,r;($(this).attr("data-isFeatured")&&$(this).hasClass("selected")||!$(this).attr("data-isFeatured")&&$(this).attr("href")=="#")&&(t.preventDefault(),$(this).attr("data-issaveappliedfilter")&&T5Global.storeUserPreference("Applied_Filter_"+Turn5.Analytics.PageVehicleType,$(this).text().trim()),$(this).hasClass("selected")?window.location.hash==""||window.location.hash=="#"?(n.updateSelectedFilter(),n.updateProducts()):(u=document.body.scrollTop,window.location.hash=" ",document.body.scrollTop=u):($(this).attr("data-useVehicleFitment")&&(f={filter:$(this).attr("title"),vehicleType:Turn5.Analytics.PageVehicleType},$.ajax({url:"/ajax/UpdateVehicleFitmentFromFilter",data:f})),i=$(this).data("ajaxurl")||"",r=$(this).data("filter-generation")||"",i&&r?$.ajax({url:i,type:"POST",data:{generation:r},datatype:"json"}).done(function(){window.location.href=window.location.href}):$(this).attr("data-shopby")&&(window.location.hash=$(this).attr("data-shopby"))),$("body").trigger("XT.FilterApplied"))});$(window).on("hashchange",function(){var t=window.location.hash.replace("#","");n.updateSelectedFilter(t);n.updateProducts($('.filters a[data-shopby="'+t+'"]').data("filter"));$("body").trigger("AM.FilterApplied")});if($(".required_filters_container").length>0)$("body").on("keyup.filtermodal",function(n){n.which==27&&($(".required_filters_container").addClass("hidden"),$("body").off("keyup.filtermodal"))})},applyFilterFromCookie:function(){var t=this,n;T5Global.getUserPreference("Applied_Filter_"+Turn5.Analytics.PageVehicleType)&&$(".filters").attr("data-apply-saved-filter-cookie")=="true"&&(n=T5Global.getUserPreference("Applied_Filter_"+Turn5.Analytics.PageVehicleType),n=n.replace(/"/g,""),$(".filters a").each(function(){if($(this).attr("title")){var i=$(this).attr("title").replace(/"/g,"");i==n&&($(this).click(),t._filterApplied=!0)}}))},applyFilterFromHash:function(){if(window.location.hash.indexOf("shop-by")>-1){var n=window.location.hash.replace("#","");this.updateSelectedFilter(n);this.updateProducts($('.filters a[data-shopby="'+n+'"]').data("filter"));this._filterApplied=!0;$("body").trigger("AM.FilterApplied")}},applyFilterFromQuerystring:function(){var t=this,n;T5Global.getQSValue("filter")&&(n=decodeURIComponent(T5Global.getQSValue("filter")),n=n.replace(/"/g,""),$(".filters a").each(function(){var i=$(this).attr("title").replace(/"/g,""),r=$(this).attr("data-shopby");(n==i||n==r)&&($(this).click(),t._filterApplied=!0)}))},applyPreSelectedFilters:function(){var t=this,n;Turn5&&Turn5.PreSelectedFilter&&(n=$("<textarea/>").html(Turn5.PreSelectedFilter).text(),n=n.replace(/"/g,""),$(".filters a").each(function(){var i=$(this).attr("title").replace(/"/g,"");i==n&&($(this).click(),t._filterApplied=!0)}))},applyVehicleFitmentFilters:function(){var n=this;Turn5&&Turn5.VehicleFitmentFilter&&(filter=Turn5.VehicleFitmentFilter.replace(/"/g,""),$(".filters a").each(function(){var t=$(this).attr("title").replace(/"/g,"");t==filter&&($(this).click(),n._filterApplied=!0)}))},updateSelectedFilter:function(n){$(".filters a[data-shopby].selected").removeClass("selected");n&&$('.filters a[data-shopby="'+n+'"]').addClass("selected")},updateProducts:function(n){var r,t,u,i;if(n)for(r=$("section[data-filter]"),t=0,u=r.length;t<u;t++)i=$(r[t]),i.data("filter")===n?i.removeClass("hidden"):i.addClass("hidden");else $("section[data-filter]").removeClass("hidden")},updateSectionCopy:function(){var i=$(".page_caption_container .content").height(),n=parseFloat($(".page_caption_container .content").css("line-height"),10),t;n&&(t=Math.ceil(i/n),t<=10?($(".page_caption_container .expand_trigger ").remove(),$(".page_caption_container").css("height","auto")):$(".page_caption_container").height(n*10+50))}}.init()})