/***********************************
            bmi calculator
***********************************/
$(document).ready(function(){
   calcBmi();
 });

function calcBmi() {
	
	$('#button-calculate').hover(
	      function () {
	        $(this).css('backgroundPosition','0 -40px');
	      }, 
	      function () {
	        $(this).css('backgroundPosition','0 0');
	      }
	    );
	
	$('#button-calculate').click(function(){

	
	var height = 0;
	var inches = 0;
	var totalInches = 0;
	var totalHeight = 0;
	var convertKg = 0;
	var weight = 0;
	var bmi = 0;
	var bmiRound = 0;
	
		height = parseInt($('#input-ft').val()); /* get entered value for height in feet */
		
		height *= 12; /* convert feet to inches */
		inches = parseInt($('#input-in').val()); /* get entered value for height in inches */
		
		
		totalInches += height;
		totalInches += inches; 
		totalHeight = totalInches * totalInches;
		weight += $('#input-lbs').val(); /* get entered weight in lbs */
		convertKg = (weight * 703); /* convert weight to kg's */
		
		if( height != 0) { /* make sure height does not equal 0, avoids dividing by 0 */
			bmi = (convertKg/totalHeight);
			}
		bmiRound = bmi.toFixed(1);
		
		$("#label-results").fadeIn('slow');
		$("#input-results").fadeIn('slow');
		$("#label-kgm").fadeIn('slow');
		$("#input-results").val(bmiRound);
		$("#bmi-stats").fadeIn('slow');
		

		
			

			if(bmiRound < 18.5) {
				$('#bmi-stats tr').css({backgroundColor:'transparent',fontWeight:'normal'});
				$('#underweight').css({backgroundColor:'#F5D355',fontWeight:'bold'});
			}
			else if(bmiRound > 18.5 && bmiRound < 24.9) {
				$('#bmi-stats tr').css({backgroundColor:'transparent',fontWeight:'normal'});
				$('#normal').css({backgroundColor:'#F5D355',fontWeight:'bold'});
			}
			else if(bmiRound > 25 && bmiRound < 29.9) {
				$('#bmi-stats tr').css({backgroundColor:'transparent',fontWeight:'normal'});
				$('#overweight').css({backgroundColor:'#F5D355',fontWeight:'bold'});
			}
			else if(bmiRound >= 30 ) {
				$('#bmi-stats tr').css({backgroundColor:'transparent',fontWeight:'normal'});
				$('#obese').css({backgroundColor:'#F5D355',fontWeight:'bold'});
			}
	});
}	

