var GLOBALS=new Object();GLOBALS.vehicleSelector=null;$.browser.chrome=/chrome/.test(navigator.userAgent.toLowerCase());
function restoreDefaultValue(e)
{var fld=e.target?e.target:e;if(!fld.value)
{fld.value=fld.defaultValue;}
return void(0);}
function clearDefaultValue(e)
{var fld=e.target?e.target:e;if(fld.value==fld.defaultValue)
fld.value='';return void(0);}
function showVehicleMissing()
{alert("If your make, model, year, or vehicle details do not appear, this product\n"+
"may be not be available for your vehicle.  In that case,\n"+
"you can find similar products at the left of your screen,\n"+
"or call our customer service and product specialists\n"+
"at 1-800-663-1570.\n");return void(0);}
function array_keys(obj){var rv=new Array();for(var key in obj){if(obj.hasOwnProperty(key))
rv.push(key);}
return rv;}
function count_keys(obj){var size=0;for(var key in obj){if(obj.hasOwnProperty(key))size++;}
return size;}
function trim(s)
{var l=0;var r=s.length-1;while(l<s.length&&s[l]==' '){l++;}
while(r>l&&s[r]==' ')
{r-=1;}
return s.substring(l,r+1);}
function replaceMixedNumbers(str)
{var brake=10;var mixedNum=new RegExp('([0-9]+)[ -]+([0-9]+)/([0-9]+)','');do{brake--;var result=mixedNum.exec(str);if(!result)
{return str;}
var mval=+(result[1]);var over=+(result[2]);var under=+(result[3]);if(+(result[3])>0)
{mval=(+mval)+(+(over/under));}
str=str.replace(result[0],mval);}while(brake>0);return str;}
function compareByWords(a,b){var awords=replaceMixedNumbers(a).replace('-',' ').split(' ');var bwords=replaceMixedNumbers(b).replace('-',' ').split(' ');var rv=0;for(var i=0;i<awords.length&&i<bwords.length;i++)
{var w1=awords[i];var w2=bwords[i];if(w1==w2)
continue;if(isNaN(w1)&&isNaN(w2))
{rv=(w1<w2)?-1:1;}else if(isNaN(w1)){rv=1;}else if(isNaN(w2)){rv=-1;}else{w1=1*w1;w2=1*w2;rv=(w1<w2)?-1:1;}
if(rv!=0)
return rv;}
if(awords.length<bwords.length)
return-1;if(awords.length>bwords.length)
return 1;return 0;}
var allFormObjects=new Array();function findFormObject(id,noisy){var rv=allFormObjects[id];if(rv)
return rv;var f=document.getElementById(id);if(f&&f.formObject)
return f.formObject;if(noisy)
alert("Cannot find form object: "+id);return rv;}
FormObject.prototype.getMasterDocument=function(noisy){var mm=this.getMaster(noisy);return mm?mm.document:null;}
FormObject.prototype.getMaster=function(noisy){if(!this.master)
{if(window.opener&&window.opener.document)
this.master=window.opener;else if(window.parent&&window.parent.document)
this.master=window.parent;else if(noisy)
alert("cannot determine master document");}
return this.master;}
FormObject.prototype.getMasterField=function(id,noisy){var m=this.getMaster();var outfield=m.$?m.$('#'+id):$(m.document).find('#'+id);if(outfield&&outfield[0])
return outfield;outfield=m.find('input[name='+id+']');if(outfield&&outfield[0])
return outfield;if(noisy)
{alert("cannot find "+id+" in master document "+m[0].location);}
return null;}
FormObject.prototype.putIntoMaster=function(id,val,noisy){var outfield=this.getMasterField(id,noisy);if(outfield&&outfield[0])
{outfield[0].value=val;outfield.change();return true;}
return false;}
FormObject.prototype.getField=function(fieldname,noisy){var rv=null;if(typeof fieldname=="string")
{rv=this.form[0].elements[fieldname];}else if(typeof fieldname=="object"){rv=fieldname;}else{alert("getField:unknown type "+(typeof fieldname)+" for form field "+fieldname);}
if(rv)
return rv;if(noisy)
alert("cannot find form field "+fieldname);return null;}
FormObject.prototype.getFieldValue=function(fieldname,noisy){var f=this.getField(fieldname,noisy);if(f)
return f.value;return undefined;}
FormObject.prototype.putFieldValue=function(fieldname,newval){var f=this.getField(fieldname,true);if(f)
{f.value=newval;}
return f;}
FormObject.prototype.handleFocus=function(evt){return this;}
FormObject.prototype.handleClick=function(evt){return this._handleChange(evt);}
FormObject.prototype.handleChange=function(evt){return null;}
FormObject.prototype._handleChange=function(evt){this.handleChange(evt);var widget=evt.target?evt.target:evt;if(widget.value!=widget.defaultValue)
this.markChanged(widget);var $w=$(widget);if($w.hasClass('suggestor'))
{var targetid=widget.id.replace('-suggestor','');if(targetid&&targetid!=widget.id)
{var f=this.getField(targetid);if(f)
{f.value=$w.val();$(f).trigger('change');}}}
return void(0);}
FormObject.prototype.handleBlur=function(evt){return this;}
FormObject.prototype.handleKeyUp=function(evt){return this;}
FormObject.prototype.handleSubmit=function(evt){return true;}
FormObject.prototype.dumpForm=function(){for(var i=0;i<f.elements.length;i++)
{var e=f.elements[i];if(window.console)
window.console.log(e.name+" is '"+e.value+"'");}
return true;}
FormObject.prototype.bindWidgets=function(widgets){var me=this;widgets.not('input[type=radio]').not('input[type=checkbox]').bind('change',function(evt){me._handleChange(evt)}).bind('keyup',function(evt){me.handleKeyUp(evt)}).bind('blur',function(evt){me.handleBlur(evt)}).bind('focus',function(evt){me.handleFocus(evt)});widgets.filter('input[type=radio]').bind('click',function(evt){me.handleClick(evt)});widgets.filter('input[type=checkbox]').bind('click',function(evt){me.handleClick(evt)});widgets.filter('button').bind('click',function(evt){me.handleClick(evt)});return widgets;}
FormObject.prototype.bindEverything=function(){if(!this.allwidgets)
{this.allwidgets=this.form.find('input,select,textarea,button');}
var me=this;this.bindWidgets(this.allwidgets);this.form.bind('submit',function(evt){return me.handleSubmit(evt);});return this;}
FormObject.prototype.getValuesBySuffix=function(suffix){var rv=new Array();for(var w in this.allwidgets)
{var widget=this.allwidgets[w];var name=widget.name?widget.name:widget.id;if(name&&(name.indexOf(suffix)>0))
{var pos=name.indexOf(suffix);var frag=name.substr(0,pos);if(frag+suffix==name)
{rv[frag]=widget.value;}}}
return rv;}
FormObject.prototype.markChanged=function(f){var field=this.getField(f,false);if(field)
{if(field.value==field.defaultValue)
{$(field).removeClass('changed');return false;}else{$(field).addClass('changed');return true;}}
return void(0);}
FormObject.prototype.assembleQueryString=function(){var elems=this.form[0].elements;var qs='';for(var i=0;i<elems.length;i++)
{var e=elems[i];if(e.name)
{qs=qs+e.name+'='+escape($(e).val())+'&';}}
return qs;}
FormObject.prototype.ajaxSubmitCallback=function(tree){return void(0);}
FormObject.prototype.ajaxSubmit=function(){this.throbber.show('fast');var qs=this.assembleQueryString();var url=this.form[0].action+'?'+qs;var me=this;jQuery.get(url,{},function(xmltree){return me.ajaxSubmitCallback(xmltree);});return this;}
FormObject.prototype.setupAjaxSubmit=function(expr){var button=this.form.find(expr);var me=this;button.bind('click',function(){me.ajaxSubmit();});if(button[0]&&button[0].form)
{$(button[0].form).bind('submit',function(){me.ajaxSubmit();return false;});}
this.throbber=$('#'+this.formid+'-throbber');this.throbber.hide('fast');return this;}
function FormObject()
{return this;}
FormObject.prototype.init=function(formid1){this.formid=formid1;this.form=$('#'+formid1);allFormObjects[formid1]=this;this.allwidgets=this.form.find('input,select,textarea,button');if(!this.form[0])
{alert("Cannot find form "+formid1);return this;}else{this.form.addClass("formObject");this.form.formObject=this;}
return this;}
VehicleSelector.prototype.getWidget=function(fieldname){var f=this.jqForm[0];return f.elements[fieldname];}
VehicleSelector.prototype.getFieldValue=function(fieldname){var w=this.getWidget(fieldname);if(w!=null)
return w.value;return"";}
VehicleSelector.prototype.putFieldValue=function(fieldname,newval){var w=this.getWidget(fieldname);if(w!=null)
w.value=newval;return w;}
VehicleSelector.prototype.buildURL=function(pos){var url="";for(var i=0;(i<pos)&&(i<this.selectors.length);i++)
{var s=this.selectors[i];var val=s.selectedValue;url=url?url+"&":"";url=url+s.name+"="+val;if(val==0)
return'';}
if(pos<this.selectors.length)
{var s=this.selectors[pos];url=url+"&want="+s.name;}
url="/aag/ajax/vehicle-list.do?"+url;url=url+"&groupId="+this.getFieldValue("groupId");url=url+"&pn="+this.getFieldValue("pn");url=url+"&tcid="+this.getFieldValue("tcid");url=url+"&catid="+this.getFieldValue("catid");url=url+"&scid="+this.getFieldValue("scid");return url;}
VehicleSelector.prototype.getWidgetOrdinal=function(name){for(var i=0;i<this.selectorNames.length;i++)
{if(this.selectorNames[i]==name)
return i;}
return-1;}
VehicleSelector.prototype.getSelector=function(pos){return this.selectors[pos];}
VehicleSelector.prototype.clearSelector=function(pos){var s=this.getSelector(pos);if(s)
{for(var i=s.elem.options.length-1;i>0;i--)
s.elem.remove(i);s.widget.removeClass('vselector-full').addClass('vselector-empty');}
return this;}
VehicleSelector.prototype.displaySelection=function(desc){if(desc)
{$('#stored-vehicle').html('<span class="ok">Your Vehicle: '+desc+
' (<a href="#" onClick="VehicleSelector_reveal()">change</a>)</span>');$('.stored-vehicle-secondary').html('<span class="ok">'+desc+'</span>');}else{$('#stored-vehicle').html('');$('.stored-vehicle-secondary').html('');}}
VehicleSelector.prototype.callbackSetVehicle=function(xmltree){this.hideThrobbers();var desc=$(xmltree).find('Description').text();var vpath=$(xmltree).find('Path').text();vpath=vpath.replace(' ','-');this.displaySelection(desc);var action=this.selectAction;if(action=="redirect")
{var loc=document.location.protocol+"//"+document.location.host;var p=document.location.port;if(p)
{loc=loc+":"+p;}
loc=loc+this.baseURL;loc=loc+"/_"+vpath;document.location.replace(loc);}
this.setState(7);}
VehicleSelector.prototype.hideThrobbers=function(){if(this.throbbers)
{this.throbbers.each(function(){this.src="/img/design/home-page/s.gif"});}}
VehicleSelector.prototype.showThrobber=function(label){if(this.throbbers)
{$('#'+label+"_throbber").each(function(){this.src="/img/design/ajax/load.gif"});}}
VehicleSelector.prototype.callbackPopulate=function(xmltree,selectorInfo,selectedValue){if(typeof selectedValue=="undefined")
selectedValue=-1;this.hideThrobbers();selectorInfo.optionZero.text(selectorInfo.caption);var objType=selectorInfo.name;var targetID=objType+"_list";var theList=$(xmltree).find('#'+targetID);if(!theList[0])
{return false;}
var mustEmbiggen=false;theList.children().each(function(){var node1=this.attributes.item(0);var node2=this.attributes.item(1);var node3=this.attributes.item(2);if(node1&&node2)
{var optValue=node1.value;var optName=node2.value;if(node2.name=='itemid')
{optName=node1.value;optValue=node2.value;}
if(node3.value.indexOf("H")>=0||node3.value.indexOf("W")>=0)
{}else{var txt='<option value="'+optValue+'">'+optName+'</option>';newNode=$(txt);newNode.appendTo(selectorInfo.widget);if(optName.length>30)
{mustEmbiggen=true;if($.browser.msie)
newNode[0].style.width="auto";}}}else{}});if(mustEmbiggen)
{if($.browser.msie)
{selectorInfo.widget[0].style.width="auto";}}
var listSize=theList.children().size();this.enableSelector(selectorInfo.ordinal,true);if(listSize<1)
{if(this.getFieldValue('pn'))
{this.putFieldValue('pn',0);}else if(this.getFieldValue('groupId')){this.putFieldValue('groupId',0);}else{alert("Sorry, no matching vehicle selections found.");}
this.populateSelector(selectorInfo.ordinal,-1);}else if(selectedValue>0){this.setSelection(selectorInfo.ordinal,selectedValue);}else if(listSize==1){if(this.getFieldValue('pn'))
{if(selectorInfo.ordinal<3)
{var selector=selectorInfo.widget[0];selector.options[1].selected=true;this.doSelect(selector);}}}}
VehicleSelector.prototype.enableSelector=function(pos,enabled){var selectorInfo=this.getSelector(pos);selectorInfo.elem.disabled=!enabled;if(enabled)
{selectorInfo.widget.removeClass('vselector-loading').removeClass('vselector-empty').addClass('vselector-full').addClass('eager');}}
VehicleSelector.prototype.populateSelector=function(pos,selectedValue){if(typeof selectedValue=="undefined")
selectedValue=-1;var s=this.getSelector(pos);var url=this.buildURL(pos);if(!url)
return void(0);s.elem.disabled=true;s.widget.addClass("vselector-loading");s.optionZero.text("loading...");this.showThrobber(s.name);var that=this;var grabber=function(){$.get(url,{},function(xmltree){that.callbackPopulate(xmltree,s,selectedValue);});return void(0);};grabber();}
VehicleSelector.prototype.doSelect=function(e){var widget=e.target?e.target:e;if(!widget||!widget.name)
{return false;}
var sinfo=this.getSelectorByName(widget.name);if(!sinfo)
{return false;}
sinfo.selectedValue=sinfo.elem.value;sinfo.widget.removeClass('eager');var pos=sinfo.ordinal;if(pos==this.selectors.length-1)
{this.saveVehicleSelection();}else{for(var i=pos+1;i<this.selectors.length;i++)
this.clearSelector(i);if(widget.value==-1)
{this.clearSelector(pos);var gid=this.getWidget("groupId");gid.value=0;this.populateSelector(pos,-1);}else{this.populateSelector(pos+1,-1);}}
return false;}
VehicleSelector.prototype.clearVehicleSelection=function(){this.displaySelection('');var url="/aag/ajax/set-vehicle.do?clear=1";jQuery.get(url,{},function(xmltree){});}
VehicleSelector.prototype.saveVehicleSelection=function(){var shortName="";var url="/aag/ajax/set-vehicle.do?groupId="+this.getFieldValue("groupId");for(var i=0;i<this.selectors.length;i++)
{var s=this.selectors[i];var v=s.selectedValue;url=url+"&"+s.name+"="+v;if(i<=2)
{shortName+=shortName?";":"";shortName+=v;}
this.showThrobber(s.name);}
var vs1=this;jQuery.get(url,{},function(xmltree){vs1.callbackSetVehicle(xmltree);});}
VehicleSelector.prototype.getSelectorByName=function(name1){for(var i=0;i<this.selectors.length;i++)
{var s=this.selectors[i];if(s.name==name1)
return s;}
alert("no selector "+name1);return null;}
VehicleSelector.prototype.addSelector=function(name1,title1){var ord=this.selectors.length;var w=this.getWidget(name1);if(!w)
{return 0;}
var stuff={ordinal:ord,name:name1,title:title1,elem:w,selectedValue:-1,widget:$(w)};stuff.optionZero=stuff.widget.find('.option-zero');stuff.caption=stuff.optionZero.text();this.selectors[ord]=stuff;if(ord>0)
{w.disabled=true;}
return this.selectors;}
VehicleSelector.prototype.setBaseURL=function(x){this.baseURL=x;}
VehicleSelector.prototype.setSelectAction=function(x){this.selectAction=x;}
VehicleSelector.prototype.setState=function(newState,speed){if(typeof speed==undefined)
speed='slow';if(newState==7||newState==0)
{this.altContent.each(function(){this.style.display='';}).show(speed);$('.vs-widget-part,.vs_widget').each(function(){this.style.display='none';});}else if(newState==1){$('#wrap-vs-make,#wrap-vs-model,#wrap-vs-year').show('fast');this.altContent.each(function(){this.style.display='none';});$('.vs-widget-part').each(function(){this.style.display='';}).show(speed);}else if(newState==4){this.altContent.each(function(){this.style.display='none';});this.enableSelector(3,true);$('#wrap-vs-make,#wrap-vs-model,#wrap-vs-year').hide(speed==0?0:'fast');$('#wrap-vs-fitment').show(speed);}else{alert("unknown state "+newState);}
this.displayState=newState;}
VehicleSelector.prototype.enableThrobbers=function(enabled){if(enabled)
{this.throbbers=this.jqForm.find('.ajaxthrobber');}else{this.throbbers=null;}}
VehicleSelector.prototype.setInitialSelection=function(ordinal,value){var selector=this.getSelector(ordinal);if(selector)
{selector.selectedValue=value;}}
VehicleSelector.prototype.setSelection=function(ordinal,value){var selector=this.getSelector(ordinal);if(!selector)
return false;var foundIt=false;for(var i=0;i<selector.elem.options.length;i++)
{var opt=selector.elem.options[i];if(opt.value==value)
{foundIt=true;opt.selected=true;}else{opt.selected=false;}}
return foundIt;}
VehicleSelector.prototype.handleGoButton=function(e){for(var i=0;i<this.selectors.length;i++)
{var s=this.selectors[i];var val=s.selectedValue;if(val<1)
{alert("Please select your "+s.title+" from the list.\n\n"+
"If your "+s.title+" does not appear, this product\n"+
"may be not be available for your vehicle.  In that case,\n"+
"you can find similar products at the left of your screen,\n"+
"or call our customer service and product specialists\n"+
"at 1-800-663-1570.\n");return void(0);}}
alert("See below for a list of matching products.");return void(0);}
VehicleSelector.prototype.finishSetup=function(){var groupid=this.getFieldValue("groupId");var tcid=this.getFieldValue("tcid");var scid=this.getFieldValue("scid");var catid=this.getFieldValue("catid");var makes=this.getSelector(0);if(!makes)
return null;var nchoices=makes.elem&&makes.elem.options?makes.elem.options.length:0;if(this.displayState<4)
{var myMake=makes.selectedValue;if((nchoices<2)||(tcid>0)||(scid>0)||(catid>0)||(groupid>0))
{this.clearSelector(0);this.populateSelector(0,myMake);}else{}}
var i;for(i=1;i<4;i++)
{var s=this.getSelector(i);if(s&&(s.selectedValue>0))
{}}
if(this.displayState==4)
{this.enableSelector(3,true);this.populateSelector(3);}
return void(0);}
function VehicleSelector(formId1,altContentId1,startupState,levels)
{this.displayState=-1;this.formid=formId1;this.jqForm=$('#'+formId1);this.throbbers=0;this.selectAction="";this.baseURL=document.location;this.altContent=altContentId1?$('#'+altContentId1):$('#ALTNOTFOUND');this.selectors=new Array();this.addSelector("make","Make");this.addSelector("model","Model");this.addSelector("year","Model Year");if(levels>3)
this.addSelector("fitment","Vehicle Details");var vSelector=this;this.jqForm.find('select').bind('change',function(evnt){return vSelector.doSelect(evnt);});$('#vs-go').bind('click',function(e){return vSelector.handleGoButton(e);});this.setState(startupState,0);}
function VehicleSelector_reveal()
{var myUrl=document.location.href;var oldvn=myUrl.indexOf("/_");if(oldvn>0)
myUrl=myUrl.substring(0,oldvn);if(myUrl.indexOf("?")>0)
{myUrl=myUrl+"&clear-vehicle=1";}else{myUrl=myUrl+"?&clear-vehicle=1";}
document.location=myUrl;return void(0);if(GLOBALS&&GLOBALS.vehicleSelector)
{GLOBALS.vehicleSelector.clearVehicleSelection();GLOBALS.vehicleSelector.setState(1);GLOBALS.vehicleSelector.setSelection(0,0);GLOBALS.vehicleSelector.setSelection(1,0);GLOBALS.vehicleSelector.setSelection(2,0);GLOBALS.vehicleSelector.setSelection(3,0);GLOBALS.vehicleSelector.clearSelector(0);GLOBALS.vehicleSelector.populateSelector(0);}else{document.location="/";}
return false;}

GroupPage.prototype.countCheckedBoxen=function(){var count=0;for(var i=0;i<this.checkBoxes.length;i++)
{if(this.checkBoxes[i].checked)
count=count+1;}
return count;}
GroupPage.prototype.validateMultiAddForm=function(evt){var checks=this.countCheckedBoxen();if(checks==0)
{if(this.checkBoxes.length<1)
return true;alert("Select the item(s) you'd like from the list by checking the box next to each.\n"+
" Be sure to select front and rear, or left and right, as appropriate.");return false;}
return true;}
GroupPage.prototype.showGroupReviews=function(evt){var w=evt.target?evt.target:evt;var classes=w.className.split(' ');for(var i in classes)
{var cl=classes[i];if(0==cl.indexOf("reviews-group-"))
{var gid=cl.replace("reviews-group-",'');}}
return void(0);}
function GroupPage()
{var me=this;this.checkBoxes=$('.checkbox-add');$('#group-add-multiple').bind('submit',function(evt){return me.validateMultiAddForm(evt)});$('.get-reviews').click(function(evt){return me.showGroupReviews(evt);});}
function SubCategoryFilterItem(scpage,attributeName,checkbox){this.innerId=checkbox.id.replace("filter-show-"+attributeName+"-",'');this.attributeName=attributeName;this.checkbox=$(checkbox);this.listItem=this.checkbox.parent();this.label=this.listItem.find('label');this.labelText=this.label.text();this.countSpan=this.label.find('.filter-count');this.oldCount=this.countSpan.text().replace('(','').replace(')','');this.passCount=0;this.failCount=0;this.touchedFilterCheckbox=null;return this;}
function SubCategoryFilterGroup(filterName,scpage){this.filterName=filterName;this.container=$('#filtergroup-'+filterName);this.boxen=$('input.show-'+filterName);this.selectedCount=0;this.filters=new Array();for(var i=0;i<this.boxen.size();i++)
{var filter=new SubCategoryFilterItem(scpage,filterName,this.boxen[i]);this.filters[filterName+"-"+filter.innerId]=filter;scpage.allFilterItems[this.boxen[i].id]=filter;}
var filterGroup=this;this.boxen.bind('click',function(e){scpage.handleFilterCheckbox(e,filterGroup);});return this;}
SubCategoryFilterGroup.prototype.getFilterItem=function(id){var rv=this.filters[id];if(rv)
return rv;rv=this.filters[this.filterName+"-"+id];if(rv)
return rv;return null;}
SubCategoryFilterGroup.prototype.resetCounts=function(){this.selectedCount=0;for(var i=0;i<this.boxen.size();i++)
{if(this.boxen[i].checked)
this.selectedCount++;}
if(this.selectedCount==0)
{}
for(var f in this.filters)
{this.filters[f].passCount=0;this.filters[f].failCount=0;}
return this.selectedCount;}
SubCategoryFilterGroup.prototype.resetEverything=function(){this.showUnmatchingFilters();for(var i=0;i<this.boxen.size();i++)
{var box=this.boxen[i];var jbox=$(box);if(box.checked)
{jbox.removeAttr('disabled');jbox.checkBox('changeCheckStatus',false);}
}
return this.resetCounts();}
SubCategoryFilterGroup.prototype.showUnmatchingFilters=function(){this.container.find('.badchoice').removeClass('badchoice');this.boxen.attr('disabled',false);}
SubCategoryFilterGroup.prototype.hideUnmatchingFilters=function(){for(var f in this.filters)
{var filter=this.filters[f];if(filter.passCount<1)
{filter.listItem.addClass('badchoice');if(!filter.checkbox[0].checked)
filter.checkbox.attr('disabled','disabled');}}}
SubCategoryFilterGroup.prototype.showCounts=function(){return void(0);}
function SubCategoryPage(){var me=this;this.productGroupDivs=$('.group-item');this.groupContainer=$('#sub-category-list');this.filterGroups=new Array();this.filterWidgets=$('.filtergroup');this.allFilterItems=new Array();this.addFilterGroup('brand');this.addFilterGroup('range');this.masterFilterName="";$('a.filter-reset-link').click(function(e){me.resetFilter(e)});$('a#sort-list-view-link').click(function(e){me.setListView(e,'list')});$('a#sort-grid-view-link').click(function(e){me.setListView(e,'grid')});$('select#subcat-sort').change(function(e){me.handleSort(e)});me.setInitialView();return this;}
SubCategoryPage.prototype.handleSort=function(e){var widget=e&&e.target?e.target:e;var sortfield=$(widget).val();return this.sortGroupItems(sortfield);}
SubCategoryPage.prototype.sortGroupItems=function(sortfield){var reversed=false;if(sortfield.indexOf('reverse')>0)
{reversed=true;sortfield=sortfield.replace('-reverse','');}
var numeric=true;if(sortfield=="name"||sortfield=="brand")
numeric=false;var sortme=new Array();this.productGroupDivs.each(function(){$this=$(this);sortme.push({id:this.id,value:$this.attr('data-'+sortfield),numeric:numeric,relevance:$this.attr('data-relevance'),name:$this.attr('data-name'),node:this});});var comparator=function(a,b){var a1=a.value;var b1=b.value;if(numeric)
{if((+a1)<(+b1))return-1;if((+a1)>(+b1))return 1;}else{if(a1<b1)return-1;if(a1>b1)return 1;}
a1=a.relevance;b1=b.relevance;if((+a1)<(+b1))return 1;if((+a1)>(+b1))return-1;a1=a.name;b1=b.name;if(a1<b1)return-1;if(a1>b1)return 1;return 0;};sortme.sort(comparator);if(reversed)
sortme.reverse();this.groupContainer.hide(0);for(var i in sortme)
{var stuff=sortme[i];this.groupContainer.append(stuff.node);}
this.groupContainer.show('slow');return void(0);}
SubCategoryPage.prototype.setInitialView=function(){var view=null;if(this.groupContainer.hasClass('sub-category-view-list'))
{view='list';}else{view='grid';}
this.showViewButtonState(view);return void(0);}
SubCategoryPage.prototype.showViewButtonState=function(view){var other=(view=='list')?'grid':'list';$('#sort-'+view+'-view').addClass('sort-'+view+'-view-active');$('#sort-'+other+'-view').removeClass('sort-'+other+'-view-active');return this;}
SubCategoryPage.prototype.setListView=function(e,view){var other=(view=='list')?'grid':'list';this.showViewButtonState(view);this.groupContainer.removeClass('sub-category-view-'+other).addClass('sub-category-view-'+view);$.cookie('scview',view,{expires:90,path:'/'});return void(0);}
SubCategoryPage.prototype.addFilterGroup=function(filterName){this.filterGroups[filterName]=new SubCategoryFilterGroup(filterName,this);return this.filterGroups[filterName];}
SubCategoryPage.prototype.resetFilter=function(e){this.setMasterFilter("");var fgroup=null;for(f in this.filterGroups)
{fgroup=this.filterGroups[f];fgroup.resetEverything();}
this.setMasterFilter("");this.updateFilterDisplay(fgroup);this.setMasterFilter("");return void(0);}
SubCategoryPage.prototype.setMasterFilter=function(fname){this.masterFilterName=fname;this.filterWidgets.removeClass('filtergroup-master');this.filterWidgets.removeClass('filtergroup-slave');if(fname)
{$('#filtergroup-'+fname).addClass('filtergroup-master');this.filterWidgets.not('#filtergroup-'+fname).addClass('filtergroup-slave');}
return fname;}
SubCategoryPage.prototype.handleFilterCheckbox=function(e,filterGroup){var widget=e&&e.target?e.target:e;this.touchedFilterCheckbox=widget;if(filterGroup==null)
{var id1=widget.id.replace('filter-show-','');var words=id1.split('-');if(words&&words.length)
{filterGroup=this.filterGroups[words[0]];}}
if(!this.masterFilterName)
{if(filterGroup)
this.setMasterFilter(filterGroup.filterName);}
return this.updateFilterDisplay(filterGroup);}
SubCategoryPage.prototype.updateFilterDisplay=function(filterGroup){var filterResults=this.applyFilters();this.analyseFilterResults(filterResults);for(var f in this.filterGroups)
{var fg=this.filterGroups[f];if(filterGroup==fg)
continue;if(filterGroup&&(filterGroup.filterName==f))
continue;fg.showUnmatchingFilters();fg.showCounts();if(fg.filterName==this.masterFilterName)
{continue;}
fg.hideUnmatchingFilters();}
return void(0);}
SubCategoryPage.prototype.analyseFilterResults=function(results){for(var i in results)
{var row=results[i].filterStatus;for(var fld in row)
{var status=row[fld];var otherstatus=row[fld=="brand"?"range":"brand"];if(status.filterItem)
{if(otherstatus.pass)
status.filterItem.passCount++;else
status.filterItem.failCount++;}}}}
SubCategoryPage.prototype.applyFilters=function(){var that=this;for(var f in this.filterGroups)
{this.filterGroups[f].resetCounts();}
$('#warning-nothing-matched').remove();var results=new Array();var goodCount=0;var allCount=0;for(var i=0;i<this.productGroupDivs.size();i++)
{++allCount;var idiv=this.productGroupDivs[i];var result=this.hideOrShowItem(idiv);if(result.visible)
goodCount++;results.push(result);}
if(goodCount)
{$('#filter-count').text(goodCount+" of "+allCount);}else{var oldstatus=false;if(this.touchedFilterCheckbox)
oldstatus=this.touchedFilterCheckbox.checked;this.resetFilter(null);if(this.touchedFilterCheckbox)
{var cb=this.touchedFilterCheckbox;this.touchedFilterCheckbox=null;$(cb).checkBox('changeCheckStatus',!oldstatus);this.handleFilterCheckbox({target:cb},null);}}
return results;}
SubCategoryPage.prototype.getFilterItem=function(filterType,which){var fgroup=this.filterGroups[filterType];if(!fgroup)
return 0;return fgroup.getFilterItem(which);}
SubCategoryPage.prototype.hideOrShowItem=function(itemdiv){var groupItem=$(itemdiv);var filterStatus=this.applyFiltersToItem(groupItem);var goodItem=true;for(var f in filterStatus)
{if(!filterStatus[f].pass)
goodItem=false;}
if(goodItem)
{groupItem.show('normal');}else{groupItem.hide('normal');}
return{filterStatus:filterStatus,visible:goodItem,target:groupItem,targetid:itemdiv.id};}
SubCategoryPage.prototype.applyFiltersToItem=function(groupItem){var results={};for(var f in this.filterGroups)
{results[f]={pass:true,filterItem:null};}
var classnames=groupItem.attr('class').split(' ');for(var c in classnames)
{var cn=classnames[c];var cnwords=cn.split('-');if(cnwords.length!=2)
continue;var filterType=cnwords[0];var filterValue=cnwords[1];var filterGroup=this.filterGroups[filterType];if(!filterGroup)
continue;var filterItem=this.getFilterItem(filterType,filterValue);if(!filterItem||!filterItem.checkbox||!filterItem.checkbox.size())
continue;if(filterItem.checkbox[0].checked||(!filterGroup.selectedCount))
{results[filterType]={pass:true,filterItem:filterItem};}else{results[filterType]={pass:false,filterItem:filterItem};}}
return results;}
function checkAll(e){handleCheckAll(e,null,true);}
function uncheckAll(e){handleCheckAll(e,null,false);}
function handleCheckAll(e,master,state){var target=e.target?e.target:e;if(master)
{state=master.checked;}
var myid=target.id;if(myid)
{var outclass=myid.replace('uncheck-all-','').replace('check-all-','');if(outclass)
{var affect=$('input.'+outclass);if(affect.checkBox)
{affect.checkBox('changeCheckStatus',state);affect.trigger('click');}else{affect.attr('checked',state?'checked':'');affect.trigger('click');}}}
return void(0);}
function findit(x){$(x).addClass('findit');}
function CategoryLoaderInit(){$('#category-loader, .qtip-box').find('a').each(function(){$(this).qtip({content:{text:'<img class="throbber" src="/img/design/ajax/load-default.gif" alt="Loading..." />',url:$(this).attr('rel'),title:{text:$(this).text(),button:'<img src="/img/design/leftnav/vert-close.gif" alt="close" />'}},position:{corner:{target:'bottomRight',tooltip:'topLeft'},adjust:{screen:true}},show:{when:'mouseover',solo:true},hide:{fixed:true,delay:1000},style:{tip:true,border:{width:0,radius:4},title:{'color':'#000','font-size':14,'padding':4,'background-color':'#e5e5e5','background-repeat':'repeat-x','background-image':'url(/img/design/leftnav/heading.jpg)'},name:'light',width:270}})});}
function initFancyBoxes(){$('#mailing-list-signup').fancybox({overlayShow:true,type:'iframe',frameWidth:710,frameHeight:540,zoomSpeedIn:0,zoomSpeedOut:0});var t=$("a.fancybox");t.fancybox({'overlayShow':true});}
$(document).ready(function(){$('#s').bind('click',clearDefaultValue).bind('focus',clearDefaultValue).bind('blur',restoreDefaultValue);$('#email-signup').bind('click',clearDefaultValue).bind('focus',clearDefaultValue).bind('blur',restoreDefaultValue);$('input[type=checkbox]').checkBox();$('a.check-all-link').click(checkAll);$('a.uncheck-all-link').click(uncheckAll);CategoryLoaderInit();});$(window).load(function(){initFancyBoxes();});
