(function($){ $(function(){
	var isMember = function(){ return $('input[name=AHCA_member]:checked').val()=='yes'; };
	
	/* Recalc if isMember status changes */
	$('input[@name=AHCA_member]').click(function(){ $(':text').change(); });
	
	/* Grand Total */
	var subtotals = $('input.subtotal');
	subtotals.change(function(){
		var total = 0;
		subtotals.each(function(){ total += parseFloat(this.value || '0');});
		$('#total_due').val(total.toFixed(2));
	});
	
	/* Totals for all but full conference */
	var calcSetup = function(set,totalField,memPrice,nonMemPrice) {
		set = $(set); totalField = $(totalField);
		set.change(function(event){
			totalField.val(
				((isMember() ? memPrice : nonMemPrice) * set.filter('[value]').length).toFixed(2)
			).change(); 
		}).change();
	};
	
	calcSetup('.AL_participants input','#AsstLiv_fee',50,75);
	calcSetup('.SNF_participants input','#SNF_fee',50,75);
	calcSetup('.AALNA_participants input','#AALNA_fee',25,45);
	calcSetup('.Wkshop_Presenters input','#WkshpPresenter_fee',175,175);
	calcSetup('.Wed_participants input','#WedOnly_fee',100,200);
	calcSetup('.Lunch_participants input','#AwardsLunch_fee',40,60);
	
	/* Full conference */
	var attendees = $('.attendee');
	var fullConfSetup = function(totalField,min,max,memPrice,nonMemPrice) {
		totalField = $(totalField); --min;
		attendees.change(function(){
			var count = attendees.filter('[value]').length - min;
			count = count < 0 ? 0 : count > (max-min) ? (max-min) : count;
			totalField.val((count * (isMember() ? memPrice : nonMemPrice)).toFixed(2)).change();
		}).change();
	}
	
	fullConfSetup('#Member_Fee',1,4,295,550);
	fullConfSetup('#Participants_5',5,9,175,350);
	fullConfSetup('#Participants_10',10,10,150,300);
	
});})(jQuery);