/**
 * Manage selector
 */
$('.selector li.option').click
(
	function()
	{
		// Get selected thickness and price
		var selected_thickness = $(this).html(),
			selected_price     = $(this).attr('title');

		// Add selected thickness
		$('.selected_thickness').html(selected_thickness);

		// Add selected price
		$('.selected_price').html(selected_price);

		// Remove active class from selector
		$('.selector li.active').removeClass('active');

		// Add active class to current selector
		$(this).addClass('active');
	}
);

/**
 * Manage calculator
 */

// Trigger calculator
$('.width').keyup(calc_result);
$('.length').keyup(calc_result);
$('.selector li.option').click(calc_result);

// Do the calculation
function calc_result()
{
	// Set width and length
	var width = $('.width').val().replace(',', '.'),
		length = $('.length').val().replace(',', '.');

	// Parse width and length as floats
	width = parseFloat(width);
	length = parseFloat(length);

	// Get price and calculate total
	var price = parseFloat($('.selected_price').html()),
		total = (width * length) * price;

	if (isNaN(total))
	{
		// No total
		total = '...';
	}
	else
	{
		// Round total
		total = Math.round(total) + ' Ft';
	}

	// Add total
	$('.total').html(total);
}
