widget.techSpree=function(a,k,i,d){defaults={lang:"en-CA"};d=$.extend(defaults,d);new api.product(a,function(c){c=parseInt(c.product.onlineAvailabilityCount)?parseInt(c.product.onlineAvailabilityCount):0;var h=k-c;d.showProgress&&d.showProgress(h);c==0&&d.soldout&&d.soldout();h>=i&&d.threshold&&d.threshold(i,h)},{include:"all",lang:d.lang});return this};
widget.topRatedProducts=function(a,k,i){defaults={lang:"en-ca"};i=$.extend(defaults,i);var d=0,c=[],h=function(l){var m=parseInt(l.total);d=this.itemCount+m>k?k:d+m;if(d>1)i.formatProductListing&&i.formatProductListing(c.concat(l.products));else i.disableWidget&&i.disableWidget()};new api.search(a,null,function(l){var m=parseInt(l.total);d=m>k?k:m;c.concat(l.products);if(m<k){c=c.concat(l.products);new api.search(a,null,h,{facetpath:"cFSMCCPCatalogenCADepartments##-1##-1~~nf39||34",lang:i.lang,orderBy:"customerRating",
pageSize:k-m})}else i.formatProductListing&&i.formatProductListing(l.products)},{facetpath:"cFSMCCPCatalogenCADepartments##-1##-1~~nf39||35",lang:i.lang,orderBy:"customerRating",pageSize:k});return this};
widget.productFinder=function(a,k,i,d){d=d||{};var c=this,h=d.lang?d.lang:"en-ca",l=function(b){var f=h=="en-ca"?"Category":"Categorie";if(parseInt(b.count)>0)if(!(d.exclude&&d.exclude.search(b.name)>-1)&&(!d.include||d.include.search(b.name)>-1)){var e=$('<select class="facet-listing"></select>').change(function(){c.update($(this).val())});e.append($('<option class="facet-name"></option>').html(b.name=="category"?f:b.name));for(var j in b.filters.filter){f=b.filters.filter[j];parseInt(f.count)>0&&
e.append($('<option class="facet-value"></option>').html(f.name+"("+f.count+")").attr("value",f.path))}return e}else return"";else return""},m=function(b){$(a).find(".keywordsearch .facetkw").val("").parent().find(".removeQuery").remove();var f=h=="en-ca"?"Undo":"annuler",e=$('<ul class="path-listing"></ul>)');for(var j in b){var g=b[j],n=g.name,o=g.value;if(g.type!="Query"){if(n!="PresentationHierarchy1"){g=$('<li class="path"><span class="facet">'+n+'</span><span class="value">'+o+"</span></li>").append($('<a href="#" class="btnRemove">'+
f+"</a>").data("filter",g.unselectPath).click(function(){c.update($(this).data("filter"));return false}));e.append(g)}}else{n=$('<span class="removeQuery"></span>').append($('<a class="btnRemove">Remove</a>').data("filter",g.unselectPath).click(function(){c.update($(this).data("filter"),"");return false}));$(a).find(".keywordsearch .facetkw").val(g.name).after(n)}}return e},r=function(b,f){var e=h=="en-ca"?"Next":"Suivant",j=h=="en-ca"?"Previous":"Pr\ufffdc\ufffddent",g=h=="en-ca"?"of":"de",n=$('<div class="pagination"></div>');
n.append($('<div class="info"></div>').html("Page: "+b+" "+g+" "+f));g=$('<ul class="pagenum"></ul>');j=$('<li class="page"></li>').append($('<a class="btnPage"></a>').html(j).click(function(){c.gotoPage(parseInt(b)-1,f);return false}));parseInt(b)<2&&j.find("a").addClass("disabled").unbind("click");g.append(j);for(j=1;j<=f;j++)if(j==1||j==f||j>parseInt(b)-3&&j<parseInt(b)+3){var o=$('<li class="page"></li>').append($('<a class="btnPage"></a>').html(j).click(function(){c.gotoPage(parseInt($(this).html()),
f);return false}));j==b&&o.addClass("selected");g.append(o)}else if(j==2&&parseInt(b)>4||j==f-1&&parseInt(b)<f-3){o=$('<li class="page divider"></li>').html("...");g.append(o)}e=$('<li class="page"></li>').append($('<a class="btnPage"></a>').html(e).click(function(){c.gotoPage(parseInt(b)+1,f);return false}));parseInt(b)>f-1&&e.find("a").addClass("disabled").unbind("click");g.append(e);n.append(g);e=$('<ul class="layouts"></ul>');e.append($('<li class="selected"></li>').append($('<a href="#" class="btnLaySimple"></a>').html("simple").click(function(){$(this).parent().parent().children().removeClass("selected");
$(this).parent().addClass("selected");c.productlayout="";a.find(".products .product-listing").attr("class","product-listing");return false})));e.append($("<li></li>").append($('<a href="#" class="btnLayDetail"></a>').html("detail").click(function(){$(this).parent().parent().children().removeClass("selected");$(this).parent().addClass("selected");c.productlayout="layDetail";a.find(".products .product-listing").attr("class","product-listing layDetail");return false})));e.append($("<li></li>").append($('<a href="#" class="btnLayThumbnail"></a>').html("thumbnail").click(function(){$(this).parent().parent().children().removeClass("selected");
$(this).parent().addClass("selected");c.productlayout="layThumbnail";a.find(".products .product-listing").attr("class","product-listing layThumbnail");return false})));c.productlayout=="layThumbnail"&&e.find(".btnLayThumbnail:first").click();c.productlayout=="layDetail"&&e.find(".btnLayDetail:first").click();return n};this.gotoPage=function(b,f){if(a.find(".products").data("page"+b)){c.updatePagination(b,f);a.find(".products").find(".product-listing").remove();a.find(".pagination").before(a.find(".products").data("page"+
b))}else{c.loadingAnimation(true);c.api.gotoPage(c.updateProducts,b)}};(function(){a.find(".keywordsearch .facetkw").keypress(function(b){if(b.which=="13"){b.preventDefault();c.update(null,$(this).val())}})})();(function(){a.find(".btnReset").click(function(){c.init();return false})})();this.cb=function(b,f){$(a).find(".facets").html("").append(m(b.paths.path)).append($('<div class="facet-wrapper"></div>'));for(var e in b.facets.facet)$(a).find(".facets .facet-wrapper").append(l(b.facets.facet[e]));
$(a).find(".productcount .count").html(b.total);a.find(".products").removeData();c.updateProducts(b,f)};this.updateProducts=function(b){c.loadingAnimation(false);a.find(".products").html("");var f=b.products,e=$('<ul class="product-listing"></ul>');c.productlayout&&e.addClass(c.productlayout);for(var j in f){var g=f[j],n=h=="en-ca"?"Customer Rating:":"Note des clients:",o="/"+h+"/product/id/"+g.sku+".aspx",q='<h3 class="btm-spacep"><a href="'+o+'" class="std-right-margin">'+g.name+'</a></h3><div class="skuwebid">'+
(h=="en-ca"?"WebID":"CodeWeb")+":"+g.sku+"</div>",p=Number(g.regularPrice)-Number(g.salePrice),t=h=="en-ca"?String(p.toFixed(2)):String(p.toFixed(2)).replace(".",","),s="";if(p>0)s='<img class="floatleft" src="http://www.futureshop.ca/images/PricePills/'+h+"_SmallFSSaveBanner_"+t+'.Gif" alt="">';if(g.customerRatingCount!=0){q+='<div class=""><div class="rating-holder"><p class="rating-title floatleft">'+n+'</p><div class="rating">';n=parseInt(g.customerRating);for(p=0;p<5;p++)q+=n>p?'<img src="/images/common/pictures/rating_arrow_full_sm.gif" alt="" />':
'<img src="/images/common/pictures/rating_arrow_empty_sm.gif" alt="" />';q+=n+' /5</div><p class="floatleft"> (Based on '+g.customerRatingCount+" votes) </p></div>"}g=$('<li class="product"></li>').append('<div class="findersku"><a href="'+o+'"><img src="'+g.thumbnailImage.replace("100x100","130x130")+'" alt="" class="img130x130" /></a></div>').append($('<div class="skudetail"></div>').html(q)).append('<div class="finderprice"><a href="'+o+'">'+s+'<div class="clear"></div><img class="floatleft" src="http://www.futureshop.ca/images/PricePills/en-CA_SmallFSPricePill_'+
String(g.salePrice).replace(".","_")+'.Gif" alt="$'+g.salePrice+'" /></a></div>');e.append(g)}a.find(".products").data("page"+b.currentPage,e).append(e);c.updatePagination(b.currentPage,b.totalPages)};this.updatePagination=function(b,f){var e=a.find(".products .pagination");e.length>0?e.replaceWith(r(b,f)):a.find(".products").append(r(b,f))};this.init=function(){c.loadingAnimation(true);a.find(".preinit-selection").hide();this.api=new api.search(k,i,this.cb,{cat:k,facets:true,lang:h,pageSize:"6"})};
this.update=function(b,f){a.find(".productcount").show();a.find(".products").show();var e={facets:true};if(b)e.facetpath=b;else if(this.api.facetPath)e.facetpath=this.api.facetPath;e.lang=h;e.pageSize="6";if(f==null)if(this.api.keyword)f=this.api.keyword;c.loadingAnimation(true);this.api=new api.search(k,f,this.cb,e)};this.loadingAnimation=function(b){b?a.find(".overlay").width(a.width()).height(a.height()).show():a.find(".overlay").hide()};return this};
var facetFinderWidget=function(a){a=$.extend(true,{initRO:{pageSize:1,include:"facets",query:"",cat:"cellcases"}},a);var k={},i=$(".CaseFinderWidget select#ddBrands"),d=$(".CaseFinderWidget select#ddModels"),c=function(h){h=$.extend({},h);i.unbind("change").change(function(){var l=$(this).val();d.find(".val").remove();if(l=="select")d.val("select").trigger("change").attr("disabled","disabled");else{l=k[l];d.find(".val").remove();for(var m in l)d.append($('<option class="val" value="'+m+'">'+m+"</option>").data("count",
l[m]));d.attr("disabled","")}});d.unbind("change").change(function(){if($(this).val()=="select"){$(".CaseFinderWidget .lblAvail").text(a.initAvailText);$(".CaseFinderWidget .count").text($(".CaseFinderWidget .count").data("count"))}else{$(".CaseFinderWidget .lblAvail").text(a.searchAvailtext);$(".CaseFinderWidget .count").text($(this).find("[value="+$(this).val()+"]").data("count"))}});a.phoneBrand&&i.find("[value~="+unescape(a.phoneBrand)+"]").attr("value")&&i.val(i.find("[value~="+unescape(a.phoneBrand)+
"]").attr("value")).trigger("change");a.phoneModel&&d.find(":contains("+unescape(a.phoneModel)+")").attr("value")&&d.val(d.find(":contains("+unescape(a.phoneModel)+")").attr("value")).trigger("change");$(".CaseFinderWidget .btnContinue a").click(function(){window.location=h.finderURL+(h.finderURL.search(/\?/)>0?"&":"?")+(i.val()&&i.val()!="select"?"phoneBrand="+i.val()+"&":"")+(d.val()&&d.val()!="select"?"phoneModel="+d.val():"");return false})};a.initRO.cb=function(h){$(".CaseFinderWidget .count").data("count",
h.total);$(".CaseFinderWidget .count").text(h.total);$(h.facets).each(function(){if(this.name!="category"&&(/^For/.test(this.name)||/^Pour/.test(this.name))){var l={};$(this.filters).each(function(){l[this.name]=this.count});k[this.name]=l;i.append($('<option class="val" value="'+this.name+'">'+this.name+"</option>"))}});c({finderURL:a.finderURL})};new api2.search(a.initRO)};
jQuery(document).ready(function(a){a("#glb-top-menu").buildMenu();a("#glb-top-menu").mouseout(function(){a(".node-1 ul").hide()});var k=util.cookie.getCookie("bbyca_mob_optout_fs")||"false",i=util.url.qs("fullsite")||"false";if(/(PlayBook|Android|iPod|iPhone|BlackBerry|iPad)/gi.test(navigator.userAgent)){k=="false"&&i=="true"&&util.cookie.createCookie("bbyca_mob_optout_fs","true",30);k=Math.min(screen.width,screen.height)>599;a("#hdr-back-to-mobile, #ftr-back-to-mobile").addClass(k?"show-tablet-link":
"show-mobile-link").show()}});

