$(document).ready(function(){$("<li class='filterGroup' id='sortPrice'><span class='filterTitle'>Sort by price</span><ul class='filterOptions'><li><a href='#' id='priceDesc' class='sort'>Highest</a></li><li><a href='#' id='priceAsc' class='sort'>Lowest</a></li></ul></li>").appendTo("#applyFilter");$('<a href="#" id="resetFilters">Reset</a>').appendTo("#applyFilter").click(function(){location.reload(true)});$("#applyFilter").frescaFilter();$("a","#fAVAILABLE_SIZE").click(function(){$(this).parent().toggleClass("on")});$("a","#fMASTER_COLOUR").click(function(){$(this).parent().toggleClass("on")});$("#priceAsc").click(function(){d("asc");productHover();if($("#priceDesc").attr("class").split(" ").slice(1,2)=="filterSelected"){$("#priceDesc").removeClass("filterSelected")}$(this).addClass("filterSelected");return false});$("#priceDesc").click(function(){d("desc");productHover();if($("#priceAsc").attr("class").split(" ").slice(1,2)=="filterSelected"){$("#priceAsc").removeClass("filterSelected")}$(this).addClass("filterSelected");return false});function d(e){var f=[];$(".productCont","#productsCont").each(function(g){var h={};h.el=$(this);h.sortValue=parseInt($(this).find("span.nowPrice").text().replace(/[^0-9]/g,""),10);f.push(h)});switch(e){case"asc":f=a(f);break;case"desc":f=c(f);break;default:break}$("#productsCont").empty();$.each(f,function(g){$("#productsCont").append(this.el)});b()}function b(){var f=$(".productCont:visible","#productsCont");var e=cookieRequest.replace("view_","");f.removeClass("firstInRow").removeClass("lastInRow");divCounter=1;f.each(function(){if(((e==""||e==null)&&divCounter%4==1)||divCounter%e==1){$(this).addClass("firstInRow")}if(((e==""||e==null)&&divCounter%4==0)||divCounter%e==0){$(this).addClass("lastInRow")}divCounter++})}function a(h){for(var g=0;g<h.length;g++){for(var e=0;e<(h.length-1);e++){if(h[e].sortValue>h[e+1].sortValue){var f=h[e+1];h[e+1]=h[e];h[e]=f}}}return h}function c(h){for(var g=0;g<h.length;g++){for(var e=0;e<(h.length-1);e++){if(h[e].sortValue<h[e+1].sortValue){var f=h[e+1];h[e+1]=h[e];h[e]=f}}}return h}});(function(a){a.fn.frescaFilter=function(c){var h={prodContClass:"productCont"};var f=a.extend(h,c);var e=a(this);e.find("#fMASTER_COLOUR li a, #fAVAILABLE_SIZE li a").click(function(j){j.preventDefault();if(!a(this).hasClass("filterDisabled")){i(a(this));g(a(this));d();b(a(this));setupNextPrevious()}});function i(j){a("div."+f.prodContClass).css("display","block").removeClass("totalExclude, partialExclude");j.toggleClass("filterSelected");if(j.parents("li.filterGroup").find("a.filterSelected").length>0){j.parents("li.filterGroup").addClass("filterGroupActive")}else{j.parents("li.filterGroup").removeClass("filterGroupActive")}}function g(j){e.find(".filterGroupActive").each(function(){a("div."+f.prodContClass).addClass("partialExclude");a(this).find("a.filterSelected").each(function(){a("div."+a(this).attr("id")).removeClass("partialExclude")});if(a("#cmsContent").length>0){a("#cmsContent").remove()}a("div.partialExclude").css("display","none")})}function d(){var k=a(".productCont:visible","#productsCont");var j=cookieRequest.replace("view_","");k.removeClass("firstInRow").removeClass("lastInRow");divCounter=1;k.each(function(){if(((j==""||j==null)&&divCounter%4==1)||divCounter%j==1){a(this).addClass("firstInRow")}if(((j==""||j==null)&&divCounter%4==0)||divCounter%j==0){a(this).addClass("lastInRow")}divCounter++})}function b(o){var k,m,j,l;var n=a("div."+f.prodContClass);e.find("a").not(".sort").each(function(p){l=a(n).filter("."+a(this).attr("id"));j=a(this).parents("li.filterGroup");a(j).siblings(".filterGroupActive").each(function(){a(this).find("a.filterSelected").each(function(){a(l).filter("."+a(this).attr("id")).addClass("partialInclude")});l=a(l).filter(".partialInclude").removeClass("partialInclude")});k=0+l.length;(k>=1)?a(this).removeClass("filterDisabled").next("span").html(k):a(this).removeClass("filterSelected").addClass("filterDisabled").next("span").html("0")});totalProducts=a(n).filter(":visible");a("span#counterNumber").html(totalProducts.length)}}})(jQuery);
