$(document).ready(function() {
	$('.slickbox').hide();
	
	$('.slick-toggle').click(function(){
		$('.slickbox').hide();
		var clickedId = this.id;
		var splitId = clickedId.split('-');
		console.log(splitId);
		var bigId = '#slickbox-' + splitId[2];
		$(bigId).css('display','table');
		return false;
	});
});

/***********************************
            bmi calculator
***********************************/
$(function(){
	calcBmi();
	$("#label-results").hide();
	$("#input-results").hide();
	$("#label-kgm").hide();
	$("#bmi-stats").hide();
});

function calcBmi() {
	
	$('#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 = parseInt($('#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');
		$("#bmi-stats").fadeIn('slow');
				
		$("#input-results").val(bmiRound);

		console.log(bmiRound);

		if(bmiRound < 20) {
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");
			$("#under").css("background-color","yellow");
		}
		else if(bmiRound > 20 && bmiRound < 24.9) {
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");
			$("#healthy").css("background-color","green");
		}
		else if(bmiRound > 25 && bmiRound < 29.9) {	
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");	
			$("#over").css("background-color","yellow");
		}
		else if(bmiRound > 30 && bmiRound < 34.9) {
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");
			$("#obesity").css("background-color","yellow");
		}
		else if(bmiRound > 35 && bmiRound < 39.9) {
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");
			$("#severe").css("background-color","red");
		}
		else if(bmiRound > 40 && bmiRound < 49.9) {
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");
			$("#morbid").css("background-color","red");
		}
		else if(bmiRound > 50) {
			$("#bmi-stats tbody tr").css("background-color","#EAD4B6");	
			$("#bmi-stats tbody tr").css("color","#000");
			$("#super-morbid").css("background-color","red");
		}
	});
}
