var oz_per_lb=16;var gm_per_lb=453.59237;function StrandCalc(){this.strands=[];}StrandCalc.prototype.addStrand=function(a){this.strands.push(a);};StrandCalc.prototype.getStrandCount=function(){return this.strands.length;};StrandCalc.prototype.getFiberContent=function(a){a=typeof(a)!="undefined"?a:true;var b=this.getPoundsPerYardArray();var e=this.getPoundsPerYardTotal();var d=$.map(b,function(f){return e?(f/e):0;});if(a){var c={};$.each(this.strands,function(f,g){c[g.fiber]=(c[g.fiber]||0)+d[f];});c=sortObjectByKey(c);}else{c=d;}return c;};StrandCalc.prototype.getPricePerPoundTotal=function(){return this.getPricePerYardTotal()*this.getYardsPerPoundTotal();};StrandCalc.prototype.getPoundsPerYardArray=function(){return $.map(this.strands,function(a){return a.ypp?(1/a.ypp):0;});};StrandCalc.prototype.getPoundsPerYardTotal=function(){return sumArray(this.getPoundsPerYardArray());};StrandCalc.prototype.getPricePerYardArray=function(){var a=this.getPoundsPerYardArray();var b=$.map(this.strands,function(d,c){return a[c]*d.ppp;});return b;};StrandCalc.prototype.getPricePerYardTotal=function(){return sumArray(this.getPricePerYardArray());};StrandCalc.prototype.getYardsPerPoundTotal=function(){var a=this.getPoundsPerYardTotal();return a?(1/a):0;};StrandCalc.prototype.getTotalPrice=function(a,b){if(isNaN(a)||a<=0){return 0;}else{if(b=="yd"){return this.getTotalPriceByLength(a);}else{if(b=="lb"){return this.getTotalPriceByWeight(a);}else{if(b=="oz"){return this.getTotalPriceByWeight(a/oz_per_lb);}else{if(b=="gm"){return this.getTotalPriceByWeight(a/gm_per_lb);}else{return 0;}}}}}};StrandCalc.prototype.getTotalPriceByLength=function(b){var a=b?(this.getYardsPerPoundTotal()/b):0;return a?(this.getPricePerPoundTotal()/a):0;};StrandCalc.prototype.getTotalPriceByWeight=function(a){return this.getPricePerPoundTotal()*a;};StrandCalc.prototype.getTotalWeight=function(a,b){if(isNaN(a)||a<=0){return 0;}else{if(b=="yd"){return this.getTotalWeightByLength(a);}else{if(b=="lb"){return a;}else{if(b=="oz"){return a/oz_per_lb;}else{if(b=="gm"){return a/gm_per_lb;}else{return 0;}}}}}};StrandCalc.prototype.getTotalWeightByLength=function(b){var a=this.getYardsPerPoundTotal();return a?(b/a):0;};StrandCalc.prototype.getTotalLength=function(a,b){if(isNaN(a)||a<=0){return 0;}else{if(b=="yd"){return a;}else{if(b=="lb"){return this.getTotalLengthByWeight(a);}else{if(b=="oz"){return this.getTotalLengthByWeight(a/oz_per_lb);}else{if(b=="gm"){return this.getTotalLengthByWeight(a/gm_per_lb);}else{return 0;}}}}}};StrandCalc.prototype.getTotalLengthByWeight=function(a){return a*this.getYardsPerPoundTotal();};StrandCalc.prototype.hasBamboo=function(){var a=false;$.each(this.strands,function(b,c){if(c.fiber.toLowerCase()=="bamboo"){a=true;}});return a;};function sumArray(c){var b=0;for(var a in c){b+=c[a];}return b;}function sortObjectByKey(a){var b=[];$.each(a,function(c){b.push(c);});b.sort();sortedProperties={};$.each(b,function(c,d){sortedProperties[d]=a[d];});return sortedProperties;}
