function prependSign(a){if(a==""){return a+"?"}else{return a+"&"}}function decode(a){return decodeURIComponent(a.split("+").join(" "))}function getQueryVariables(){var a={};document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g,function(){a[decode(arguments[1])]=decode(arguments[2])});return a}function pricePresent(){price_min=Math.floor(price_min);price_left=Math.floor(price_left);price_max=Math.ceil(price_max);price_right=Math.ceil(price_right);if(price_min==price_max){return false}else{return true}}function init(){vault=new Vault();vault.getUrlVars()}window.onload=init;function Vault(){this.getUrlVars=function(){var d=[],c;var e=window.location.href.indexOf("?");if(e==-1){return[]}var a=window.location.href.slice(e+1).split("&");for(var b=0;b<a.length;b++){c=a[b].split("=");d.push(c[0]);if(c[1]){d[c[0]]=c[1]}}return d};this.urlVars=this.getUrlVars();this.setVar=function(c,b){var a=this.urlVars[c];if(a){a=b}else{this.urlVars.push(c);this.urlVars[c]=b}};this.getVar=function(b){var a=this.urlVars[b];if(a){return a}else{return null}};this.getUrl=function(){url="";var b="";var c="";for(var a=0;a<this.urlVars.length;a++){if(a==0){url+="?"}else{url+="&"}b=this.urlVars[a];c=this.urlVars[b];url+=b+"="+c}return url}}(function(a){a.fn.exists=function(){return a(this).length>0&&!a(this).is(":hidden")};a.fn.toggleButton=function(){var c=a(this);var b=c.html();if(b=="Hide"){b="Show"}else{if(b=="Show"){b="Hide"}}c.toggleClass("Show").html(b);return this};a(document).ready(function(){a("div.Content-Wide a[rel=toggleContainer]").click(function(b){a(this).closest(".Content-Wide").slideToggle();b.preventDefault()});a("div.Content-Wide a[rel=toggleContent]").click(function(b){a(this).toggleButton().closest(".Content-Wide").find(".Content-Wide-Content").slideToggle();b.preventDefault()});a("a[rel=viewAll]").click(function(b){vault.setVar("itemsperpage",99999);document.location.href=vault.getUrl();b.preventDefault()})});a.fn.simpleLightBox=function(c){var b=a(this);b.click(function(d){d.preventDefault();if(a(".Simple-Lightbox").length>0){a(".Simple-Lightbox").remove()}a.ajax({url:c,dataType:"html",success:function(e){a("body").append(e);a(".Simple-Lightbox").fadeIn()}});a(".Simple-Lightbox").fadeIn()});a(".Simple-Lightbox-Close").live("click",function(){a(".Simple-Lightbox").fadeOut()})};a.fn.checkRequired=function(){var c=a(this).find("form");var b=0;c.submit(function(){c.find(":input.required").each(function(){b=0;if(a(this).val()===""||a(this).val()==="Required"){a(this).addClass("error");a(this).val("Required");b=1}else{a(this).removeClass("error")}});if(b===1){return false}});c.find(":input.required").live("focus",function(){if(a(this).val()==="Required"){a(this).val("");a(this).removeClass("error")}})};a.fn.productSuggestions=function(f){var d=this;var g=null;var f=a.extend({dataFile:"!autocomplete.xml",suggestionsCallback:"master-callback-productsuggestions.html",minLength:2,delay:300,limit:5},f);c();return d.each(function(){a(this).autocomplete({source:g,minLength:f.minLength,delay:f.delay,position:{my:"left top",at:"left bottom"},open:function(h,i){e(this.value)},focus:function(h,i){this.value=i.item.value},select:function(h,i){a(this).parents("form:first").submit()}});b(a(this))});function c(){a.ajax({url:"/"+f.dataFile,dataType:"xml",async:false,success:function(h){g=a("item",h).map(function(){return a("title",this).text()}).get()}})}function b(h){$list=a("<div></div>").attr("id","Product-Suggestions").css("display","none").css("position","absolute").css("z-index","99999").appendTo(a("body"));var j=undefined;var l=0;var k=0;var i=null;h.keyup(function(){if(h.val().length<f.minLength){$list.hide();return}if(j!=undefined){clearTimeout(j)}a.ajax({url:"/"+f.suggestionsCallback+"?searchquery="+h.val()+"&searchmaxreturn="+f.limit,dataType:"html",success:function(m){i=m}});j=setTimeout(function(){offset=h.offset();l=offset.left;k=h.outerHeight()+offset.top;if(a(".ui-autocomplete").css("display")=="block"){k+=a(".ui-autocomplete").outerHeight()}if(a.trim(i).length>0){$list.html(i);$list.css("left",l+"px");$list.css("top",k+"px");$list.show()}},f.delay)});h.blur(function(){if(j!=undefined){clearTimeout(j)}j=setTimeout(function(){$list.hide()},100)})}function e(h){a("ul.ui-autocomplete li a").each(function(){a(this).html(a(this).html().replace(new RegExp(h.toLowerCase(),"gi"),'<span class="highlight">'+h.toLowerCase()+"</span>"))})}};a.fn.brandSlider=function(e){var f=this;var d=0;var e=a.extend({interval:5000,speed:1000},e);return this.each(function(){var h=a(this);g(h);setTimeout(function(){c(h)},e.interval)});function g(h){var j=a("li",h).size();var i=a("li",h).outerWidth(true);h.css("width",(1+j)*i)}function c(h){b(h);d=setTimeout(function(){c(h)},e.interval)}function b(h){var i=a("li",h).outerWidth(true);var k=a("li:first",h);var j=a("li:last",h);k.clone().appendTo(h);h.animate({left:-i},e.speed,function(){k.remove();h.css("left",0)})}};a.fn.tabbedContainer=function(b){var d=this;var b=a.extend({},b);return this.each(function(){c(a(this))});function c(e){a(".Tabs a",e).each(function(f){a(this).click(function(i){var h=f;a(".Tabs a",e).each(function(j){if(j==h){a(this).addClass("Selected")}else{a(this).removeClass("Selected")}});a(".Tab-Content",e).each(function(j){if(j==h){a(this).removeClass("Deselected")}else{a(this).addClass("Deselected")}});var g=a(this).attr("href");if(g==""||g=="#"){i.preventDefault()}})});if(!a(".Tabs a",e).hasClass("Selected")){a(".Tabs a:first",e).addClass("Selected")}a(".Tab-Content:gt(0)",e).addClass("Deselected")}};a.fn.dropdowns=function(b){var c=this;var b=a.extend({},b);return this.each(function(){d(a(this))});function d(e){a("li a",e).each(function(){var g=a(this).parent().find("ul");var f=a(this);a(this).mouseenter(function(){g.show();f.addClass("hover")});a(this).mouseleave(function(){g.hide();f.removeClass("hover")});g.hover(function(){a(this).show();f.addClass("hover")});g.mouseleave(function(){a(this).hide();f.removeClass("hover")})})}};a.fn.advancedSearch=function(c){var e=this;var c=a.extend({key:"cfsearch",value:"cfvalue",def_searchquery:"Enter Keywords Here..."},c);return this.each(function(){b(a(this))});function b(f){var g=a("form",f);g.submit(function(h){h.preventDefault()});if(a("input[name='searchquery']",f).exists()){a("input[name='searchquery']",f).keypress(function(h){if(h.which==13){d(g)}})}if(a("input[type=submit]",f).exists()){g.submit(function(h){d(g);h.preventDefault()})}else{if(a("input[type=button]",f).exists()){a("input[type=button]",f).click(function(h){d(g);h.preventDefault()})}}}function d(k){var g=k.attr("action");var l="";var h=1;var f="";var j="";a("option:selected",k).each(function(){if(a(this).val()!="-1"){f=a(this).parent().attr("name");if(f=="searchPrice"){l=prependSign(l)+f+"="+a(this).val()}else{if(f=="Category"){j=a(this).val()}else{l=prependSign(l)+c.key+h+"="+f+"&"+c.value+h+"="+a(this).val();h++}}}});a("input[name=searchquery]",k).each(function(){if(a(this).val()!=""&&a(this).val()!=c.def_searchquery){l=prependSign(l)+"searchquery="+a(this).val()}});if(l!=""||j!=""){document.location.href="/"+(j==""?g:"")+j+l}}};a.fn.filterAction=function(c){var d=this;var b=getQueryVariables();var c=a.extend({key:"cfsearch",value:"cfvalue"},c);return this.each(function(){if(a(this).is("select")){a(this).change(function(){e()})}else{if(a(this).is("div")){e()}else{a(this).click(function(){e()})}}});function e(){var g="";var j=null;var h=1;a("#Menu-Filter table").each(function(){var k=a(this).attr("id");var i=0;a(this).find("input:checked").each(function(){j=a(this).attr("name");if(i==0){g=prependSign(g)+c.key+h+"="+k+"&"+c.value+h+"="+j;h++}else{g+=","+j}i++})});if(a("#Slider-Price-Range").exists()){price_left=a("#Slider-Price-Range").slider("values",0);price_right=a("#Slider-Price-Range").slider("values",1)}if(a("select[name=searchPrice]").exists()&&a("select[name=searchPrice]").val()!="-1"&&(!a("#Slider-Price-Range").exists()||b.searchPrice!=a("select[name=searchPrice]").val())){g=prependSign(g)+"searchPrice="+a("select[name=searchPrice]").val()}else{if(price_min!=price_left||price_right!=price_max){j=price_left+"t"+price_right;g=prependSign(g)+"searchPrice="+j}}if(categoryID!=""){g=prependSign(g)+"catid="+categoryID}if(vault.getVar("searchquery")!=null){g=prependSign(g)+"searchquery="+vault.getVar("searchquery")}if(b.itemsperpage=="99999"||a(".View-All").attr("name")=="clicked"){g=prependSign(g)+"itemsperpage=99999"}if(a("select[name=SearchSortBy]").val()!="-1"){g=prependSign(g)+"SearchSortBy="+a("select[name=SearchSortBy]").val()}f(g)}function f(g){a("#LoadingBG").css("top",a(document).scrollTop()).css("display","block");document.location.href=g}};a.fn.viewAll=function(c){var d=this;var b=getQueryVariables();var c=a.extend({},c);return this.each(function(){e(a(this))});function e(f){f.click(function(){f.attr("name","clicked")})}};a.fn.sortFilter=function(c){var e=this;var b=getQueryVariables();var c=a.extend({},c);return this.each(function(){d(a(this))});function d(f){if(b.SearchSortBy){a("select[name=SearchSortBy] option[value="+b.SearchSortBy+"]",f).attr("selected","selected")}if(b.searchPrice){a("select[name=searchPrice] option[value="+b.searchPrice+"]",f).attr("selected","selected")}a("select",f).filterAction()}};a.fn.menuFilter=function(e){var f=this;var b=getQueryVariables();var d=pricePresent();var e=a.extend({key:"cfsearch",value:"cfvalue",keyRange:"cfrangename",valRange:"cfrangevalue"},e);return this.each(function(){c(a(this))});function c(g){var j=1;while(true){if(b[e.key+j]&&b[e.key+j]||b[e.keyRange+j]&&b[e.valRange+j]){var h=b[e.value+j].split(",");for(var k in h){a("input[name='"+h[k]+"']",g).attr("checked",true);anchor_item=a("<a></a>").addClass("Filter-Close").attr("href",h[k]);new_item=a("<p></p>").addClass("Filter-Selection").text(h[k]);a("#Selection div").append(new_item).append(anchor_item);a("#td"+h[k]).addClass("hover");a("#th"+h[k]).addClass("hover")}j++;continue}break}if(j>1){a("#Selection",g).show();a("#Selection a",g).click(function(i){a("input[name="+a(this).attr("href")+"]",g).attr("checked",false);i.preventDefault()});a("#Selection a",g).filterAction()}a("input",g).filterAction();if(d){if(b.searchPrice){prices=b.searchPrice.split("t");prices[0]=parseInt(prices[0]);prices[1]=parseInt(prices[1]);if(prices[0]<=prices[1]){if(prices[0]>price_min&&prices[0]<price_max){price_left=prices[0]}if(prices[1]>price_min&&prices[1]<price_max){price_right=prices[1]}}}a("#Slider-Price-Range",g).slider({range:true,min:price_min,max:price_max,values:[price_left,price_right],slide:function(i,l){a("#Price-Left",g).html("&pound;"+l.values[0]);a("#Price-Right",g).html("&pound;"+l.values[1])},change:function(i,l){a(this).filterAction()}});a("#Price-Left",g).html("&pound;"+a("#Slider-Price-Range").slider("values",0));a("#Price-Right",g).html("&pound;"+a("#Slider-Price-Range").slider("values",1))}else{a("#Price",g).hide()}}}})(jQuery);
