var spResx={};spResx.links="";spResx.pageid="";spResx.customerid="";spResx.cv1="";spResx.itemid="";spResx.qty="";spResx.price="";spResx.total="";spResx.transactionid="";spResx.host="";spResx.scheme="";spResx.appid="smartpak01";spResx.trackingid="";spResx.sessionid="";spResx.context="";spResx.display=4;spResx.rvp=[];spResx.carousel=[];spResx.canRun=true;spResx.tabIndex=0;spResx.beforeLoadCallback=null;spResx.afterLoadCallback=null;spResx.isRendered=false;spResx.replacePattern="sp_";spResx.recs=[];spResx.queue=[];spResx.setRvp=function(value){spResx.rvp=value};spResx.setLinks=function(){if(typeof spResx.productclassIds!=="undefined"&&spResx.productclassIds.length>0)if(spResx.links.length>0)resx.links=spResx.links+";"+spResx.productclassIds;else resx.links=spResx.productclassIds;else resx.links=spResx.links};spResx.setItemid=function(){if(typeof resx.itemid!=="undefined")resx.itemid=spResx.itemid};spResx.setHost=function(){if(typeof spResx.host!=="undefined")resx.host=spResx.host};spResx.setPageid=function(){resx.pageid=spResx.pageid};spResx.setCustomerid=function(){if(typeof spResx.customerid!=="undefined")resx.customerid=spResx.customerid};spResx.setCv1=function(){if(typeof spResx.cv1!=="undefined")resx.cv1=spResx.cv1};spResx.setRrelem=function(){if(typeof resx.rrec==="boolean"&&resx.rrec===true&&typeof(spResx.scheme==="string")&&spResx.scheme.length>0)resx.rrelem=spResx.scheme};spResx.setRrqs=function(){if(typeof spResx.categoryDefinition!=="undefined")resx.rrqs="categoryname="+encodeURIComponent(spResx.categoryDefinition)};spResx.canRecommend=function(){return typeof resx.rrec!=="undefined"&&resx.rrec===true};spResx.getPipeScheme=function(hasSeparator){var separator=";";if(typeof hasSeparator!=="undefined"&&hasSeparator===false)separator="";return spResx.canRecommend()?"|"+spResx.scheme+separator:";"};spResx.setCarousel=function(links,display){var pipeScheme=spResx.getPipeScheme();spResx.display=display;spResx.carousel=links;if(spResx.carousel.length>0)if(spResx.links.length>0)spResx.links=spResx.carousel.slice(0,spResx.display).join(pipeScheme)+pipeScheme+spResx.links;else spResx.links=spResx.carousel.slice(0,spResx.display).join(pipeScheme)+pipeScheme.replace(";","")};spResx.carouselUpdate=function(carousel,item,index,state){var pipeScheme=spResx.getPipeScheme(),links=[],i=2,re=/\d+(?=p\.aspx)/;if(state==="init"&&"#"+$(carousel.container).attr("id")!==$("ul.ui-tabs-nav li.ui-tabs-selected a").attr("href"))return;links.push($(item).find("a").not("a.button-red-small").attr("href").match(re)[0]);$(item).nextAll("li").find("a").not("a.button-red-small").each(function(){re.test($(this).attr("href"))&&links.push($(this).attr("href").match(re)[0]);if(i++>carousel.options.scroll-1)return false});if(spResx.tabIndex===0&&spResx.canRecommend()&&$(carousel.container).attr("id")!=="recentlyViewedProducts")spResx.links=links.join(pipeScheme)+pipeScheme.replace(";","");else spResx.links=links.join(";");spResx.setLinks();state!=="init"&&certonaResx.run()};spResx.tabSelect=function(selector){$(selector).bind("tabsselect",function(event,ui){var pipeScheme=spResx.getPipeScheme(),$items=$(ui.panel),$tab=$(ui.tab).attr("href"),$carousel=$($tab).data("jcarousel"),isCarousel=$carousel!==null,i=1,re=/\d+(?=p\.aspx)/,links=[];if(isCarousel){var $start=$(">.jcarousel-item-"+$carousel.first,$carousel.list);links.push($($start).find("a").not("a.button-red-small").attr("href").match(re)[0]);i=2;$($start).nextAll("li").find("a").not("a.button-red-small").each(function(){re.test($(this).attr("href"))&&links.push($(this).attr("href").match(re)[0]);if(i++>$carousel.options.scroll-1)return false})}else $("ul a",$items).not("ul a.button-red-small").each(function(){re.test($(this).attr("href"))&&links.push($(this).attr("href").match(re)[0])});if(ui.index===0&&spResx.canRecommend()){spResx.isRendered=false;spResx.links=links.join(pipeScheme)+pipeScheme.replace(";","")}else spResx.links=links.join(";");spResx.tabIndex=ui.index;spResx.setLinks();certonaResx.run()})};spResx.rvpReady=function(ary){spResx.setRvp(ary);spResx.canRun=true;spResx.onReady()};spResx.onReady=function(){spResx.svcTimer=setInterval(function(){if(spResx.canRun===true&&!spResx.queue.length){clearInterval(spResx.svcTimer);spResx.svcTimer=null;spResx.run()}},500)};spResx.run=function(){if(spResx.canRun===true){spResx.setRvpLinks();spResx.setLinks();spResx.setCustomerid();spResx.setCv1();spResx.setPageid();spResx.setHost();spResx.setRrelem();spResx.setRrqs();certonaResx.run()}};spResx.AddToCart=function(){spResx.canRun=false;resx.itemid=spResx.lastAddedProductClassId+"";spResx.rrsel="#rr_suggestCart";spResx.afterLoadCallback=function(){$(spResx.rrsel.replace("rr_","sp_")).remove();spResx.displayRecs()};spResx.setSuggestedItems(spResx.rrsel.replace("rr_","sp_")+" li a");certonaResx.run()};spResx.ApplyFilter=function(links){resx.links=links.join(";");certonaResx.run()};spResx.setTopPicks=function(links){var ary_links=typeof links==="undefined"?[]:links,pipeScheme=spResx.getPipeScheme();if(ary_links.length>0)if(spResx.links.length>0)spResx.links=ary_links.join(pipeScheme)+pipeScheme+spResx.links;else spResx.links=ary_links.join(pipeScheme)+pipeScheme.replace(";","")};spResx.setTopPicksLinks=function(selector){var toppick=typeof selector==="undefined"?"#top_picks a":selector,pipeScheme=spResx.getPipeScheme(false),links=[],val="";$(toppick).each(function(){var newVal=$(this).attr("href").match(/\d+(?=p\.aspx)/)[0];if(newVal!==val){links.push(newVal+pipeScheme);val=newVal}});if(links.length>0)if(spResx.links.length>0)spResx.links=links.join(";")+";"+spResx.links;else spResx.links=links.join(";")};spResx.setBrowseSupplementsLinks=function(){var links=[];$("div.product a:not(.buy)").each(function(){var re=/\d+(?=p\.aspx)/;re.test($(this).attr("href"))&&links.push($(this).attr("href").match(re)[0])});spResx.links=links.join(";")};spResx.setBuilderTopPicks=function(selector){var pipeScheme=spResx.getPipeScheme(),links=[];$(selector).each(function(){links.push($(this).attr("id").split("|")[1])});spResx.formatLinks(links)};spResx.setWizardLinks=function(){var links=[];$("input[id$='hfRecommendedProductId']").each(function(){links.push($(this).val())});spResx.links=links.join(";")};spResx.setRvpLinks=function(){if(spResx.rvp.length>0)if(spResx.links.length>0)spResx.links=spResx.links+";"+spResx.rvp.join(";");else spResx.links=spResx.rvp.join(";")};spResx.setRecLinks=function(){var pipeScheme=spResx.getPipeScheme(),display=spResx.display||4;if(spResx.recs.length>0)if(spResx.links.length>0)spResx.links=spResx.recs.slice(0,display).join(pipeScheme)+pipeScheme+spResx.links;else spResx.links=spResx.recs.slice(0,display).join(pipeScheme)+pipeScheme.replace(";","");spResx.recs=[]};spResx.setCarouselLinks=function(selector,display){var carousel=typeof selector==="undefined"?"#carouselview .carousel-name a":selector;spResx.display=typeof display==="undefined"?4:display;var pipeScheme=spResx.getPipeScheme(),links=[],i=1;$(carousel).each(function(){var re=/\d+(?=p\.aspx)/;re.test($(this).attr("href"))&&links.push($(this).attr("href").match(re)[0]+pipeScheme);if(++i>spResx.display)return false});spResx.carousel=links;if(spResx.carousel.length>0)if(spResx.links.length>0)spResx.links=spResx.carousel.slice(0,spResx.display).join(pipeScheme)+pipeScheme+spResx.links;else spResx.links=spResx.carousel.slice(0,spResx.display).join(pipeScheme)+pipeScheme.replace(";","")};spResx.setSuggestedItems=function(selector,notSelector){var suggest=typeof selector==="undefined"?"#sp_suggest li a":selector,notFilter=typeof notSelector==="undefined"?null:notSelector,links=[],re=/\d+(?=p\.aspx)/;if(notFilter===null)$(suggest).each(function(){links.push($(this).attr("href").match(re)[0])}).css({display:"block"});else $(suggest).not(notFilter).each(function(){re.test($(this).attr("href"))&&links.push($(this).attr("href").match(re)[0])}).css({display:"block"});spResx.formatLinks(links)};spResx.getItemFromUrl=function(){var re=/\d+(?=p\.aspx)/;spResx.itemid=location.href.match(re)[0];return spResx.itemid};spResx.formatLinks=function(value){var pipeScheme=spResx.getPipeScheme(),links=value;if(links.length>0)if(spResx.links.length>0)spResx.links=links.join(pipeScheme)+pipeScheme+spResx.links;else spResx.links=links.join(pipeScheme)+pipeScheme.replace(";","")};spResx.setProductRecs=function(options){var config={showBuyNow:false,isClearance:false,isRec:false,cm:null,beforeLoadCallback:null,afterLoadCallback:null,onErrorCallback:null},options=$.extend({},config,options),spHost="https:"===document.location.protocol?"https://":"http://",hasCMTag=typeof options.cm!==null;if(typeof options.beforeLoadCallback==="function"){options.beforeLoadCallback.call(this,options.selector);options.beforeLoadCallback=null}if(options.isRec===true){spResx.recs=options.items.split("|");spResx.setRecLinks();spResx.queue.push(options.selector)}$.ajax({type:"GET",url:"/Services/ProductClass.svc/productClasses/"+options.items.replace(";","|"),contentType:"application/json; charset=utf-8",dataType:"json",success:function(data){var recs=[];$.each(data,function(i,item){var oItem={};oItem.Id=item.Id;oItem.reviewCount=item["total-reviews"];oItem.reviewRating=Math.round(item["average-rating"]*10)/10+"";oItem.reviewImg=spHost+"reviews.smartpakequine.com/7493/"+oItem.reviewRating.replace(".","_")+"/5/rating.gif";var prodImage=item.Image;oItem.altTitle=rvpCleanTitle(item.Title,"alt");oItem.cmTag=hasCMTag===true?"?cm_sp="+options.cm+item.Id:"";oItem.isClearance=options.isClearance===true;oItem.prodPrice=item.Price;oItem.showBuyNow=options.showBuyNow===true;oItem.prodImg="/images/product/thumbnails/"+prodImage;oItem.img=prodImage;oItem.prodName=rvpCleanTitle(item.Title);oItem.prodUrl=item.Url+oItem.cmTag;oItem.Url=item.Url;recs.push(oItem);oItem=null});$(options.template).tmpl(recs).appendTo(options.selector);if(recs.length>1)if(typeof options.afterLoadCallback==="function"){options.afterLoadCallback.call(this,options.selector);options.afterLoadCallback=null}if(options.isRec===true){var idx=$.inArray(options.selector,spResx.queue);idx!=-1&&spResx.queue.splice(idx,1)}},error:function(){if(typeof options.onErrorCallback==="function"){options.onErrorCallback.call(this,options.selector);options.onErrorCallback=null}}})};spResx.renderRecs=function(data){var hasRecs=false,recsEqual=false;try{if(!spResx.isRendered&&typeof data==="object"){var response=data.Resonance.Response[0];if(response.hasOwnProperty("display")&&response["display"].toLowerCase()==="yes"&&response["output"].length>0){hasRecs=true;spResx.scheme=typeof resx.scheme!="undefined"&&resx.scheme.length>0?resx.scheme:response["scheme"];if(spResx.scheme==="home_rr"){if(spResx.recs.length>0)recsEqual=true;spResx.recs=response["output"].replace(";","").split("|")}!recsEqual&&spResx.setProductRecs({items:response["output"].replace(";",""),selector:spResx.rrsel,template:"#tmpl_products",cm:spResx.cm,beforeLoadCallback:spResx.beforeLoadCallback,afterLoadCallback:spResx.afterLoadCallback})}}}catch(e){}finally{if(!hasRecs&&!spResx.isRendered){if(spResx.scheme!="undefined"&&spResx.scheme==="home_rr")typeof homeInit==="function"&&spResx.afterLoadCallback(spResx.rrsel);$(spResx.rrsel.replace("rr_",spResx.replacePattern)).css({display:"block"});spResx.scheme==="addtocart_rr"&&showCartWindow()}spResx.isRendered=true}};spResx.displayRecs=function(){$("#"+spResx.scheme).css({display:"block"})};spResx.reloadHomeRecs=function(selector){var $carousel=$(spResx.rrsel.replace("rr_","")).data("jcarousel");$carousel.reset();$carousel.size(0);$(selector+" li").remove()}

