// Calculate optimum putter length based on kuckles to floor

function clearForm() {
	// clear downstream forms
	$("#putter-length").text('');
	$("#putter-lie").text('');
	bellyOffset = 0;
}

$(document).ready(function() {
	
	var length = 0;
	
	// Hide the waist div by default
	$("div#waist").hide();
	
	// but if Belly was already selected, show the waist div
	if ($("input[name=putter-style]:checked").val() == 'b') {
		$("div#waist").show();
	};
	
	// Set the values to 'none', so we can use the .change() function
	$("#fitting-height #height").val("--");
	$('#knuckles').val("--");
	var bellyOffset = 0;
	
	// if they want a Belly putter, show the waist size div
	$("input[name=putter-style]").change(function() {
		clearForm();
		$("div#waist").toggle();
	});
	
	// if they select a waist size, set the bellyOffset
	$("input[name=waist-size]").change(function() {
		clearForm();
		if ($(this).val() == 't') {
			bellyOffset = 9;
		} else if ($(this).val() == 'm') {
			bellyOffset = 8;
		} else if ($(this).val() == 'h') {
			bellyOffset = 7;
		}
	});
	
	$("#knuckles").change(function() {
		var height = $("#fitting-height #height").attr('value');
		var knuckles = parseFloat($(this).attr('value'));
		
		if (height > 72) { 
			if (knuckles != 34.5) {
				knuckles += 0.5;
			};
		};
		
		length = knuckles + bellyOffset;
		$("#putter-length").text(length + " inches");

	});
	
	$("#posture").change(function() {
		var posture = $("#posture").attr('value');
		
		if (posture == "round") {
			length -= 0.5;
			$("#putter-length").text(length + " inches");
		}
	});
	
	$("#hands").change(function() {
		var hands = $("#hands").attr('value');
	
		if (hands == "Neutral") { 
			$("#putter-lie").text('70 degrees');
		} else if (hands == "Low") {
			$("#putter-lie").text('68 degrees');
		} else if (hands == "High") {
			$("#putter-lie").text('72 degrees');
		};

	});
	
	$("a[rel='fitter-popup']").click(function () {
		var features = "height=700,width=800,scrollTo,resizable=0,scrollbars=1,location=0";
		newwindow=window.open(this.href, 'Popup', features);
		return false;
	 });
	
});
