/*
	Table Shopby v1.0.0
	Written by All Web Promotion, Inc. 2009
*/

(function(a){a.awpTableShopby=function(c){var i={shopbyTableSel:"#contents-table.shopby",shopbySelectorSel:".shopby-selector",shopbyProgressSel:"#shopby-progress"};var g=a.extend({},i,c);var e=a(g.shopbyTableSel);if(!(e.size()>0&&a(g.shopbySelectorSel).size()>0)){return false;}f();h();return true;function f(){a(g.shopbySelectorSel).val(0).change(function(){var q=a(this).val();var p=a(this).find("option:selected").metadata();d(p,q);a(g.shopbySelectorSel).not(this).val(0);});}function h(){var p=e.metadata().dfn;var q=e.find("tbody > tr").get();a.each(q,function(u,x){x.keys={};var w=a(x).metadata();var t,s,v;for(var r=0;r<p.length;r++){s=p[r]["name"];v=p[r]["type"];t=w[s];if(v=="numeric"){t=n(t);}else{t=k(t);}x.keys[s]=t;}if(u>4){return;}});}function d(u,v){b("start");if(u.kind.indexOf("parse")!=-1){if(u.kind.indexOf("price")!=-1){v=v.replace("$","").replace("$","").toLowerCase();}if(v.indexOf("high to low")!=-1){u.mode="desc";o(u.name,u.mode);}else{if(v.indexOf("low to high")!=-1){u.mode="asc";o(u.name,u.mode);}else{var r=v.split(" ");if(r.length>2){var s=parseFloat(r[0]);var q=parseFloat(r[r.length-1]);var t=isNaN(s);var p=isNaN(q);if(!(t&&p)){s=t?null:s;q=p?null:q;l(u.name,s,q);}}}}}else{if(u.kind=="filter"){m(u.name,v);}else{o(u.name,u.mode);}}b();}var j="Written by All Web Promotion, Inc.";function m(p,q){q=k(q);e.find("tbody > tr").each(function(){if(q==this.keys[p]){a(this).show();}else{a(this).hide();}});}function l(r,q,p){e.find("tbody > tr").each(function(){var t=this.keys[r];var s=true;if(q&&(t<q)){s=false;}if(p&&(t>p)){s=false;}if(s){a(this).show();}else{a(this).hide();}});}function o(q,s){var p=(s=="desc")?-1:1;var r=e.find("tbody > tr").get();r.sort(function(v,t){var w=v.keys[q];var u=t.keys[q];if(w<u){return -p;}if(w>u){return p;}return 0;});a.each(r,function(t,u){e.children("tbody").append(a(u).show());});}function k(p){return p.toLowerCase().replace("'","").replace("'","").replace(",","").replace(",","");}function n(p){p=parseFloat(p);return isNaN(p)?0:p;}function b(p){a(g.shopbyProgressSel).css("visibility",(p=="start")?"visible":"hidden");}};})(jQuery);
