//----------------------------------------------------------------------------------------------------------------------------------------------------

jQuery(function(){

	if ( typeof global_Current_ProductCode != "undefined" && jQuery("[name^=SELECT___] ").length )
	{

/* Copyright (c) 2009 Michael Manning (actingthemaggot.com) Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.*/
(function(A){A.fn.extend({currency:function(B){var C={s:",",d:".",c:2};C=A.extend({},C,B);return this.each(function(){var D=(C.n||A(this).text());D=(typeof D==="number")?D:((/\./.test(D))?parseFloat(D):parseInt(D)),s=D<0?"-":"",i=parseInt(D=Math.abs(+D||0).toFixed(C.c))+"",j=(j=i.length)>3?j%3:0;A(this).text(s+(j?i.substr(0,j)+C.s:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+C.s)+(C.c?C.d+Math.abs(D-i).toFixed(C.c).slice(2):""));return this})}})})(jQuery);jQuery.currency=function(){var A=jQuery("<span>").text(arguments[0]).currency(arguments[1]);return A.text()};

		function recal(){
			if(jQuery('select[name^="SELECT___"]').length ){
				//add up all selected options
				jQuery('select[name^="SELECT___"]').each(function(){
				var recal_var = 0;
				recal_var = jQuery(this).find("option:selected").text();	
			
					if (recal_var.indexOf('[Subtract -$') >0){
					price_result = recal_var.split('$')[1].slice(0,-1).replace(/,/g,'');
					current_val=current_val-price_result;
					}
					else if (recal_var.indexOf('[Add $') >0){
					price_result = parseFloat(recal_var.split('$')[1].slice(0,-1).replace(/,/g,''));
					current_val=current_val+price_result;
					}
				}); //each function
			} //if length

			if (jQuery('input[name^="SELECT___"][type="radio"]').length ){
				//add up all radio
				jQuery('input[name^="SELECT___"][type="radio"]:checked').each(function(){
				var recal_var = 0;
				recal_var = jQuery.trim(jQuery(this).next("span").text());

					if (recal_var.indexOf('[Subtract -$') >0){
					price_result = recal_var.split('$')[1].slice(0,-1).replace(/,/g,'');
					current_val=current_val-price_result;
					}
					else if (recal_var.indexOf('[Add $') >0){
					price_result = parseFloat(recal_var.split('$')[1].slice(0,-1).replace(/,/g,''));
					current_val=current_val+price_result;
					}
				}); //
			} //if length

			if (jQuery('input[name^="SELECT___"][type="checkbox"]').length ){
				//add up all radio
				jQuery('input[name^="SELECT___"][type="checkbox"]:checked').each(function(){
				var recal_var = 0;
				recal_var = jQuery.trim(jQuery(this).next("span").text());
	
					if (recal_var.indexOf('[Subtract -$') >0){
					price_result = recal_var.split('$')[1].slice(0,-1).replace(/,/g,'');
					current_val=current_val-price_result;
					}
					else if (recal_var.indexOf('[Add $') >0){
					price_result = parseFloat(recal_var.split('$')[1].slice(0,-1).replace(/,/g,''));
					current_val=current_val+price_result;
					}
				}); //each function
			} //if length

			jQuery('font.pricecolor.colors_productprice').find('.price1:last').html('$' + jQuery.currency(current_val,{s:",",d:".",c:2}));
			current_val=product_orig_price;
		}

	var parent = jQuery('input[type="radio"][name^="SELECT___"],input[type="checkbox"][name^="SELECT___"]').parent('td');
	parent.contents().filter(function() { return this.nodeType != 1; }).wrap('<span></span>');
	var current_val;
	var price_result;
	var product_orig_price = parseFloat(jQuery('font.pricecolor.colors_productprice:not(.pricecolorsmall)').find('.price1:last').text().replace('$','').replace(/,/g,''));
	current_val = product_orig_price;
	recal();
		jQuery('select[name^="SELECT___"],input[name^="SELECT___"]').change(function(){
		recal();
		}); //change

	jQuery("a[href^='javascript:change_option']").click(function(){
		var result_href = jQuery(this).attr('href').match(/\'(.*?)\'/)[1];
		var result_val = jQuery(this).attr('href').match(/\,(.*?)\)/)[1];
		change_option(result_href,result_val);
		recal();
		return false;
	});
	}
}); //doc

//----------------------------------------------------------------------------------------------------------------------------------------------------

