$.fn.extend({
	showImage: function () {
		$(this).addClass('active').siblings().removeClass('active');
		$('#image').attr('src', $(this).attr('data-src'));
	}
});

$(document).ready(function () {

	$('.thumb').click(function () {
		$(this).showImage();
	});
	
	$('.back').click(function () {
		$('.thumb.active').prev().showImage();
	});
	$('.next').click(function () {
		$('.thumb.active').next().showImage();
	});

	$('.thumb:first').showImage();
	
	
	$('input').change(function () {
		var qty = parseInt($('#qty').val());
		var shipping = 0;

		if (qty) {
			$('#product-subtotal').html('$' + (50 * qty).toFixed(2));
			$('#pickup-label').html('$' + (0 * qty).toFixed(2));
			$('#fedex-ground-label').html('$' + (12 * qty).toFixed(2));
			$('#fedex-overnight-label').html('$' + (36 * qty).toFixed(2));
			
			switch ($('input[name=os1]:checked').val()) {
			case 'pickup':
				shipping = 0 * qty;
				break;
			case 'ground':
				shipping = 12 * qty;
				break;
			case 'overnight':
				shipping = 36 * qty;
				break;
			}

			$('#shipping-subtotal').html('$' + shipping.toFixed(2));
			
			$('#shipping').val(shipping);
			tax = 50 * qty * 0.08;
			$('#tax-subtotal').html('$' + tax.toFixed(2));
			total = (50 * qty) + shipping + tax;
			$('#order-total').html('$' + total.toFixed(2));
		}

	}).change();

});
