$(function(){
		calc_price();
		$('input').change(function(){ calc_price(); })
		$('select').change(function(){ calc_price(); })
	});
	
	var unit_price = 9.99;
	var vat = 0.0;
	
	function calc_price(){
		
		var qty = Number($('#qty :selected').text());

		var shipping = Number($('input[name=shipping]:checked').val());
		var extra_shipping = 0;
		
		if(qty>1) { extra_shipping = (qty-1) * 0.50; }
		
		var postage = roundNumber(shipping + extra_shipping,2);
		
		var total_no_vat = roundNumber((unit_price * qty) + postage, 2);
		var total = roundNumber(total_no_vat + (total_no_vat/100)*vat, 2);
		
		
		$('#postage').text(postage.toFixed(2), 2);
		$('#unit_price').text(PadDigits(unit_price.toFixed(2),2));
			$('#vat').text(PadDigits(total_no_vat.toFixed(2),2));
			$('#total').text(PadDigits(total.toFixed(2),2));
		
		$('#item_price_1').attr('value', total);
		$('#item_quantity_1').attr('value', qty);
		
		var desc = qty + ' x units';
		
		$('#item_description_1').attr('value', desc)
	}
	
	function roundNumber(rnum, rlength) { 
	  return Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	
	function PadDigits(n, totalDigits) 
	    { 
	        n = n.toString(); 
	        var pd = ''; 
	        if (totalDigits > n.length) 
	        { 
	            for (i=0; i < (totalDigits-n.length); i++) 
	            { 
	                pd += '0'; 
	            } 
	        } 
	        return n.toString() + pd; 
	    }
	
