$(document).ready(function(){
	
	$('#slideshow').cycle({ 
		timeout:       8000,
		speed:         1500,
		sync:          1
	});


	// donation fee adjustments
	// figure out and update the fee based on the amount
	$('input.original_amount').change(function(){
		// strip everything but numbers and . from the donation amount
		// and make sure its an integer
		var val = $(this).val().replace(/[^\d\.]/g,''),
			fee_amount = '3.25%';
		
		val = val * 1;

		if(!isNaN(val) && val != 0){
			fee_amount = val * .0325;
			fee_amount = Math.round(100*fee_amount)/100;
			$(this).parents('form').find('.fee_amount').text('$'+fee_amount);
		} else {
			$(this).parents('form').find('.fee_amount').text(fee_amount);
		}		
	}).change();

	// add the fee to the donation total on submit
	$('form#one_time_donation, form#recurring_donation').submit(function(e){

		if($(this).find('input.add_fee:checked').val() == 'yes'){
			// strip everything but numbers and . from the donation amount
			// and make sure its an integer
			var val = $(this).find('input.original_amount').val().replace(/[^\d\.]/g,'');			
			val = val * 1;
			if(!isNaN(val) && val != 0){
				fee_amount = val * .0325;
				fee_amount = Math.round(100*fee_amount)/100;
				val = fee_amount + val;
				$(this).find('input.donation_amount').val(val);
			}
		} else {
			$(this).find('input.donation_amount').val( $(this).find('input.original_amount').val() );
		}
	});



});// end document ready
