$().ready(function() {
	$('.tickets .add').click(function() {
		$(this).parent().find('input').attr('value', parseInt($(this).parent().find('input').attr('value')) + 1);
		updateTotal(this);
	});	
	
	$('.tickets .subtract').click(function() {
		var value =  parseInt($(this).parent().find('input').attr('value'));
		if (value > 0) {
			$(this).parent().find('input').attr('value', value - 1);
		}
		updateTotal(this);
	});	
	
	$('.tickets input').change(function() {
		updateTotal(this);
	});
});

function updateTotal(element) {
	var quantity = $(element).parent().find('input').attr('value');
	var price = parseFloat($(element).parent().parent().find('.price span').text());
	
	var subtotal = quantity * price;
	$(element).parent().parent().find('.subtotal span').text(subtotal.toFixed(2));
	
	var total = 0;
	$('.subtotal span').each(function() {
		total += parseFloat($(this).text());
	});
	
	$('.total span').text(total.toFixed(2));
	
	var adminFee = parseInt($('.adminfee span').text());
	var total2 = total + adminFee;
	$('.total2 span').text(total2.toFixed(2));
}
