/*
	Dynamic Prices 1.3.0
*/

(function(a){a.awpDynamicPricing=function(l){var e={currency:"$",removeOptionPrices:false,itemParentSel:".itemform form",itemPriceSel:".price .value, .price-bold .value",itemSalePriceSel:".sale-price .value, .sale-price-bold .value",sectionParentSel:"#contents-table td",sectionPriceSel:".price .value, .price-bold .value",sectionSalePriceSel:".sale-price .value, .sale-price-bold .value",optionSel:'select,input[type="checkbox"],input[type="radio"]',quantitySel:".order-quantity .quantity-input",extendedPriceSel:".total-price .value",priceSaveAmountSel:".price-save .price",priceSavePercentSel:".price-save .percent",hidePriceTime:200,showPriceTime:400};var d=a.extend({},e,l);var g=/\$\d+\.\d{2}/;var c=/\([\+|\-](.*)\)/;a(d.itemParentSel).each(function(){var m=this;var o="item";var p=h(m,d.itemPriceSel);var n=h(m,d.itemSalePriceSel);var q;a(d.optionSel,m).change(function(){j(m,o,p,n);});a(d.quantitySel,m).keyup(function(){j(m,o,p,n);});f(m);});a(d.sectionParentSel).each(function(){var m=this;var o="section";var p=h(m,d.sectionPriceSel);var n=h(m,d.sectionSalePriceSel);a(d.optionSel,m).change(function(){j(m,o,p,n);});a(d.quantitySel,m).keyup(function(){j(m,o,p,n);});f(m);});if(a(d.quantitySel,d.itemParentSel).size()>0){a(d.quantitySel,d.itemParentSel).eq(0).trigger("keyup");}else{a(d.optionSel,d.itemParentSel).eq(0).trigger("change");}if(a(d.quantitySel,d.sectionParentSel).size()>0){a(d.quantitySel,d.sectionParentSel).eq(0).trigger("keyup");}else{a(d.optionSel,d.sectionParentSel).eq(0).trigger("change");}function j(q,n,s,m){if(!q){return false;}var v,w,u,p,o,t;var r=0;a(q).find(d.optionSel).each(function(){v=a(this).val();v=v.match(/\((.*)\)/);if(v){v=v[1];v=v.replace("$","");v=parseFloat(v);v=isNaN(v)?0:v;}else{v=0;}r=r+v;});if(s){w=(n=="section")?d.sectionPriceSel:d.itemPriceSel;u=parseFloat(s)+parseFloat(r);k(q,w,u);}if(m){w=(n=="section")?d.sectionSalePriceSel:d.itemSalePriceSel;p=parseFloat(m)+parseFloat(r);k(q,w,p);}if(a(d.quantitySel,q).size()>0){o=parseFloat(a(d.quantitySel,q).val());o=o?o:0;o=(o<0)?0:o;}else{o=1;}u=p?p:u;u=b(u*o);a(d.extendedPriceSel,q).text(u);if(s&&m){s=s*o;m=m*o;t=b(s-m);a(d.priceSaveAmountSel,q).text(t);t=i(s,m);a(d.priceSavePercentSel,q).text(t);}}function h(m,p){var o=a(m).find(p).eq(0).text();if(!o){return 0;}var n=parseFloat(o.replace(/\$/,"").replace(/\,/,""));return isNaN(n)?0:n;}function k(m,n,o){a(m).find(n).hide(d.hidePriceTime,function(){a(this).text(b(o)).show(d.showPriceTime);});}function b(n){var m=new Number(n);return d.currency+m.toFixed(2);}function i(n,m){return(Math.round((n-m)/n*100))+"%";}function f(m){if(d.removeOptionPrices){a(d.optionSel,m).each(function(){if(this.tagName.toLowerCase()=="select"){a("option",this).each(function(){var n=a(this).text();if(!n){n=a(this).val();}a(this).text(a.trim(n.replace(c,"")));});}else{if(a(this).attr("type")=="radio"){}else{if(a(this).attr("type")=="checkbox"){}}}});}}};})(jQuery);
