function lastCategory(a){$.cookie("lastCategory",a,{expires:31,path:"/"})}function setupNextPreviousProduct(){var b=$("div#productsCont img.productImg");var a="";var c=true;if(b.length>1){$.each(b,function(d,e){if(c){a=a+$(e).attr("id").split("_")[1];c=false}else{a=a+","+$(e).attr("id").split("_")[1]}});$.cookie("nextPreviousIds",a,{expires:31,path:"/"})}}$(document).ready(function(){if($("div.productCont").length>0){$("ul#applyFilter").frescaFilter();setupNextPreviousProduct()}});(function(a){a.fn.frescaFilter=function(c){var h=a(this);var m;var n;var i={};var f={};var b=0+a("div.productCont").length;k();h.find("li a").click(function(t){t.preventDefault();if(!a(this).hasClass("filterDisabled")){s(a(this));g();e();j()}return false});q();function s(t){t.toggleClass("filterSelected");if(t.parents("li.filterGroup").find("a.filterSelected").length>0){t.parents("li.filterGroup").addClass("filterGroupActive")}else{t.parents("li.filterGroup").removeClass("filterGroupActive")}}function g(){a("div.productCont").removeClass("filterExclude");a("div.productCont").removeClass("partialExclude");h.find(".filterGroupActive").each(function(){a("div.productCont").addClass("partialExclude");a(this).find("a.filterSelected").each(function(){a("div."+a(this).attr("id")).removeClass("partialExclude")});a("div.partialExclude").addClass("filterExclude")})}function o(){var u,t;a("div.productCont").removeClass("priceExclude").each(function(w,v){u=parseInt(a(this).attr("class").split(" ")[1].replace(/fMAXPRICE/,"")*100);t=parseInt(a(this).attr("class").split(" ")[2].replace(/fMINPRICE/,"")*100);if(i.currentMinPrice>u||i.currentMaxPrice<t){a(this).addClass("priceExclude")}})}a("input[name='sortOrder']").click(function(t){t.preventDefault();l(a(this).attr("id"))});function k(){a(".hideFilter").remove()}function l(t){var u=[];a("div.productCont").each(function(w){var y={};y.el=a(this);var x=a(this).attr("class").split(" ");for(var w=0;w<x.length;w++){var v=jQuery.trim(x[w]);if(v.substring(0,9)==="fMAXPRICE"){y.fMaxPrice=new Number(parseInt(v.replace(/fMAXPRICE/,"")*100))}if(v.substring(0,9)==="fMINPRICE"){y.fMinPrice=new Number(parseInt(v.replace(/fMINPRICE/,"")*100))}if(v.substring(0,11)==="fSORTPRICE_"){y.sortValue=new Number(parseInt(v.replace(/fSORTPRICE_/,""),10));break}}u.push(y)});switch(t){case"apriceSearch":u=d(u);break;case"dpriceSearch":u=r(u);break;default:break}a("div#productsCont").empty();a.each(u,function(v){a("div#productsCont").append(this.el)});e()}function r(w){for(var v=0;v<w.length;v++){for(var t=0;t<(w.length-1);t++){if(w[t].fMinPrice<w[t].sortValue){if(w[t].fMinPrice>w[t+1].sortValue){var u=w[t+1];w[t+1]=w[t];w[t]=u;w[t].sortValue=w[t].fMinPrice}}else{if(w[t].sortValue>w[t+1].sortValue){var u=w[t+1];w[t+1]=w[t];w[t]=u}}}}return w}function d(w){for(var v=0;v<w.length;v++){for(var t=0;t<(w.length-1);t++){if(w[t].fMaxPrice>w[t].sortValue){if(w[t].fMaxPrice<w[t+1].sortValue){var u=w[t+1];w[t+1]=w[t];w[t]=u;w[t].sortValue=w[t].fMaxPrice}}else{if(w[t].sortValue<w[t+1].sortValue){var u=w[t+1];w[t+1]=w[t];w[t]=u}}}}return w}function e(){a("div.categoryRowDivider").remove();a("div.productLast").removeClass("productLast");a("#productsCont").prepend('<div class="categoryRowDivider">&nbsp;</div>');var t=0;a("div.productCont:visible").each(function(u){t++;if(t%4===0){a(this).addClass("productLast");a(this).after('<div class="categoryRowDivider">&nbsp;</div>')}})}function j(w){var u,x,t,v;var y=a("div.productCont");h.find("a").not(".sort").each(function(z){v=a(y).filter("."+a(this).attr("id")).not(".priceExclude");t=a(this).parents("li.filterGroup");a(t).siblings(".filterGroupActive").each(function(){a(this).find("a.filterSelected").each(function(){a(v).filter("."+a(this).attr("id")).addClass("partialInclude")});v=a(v).filter(".partialInclude").removeClass("partialInclude")});count=v.length;if(count>0){a(this).removeClass("filterDisabled");if(a(this).parent("li").parent("ul").hasClass("filterImage")){a(this).css("opacity",1)}}else{a(this).removeClass("filterSelected").addClass("filterDisabled");if(a(this).parent("li").parent("ul").hasClass("filterImage")){a(this).css("opacity",0.3)}}});p()}function p(){var t=a("div.productCont:visible").length;a("span.jsProdCount").empty().append(t)}function q(){h.append('<li class="filterGroup" id="fPRICE_SLIDE"><p class="heading">Shop by price range</p><div class="sliderCont"><div id="priceSlider"><div id="leftSliderHandle" class="ui-slider-handle">&nbsp;</div><div id="rightSliderHandle" class="ui-slider-handle">&nbsp;</div><span id="sliderMinPrice">&nbsp;</span><span id="sliderMaxPrice">&nbsp;</span></div></div></li>');var x=a("div#minMaxPricing").attr("class");var v=x.split("_");i.minPrice=parseInt(Math.floor((v[0].replace(/MIN/,"")))*100);i.maxPrice=parseInt(Math.ceil((v[1].replace(/MAX/,"")))*100);var t=i.minPrice;var u=i.maxPrice;a("span#sliderMinPrice").append("&pound;"+parseFloat(i.minPrice/100).toFixed(2));a("span#sliderMaxPrice").append("&pound;"+parseFloat(i.maxPrice/100).toFixed(2));var w=a("div#priceSlider").slider({min:i.minPrice,max:i.maxPrice,values:[i.minPrice,i.maxPrice],range:true,step:100,stop:function(z,y){(y.handle.id==="leftSliderHandle")?i.currentMinPrice=y.value:i.currentMaxPrice=y.value;o();e();j("priceFilter")},slide:function(z,y){if(y.handle.id=="leftSliderHandle"){i.currentMinPrice=y.value;a("span#sliderMinPrice").html("&pound;"+parseFloat(i.currentMinPrice/100).toFixed(2))}else{i.currentMaxPrice=y.value;a("span#sliderMaxPrice").html("&pound;"+parseFloat(i.currentMaxPrice/100).toFixed(2))}}})}}})(jQuery);