function handlePaging(){var n=$("#bikeList").is(":visible");setTimeout(function(){n&&(refreshBikeList(),$("#bikeList").show())},2500)}function refreshBikeList(){for($(".bike-compare").show(),$("#threeMaxMessage").hide(),$(".js-search-trigger").unbind(),$(".js-search-trigger").click(function(){handlePaging()}),$("#bikeListArr").html(""),i=0;i<selectedBikes.length;i++)$("#bikeListArr").append("<div style='background-image: url(\""+selectedBikes[i].ImageSource+"\"); background-size: 125px 150px;' class='bikeContainer'><span aria-label='Remove bike from comparison tool' class='removeBike'>Remove<\/span><\/div>");selectedBikes.length<=1?($("#bikeCompareDisabled").show(),$("#launchComparison").addClass("compareDisabled")):($("#bikeCompareDisabled").hide(),$("#launchComparison").removeClass("compareDisabled"));$(".removeBike").unbind();$(".removeBike").click(function(){var t=this,n=$(".removeBike").index($(t));$("#"+selectedBikes[n].ItemNumber).find(".bike-compare").addClass("deselected");selectedBikes.splice(n,1);refreshBikeList()});$("#resetAllSelect").unbind();$("#resetAllSelect").click(function(){for(var n=0;n<selectedBikes.length;n++)$("#"+selectedBikes[n].ItemNumber).find(".bike-compare").addClass("deselected");selectedBikes=[];refreshBikeList();$("#bikeList").hide()});$("#closeBikeList").unbind();$("#closeBikeList").click(function(){$("#bikeList").hide()});$(".bike-compare").unbind();$(".bike-compare").click(function(){var n=this,t;if($("#bikeList").show(),$(n).hasClass("deselected"))if(selectedBikes.length>=3)$("#threeMaxMessage").fadeIn(300).delay(1200).fadeOut(300);else{$(n).removeClass("deselected");var i=$(n).parent().attr("id"),r=$(n).siblings(".item-img").find(".js-main-image").prop("src"),u=$(n).siblings(".product-name").html(),f=$(n).siblings(".item-price").find(".product-price-saleprice").html(),e=$(n).siblings(".item-price").find(".product-price-defprice").html(),o=$(n).siblings(".item-price").find(".product-price-percentoff").html(),s=new BikeSelectionEntry(i,r,u,f,e,o);selectedBikes.push(s)}else $(n).addClass("deselected"),t=selectedBikes.map(function(n){return n.ItemNumber}).indexOf($(n).parent().attr("id")),selectedBikes.splice(t,1);refreshBikeList()});$("#launchComparison").unbind();$("#launchComparison").click(function(){var t,n;if(selectedBikes.length>=2){for($("body").append("<div id='compareLoading'>Please wait, loading bike comparrison... <br /> <img src='/Content/images/loadingCog.gif' /><\/div>"),t=[],n=0;n<selectedBikes.length;n++)t.push(selectedBikes[n].ItemNumber);$.post("/api/category/CompareBikeRequest",{CompareCodes:t},function(n){$("#compareLoading").remove();SetupCompareWindow(selectedBikes,n);$("#bikeCompareTool").fancybox({type:"inline",autoSize:!1,width:1200,height:870,scrolling:"no"}).trigger("click");$(".fancybox-skin").css("background-color","white");InitiateRemove(selectedBikes,n)},"json")}})}function BikeSelectionEntry(n,t,i,r,u,f){this.ItemNumber=n;this.ImageSource=t;this.ItemName=i;this.ItemPrice=r;this.MSRP=u;this.SavePercent=f}function SetupCompareWindow(n,t){for(CleanCompareWindow(),i=0;i<t.Bikes.length;i++){$("table #compareHeaderImage").append("<td class='bikeCompareImg'><a href ='https://"+window.location.host+"/"+n[i].ItemNumber+"'><img src='"+n[i].ImageSource+"' alt='"+n[i].ItemName+"' /><\/a><\/td>");$("table #compareBikeName").append("<td class='bikeCompareTitle'>"+n[i].ItemName+"<\/td>");var r="<td class='bikeComparePrice'><span class='currentPrice'>"+n[i].ItemPrice+"<\/span>";n[i].MSRP!=null&&(r+="<span class='savePercent'>"+n[i].SavePercent+"<\/span><span class='bikeMSRP'>"+n[i].MSRP+"<\/span>");r+="<\/td>";$("table #comparePrice").append(r);$("table #compareButtons").append("<td class='compareBtnRow'><a href ='https://"+window.location.host+"/"+n[i].ItemNumber+"'><input type='button' class='compareShopNowBtn' value='SHOP NOW' /><\/a><input type='button'  name='"+[i]+"' class='compareRemoveBtn' value='REMOVE' /><\/td >");DoColumnsExist(t.Bikes,"DriveUnit")?$("table #driveUnit").append("<td class='bikeCompareColumn'>"+t.Bikes[i].DriveUnit+"<\/td>"):$("table #driveUnit").hide();DoColumnsExist(t.Bikes,"Battery")?$("table #specBattery").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Battery+"<\/td>"):$("table #specBattery").hide();DoColumnsExist(t.Bikes,"Display")?$("table #specDisplay").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Display+"<\/td>"):$("table #specDisplay").hide();DoColumnsExist(t.Bikes,"Frame")?$("table #specFrame").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Frame+"<\/td>"):$("table #specFrame").hide();DoColumnsExist(t.Bikes,"Fork")?$("table #specFork").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Fork+"<\/td>"):$("table #specFork").hide();DoColumnsExist(t.Bikes,"RearShock")?$("table #specRearShock").append("<td class='bikeCompareColumn'>"+t.Bikes[i].RearShock+"<\/td>"):$("table #specRearShock").hide();DoColumnsExist(t.Bikes,"Headset")?$("table #specHeadset").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Headset+"<\/td>"):$("table #specHeadset").hide();DoColumnsExist(t.Shifters,"Battery")?$("table #specShifters").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Shifters+"<\/td>"):$("table #specShifters").hide();DoColumnsExist(t.Bikes,"RearDerailleur")?$("table #specRearDerailleur").append("<td class='bikeCompareColumn'>"+t.Bikes[i].RearDerailleur+"<\/td>"):$("table #specRearDerailleur").hide();DoColumnsExist(t.Bikes,"Crankset")?$("table #specCrankset").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Crankset+"<\/td>"):$("table #specCrankset").hide();DoColumnsExist(t.Bikes,"Chain")?$("table #specChain").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Chain+"<\/td>"):$("table #specChain").hide();DoColumnsExist(t.Bikes,"Cassette")?$("table #specCassette").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Cassette+"<\/td>"):$("table #specCassette").hide();DoColumnsExist(t.Bikes,"Brakes")?$("table #specBrakes").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Brakes+"<\/td>"):$("table #specBrakes").hide();DoColumnsExist(t.Bikes,"RotorSize")?$("table #specRotorSize").append("<td class='bikeCompareColumn'>"+t.Bikes[i].RotorSize+"<\/td>"):$("table #specRotorSize").hide();DoColumnsExist(t.Bikes,"WheelSet")?$("table #specWheelset").append("<td class='bikeCompareColumn'>"+t.Bikes[i].WheelSet+"<\/td>"):$("table #specWheelset").hide();DoColumnsExist(t.Bikes,"Tires")?$("table #specTires").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Tires+"<\/td>"):$("table #specTires").hide();DoColumnsExist(t.Bikes,"Handlebar")?$("table #specHandlebars").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Handlebar+"<\/td>"):$("table #specHandlebars").hide();DoColumnsExist(t.Bikes,"Stem")?$("table #specStem").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Stem+"<\/td>"):$("table #specStem").hide();DoColumnsExist(t.Bikes,"Grips")?$("table #specGrips").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Grips+"<\/td>"):$("table #specGrips").hide();DoColumnsExist(t.Bikes,"SeatPost")?$("table #specSeatpost").append("<td class='bikeCompareColumn'>"+t.Bikes[i].SeatPost+"<\/td>"):$("table #specSeatpost").hide();DoColumnsExist(t.Bikes,"SeatClamp")?$("table #specSeatclamp").append("<td class='bikeCompareColumn'>"+t.Bikes[i].SeatClamp+"<\/td>"):$("table #specSeatclamp").hide();DoColumnsExist(t.Bikes,"Saddle")?$("table #specSaddle").append("<td class='bikeCompareColumn'>"+t.Bikes[i].Saddle+"<\/td>"):$("table #specSaddle").hide();DoColumnsExist(t.Bikes,"IntendedUse")?$("table #specIntendedUse").append("<td class='bikeCompareColumn'>"+t.Bikes[i].IntendedUse+"<\/td>"):$("table #specIntendedUse").hide()}$("td.bikeCompareColumn").each(function(){$(this).html()=="null"&&$(this).html("---")});$(".compareShopNowBtn").click(function(){window.location=$(this).parent().attr("href")});$(".bikeCompareImg").click(function(){window.location=$(this).children().attr("href")});UpdateCompareWidth(t)}function DoColumnsExist(n,t){if(n!=undefined&&n!=null&&n.length!=undefined&&n.length!=null)for(var i=0;i<n.length;i++)if(n[i][t]!=undefined&&n[i][t]!=null)return!0;return!1}function InitiateRemove(n,t){$(".compareRemoveBtn").click(function(){var i=parseInt($(this).attr("name"));$("#"+n[i].ItemNumber).find(".bike-compare").addClass("deselected");t.Bikes.splice(i,1);n.splice(i,1);UpdateCompareWidth(t);refreshBikeList();SetupCompareWindow(n,t);InitiateRemove(n,t);n.length<2&&$.fancybox.close()})}function UpdateCompareWidth(n){n.Bikes.length==2?$(".bikeCompareColumn").css("width","37%"):$(".bikeCompareColumn").css("width","27%")}function CleanCompareWindow(){$("thead #compareButtons .compareBtnRow").remove();$("thead #compareBikeName .bikeCompareTitle").remove();$("td.bikeCompareColumn").each(function(){$(this).prop("id")||$(this).remove()});$("thead #comparePrice .bikeComparePrice").remove();$("thead #compareHeaderImage .bikeCompareImg").remove()}