//--------------------------------------------------
// Custom SASS functions
//--------------------------------------------------

// Strip unit.
@function strip-unit( $num ) {
	@return $num / ($num * 0 + 1);
}

// Convert to em.
@function convert-to-em( $value ) {
	$value: strip-unit( $value ) / strip-unit( $em-base ) * 1em;
	@if ( $value == 0em ) {
		$value: 0; // Turn 0em to 0
	}
	@return $value;
}

//--------------------------------------------------
// EM CALC
// 
// Call it with 1, 2, 3, or 4 parameters.
// 'px' is not required but supported:
// 
//   em-calc(10 20 30px 40);
// 
// Space delimited, if you want to delimit using commas,
// wrap it in another pair of brackets.
// 
//   em-calc((10, 20, 30, 40px));
// 
//--------------------------------------------------

@function em-calc($values) {
	$max: length($values);

	@if $max == 1 {
		@return convert-to-em( nth( $values, 1 ) );
	}

	$em-values: ();
	@for $i from 1 through $max {
		$em-values: append( $em-values, convert-to-em( nth( $values, $i ) ) );
	}
	@return $em-values;
}