$('.sf-menu').superfish({ 
	delay:       400,                            // delay on mouseout 
	animation:   {opacity:'show',height:'show'}, // fade-in and slide-down animation 
	speed:       'fast',                         // faster animation speed 
	autoArrows:  false,                          // disable generation of arrow mark-up 
	dropShadows: false                            // disable drop shadows 
});


// Räkna ut kaloriförbrukning
$('#cal').submit(function() {

	var weight 		= $('#weight').val().replace(',', '.');
	var duration 	= $('#duration').val().replace(',', '.');
	
	$('tbody tr', this).each(function() {
		var mets = $('td:first', this).attr('data-mets');
		var answer = Math.round( (mets - 1) * weight * (duration / 60) );
		var godis = Math.round(answer/16);
		$('td:eq(1)', this).text(answer+' kcal (eller '+godis+' punschpraliner...)');
	});

	return false;
});


// Räkna ut maxpuls
$('#maxpulse').submit(function() {

	var age 		= $('#age').val();
	var answer = 205.8 - (0.685 * age);
	$('span', this).html('Din uppskattade maxpuls är <strong>'+Math.round(answer)+' slag/minut</strong>.');

	return false;
});


// Räkna ut BMI
$('#bmi').submit(function() {
	
	var weight = $('#weight').val().replace(',', '.');
	var height = $('#height').val().replace(',', '.');

	var answer = weight / Math.pow(height / 100, 2);
	var rounded = Math.round(answer*100)/100;
	$('span:first', this).html('Ditt BMI är <strong>'+ rounded +'</strong>');
	
	var markerOffset = Math.round( ((rounded-10) * 18) - 3);
	
	$('#marker').remove();
	$('#bmi-chart').append('<span id="marker" style="left:'+ markerOffset+'px"></span>'); 

	return false;
});

	
// Räkna ut pulszoner
$('#zones').submit(function() {

	var pulse_max 	= parseInt($('#pulse_max').val());
	var pulse_rest = parseInt($('#pulse_rest').val());
	var diff = pulse_max - pulse_rest;
	
	$('tbody tr:eq(0) td:eq(2)', this).text(Math.floor(pulse_max*.5)	+' - '+ Math.floor(pulse_max*.6));
	$('tbody tr:eq(1) td:eq(2)', this).text(Math.ceil(pulse_max*.6)	+' - '+ Math.floor(pulse_max*.7));
	$('tbody tr:eq(2) td:eq(2)', this).text(Math.ceil(pulse_max*.7)	+' - '+ Math.floor(pulse_max*.85));
	$('tbody tr:eq(3) td:eq(2)', this).text(Math.ceil(pulse_max*.85)	+' - '+ Math.floor(pulse_max*.95));
	$('tbody tr:eq(4) td:eq(2)', this).text(Math.ceil(pulse_max*.95)	+' - '+ Math.ceil(pulse_max));
	
	$('tbody tr:eq(0) td:eq(3)', this).text(Math.floor(diff*.5 + pulse_rest)	+' - '+ Math.floor(diff*.6 + pulse_rest));
	$('tbody tr:eq(1) td:eq(3)', this).text(Math.ceil(diff*.6 + pulse_rest)		+' - '+ Math.floor(diff*.7 + pulse_rest));
	$('tbody tr:eq(2) td:eq(3)', this).text(Math.ceil(diff*.7 + pulse_rest)		+' - '+ Math.floor(diff*.85 + pulse_rest));
	$('tbody tr:eq(3) td:eq(3)', this).text(Math.ceil(diff*.85 + pulse_rest)	+' - '+ Math.floor(diff*.95 + pulse_rest));
	$('tbody tr:eq(4) td:eq(3)', this).text(Math.ceil(diff*.95 + pulse_rest)	+' - '+ Math.ceil(diff*1 + pulse_rest));

	return false;
});


// Tempo -> hastighet
$('#tempo').submit(function() {
	var tempo 		= $('input:first', this).val().replace(',', '.');
	answer = Math.round((60/tempo)*100)/100;
	$('span', this).html('Hastighet: <strong>'+answer+' km/h</strong>.');

	return false;
});

// hastighet -> tempo
$('#speed').submit(function() {
	var speed 		= $('input:first', this).val().replace(',', '.');
	answer = Math.round((60/speed)*100)/100;
	$('span', this).html('Tempo: <strong>'+answer+' min/km</strong>.');

	return false;
});
