// Yep, taken right from bourbon - https://github.com/thoughtbot/bourbon/blob/master/dist/settings/_prefixer.scss
$prefix-for-webkit:    true !default;
$prefix-for-mozilla:   true !default;
$prefix-for-microsoft: true !default;
$prefix-for-opera:     true !default;
$prefix-for-spec:      true !default; // set all prefixes to false EXCEPT spec to disable all vendor prefixes

//Property size
@mixin property-size($property, $values...) {
	$fallback: true;
	$max: length($values);
	$defaultValues: '';
	
	@if($fallback) {
		$fallbackValues: '';
		
		@for $i from 1 through $max {
			$value: nth($values, $i);	  
			$fallbackValuesStatement: #{$fallbackValues + $value};
			
			@if($value != auto and $value != inherit){
				@if(unit($value) != "%"){
					$fallbackValues: #{$fallbackValues + strip-units($value) + "px"}; //need to apply strip units as some values come in with px especially if a multiplication of $font-size for example...
				} @else {
					$fallbackValues: $fallbackValuesStatement;
				}
			} @else {
				$fallbackValues: $fallbackValuesStatement;
			}
			
			@if $i < $max {
				$fallbackValues: #{$fallbackValues + " "};
    		}
		}
		#{$property}: $fallbackValues; 
	}
	
	@for $i from 1 through $max {
		$value: nth($values, $i);
		$defaultValuesStatement: #{$defaultValues + $value};
		
		@if($value != auto and $value != inherit){	
			@if(unit($value) != "%"){
				$defaultValues: #{$defaultValues + rem($value)};
			} @else {
				$defaultValues: $defaultValuesStatement;
			}
		} @else {
			$defaultValues: $defaultValuesStatement;
		}
		
		@if $i < $max {
      		$defaultValues: #{$defaultValues + " "};
    	}
	}
  	#{$property}: $defaultValues; 
}

// Retina image
@mixin image-2x($image, $width, $height) {
  @media (min--moz-device-pixel-ratio: 1.3),
         (-o-min-device-pixel-ratio: 2.6/2),
         (-webkit-min-device-pixel-ratio: 1.3),
         (min-device-pixel-ratio: 1.3),
         (min-resolution: 1.3dppx) {
    /* on retina, use image that's scaled by 2 */
    background-image: url($image);
    background-size: $width $height;
  }
}

// Vertical Align
@mixin vertical-align($position: relative) {
  position: $position;
  top: 50%;
  @include prefixer("transform", translateY(-50%), webkit ms spec);
}

// Yep, taken right from bourbon - https://github.com/thoughtbot/bourbon/blob/master/dist/addons/_prefixer.scss
// @prefixer ( string $property, mixed $value, list $prefixes )
@mixin prefixer($property, $value, $prefixes) {
	@each $prefix in $prefixes {
		@if $prefix == webkit {
			@if $prefix-for-webkit {
				-webkit-#{$property}: $value;
			}
		}
		@else if $prefix == moz {
			@if $prefix-for-mozilla {
				-moz-#{$property}: $value;
			}
		}
		@else if $prefix == ms {
			@if $prefix-for-microsoft {
				-ms-#{$property}: $value;
			}
		}
		@else if $prefix == o {
			@if $prefix-for-opera {
				-o-#{$property}: $value;
			}
		}
		@else if $prefix == spec {
			@if $prefix-for-spec {
				#{$property}: $value;
			}
		}
		@else  {
			@warn "Unrecognized prefix: #{$prefix}";
		}
	}
}

// @see https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
// @box-shadow ( [ none | inset? && [ <offset-x> <offset-y> <blur-radius>? <spread-radius>? <color>? ] ] ] )
@mixin box-shadow($shadow...) {
	@if length($shadow) > 4 {
		@warn("$shadow should only accept four argument for each side of the box. Using more may cause undesired results");
	}
	@include prefixer(box-shadow, $shadow, webkit moz ms o spec);
}


// @opacity ( number $alpha [ boolean $ie: true ] )
@mixin opacity($alpha, $ie: true) {
	@if(type-of($alpha) != number) {
		@warn "$alpha must be a number. Setting to 0.5.";
		$alpha: 0.5;
	} @else {
		@if($alpha < 0 or $alpha > 1) {
			@warn "$alpha must be within 0 and 1. Setting to 0.5.";
			$alpha: 0.5;
		}
	}
	@if($ie == true) {
		filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=$alpha * 100);
	}
	opacity: $alpha;
}

// @border-radius ( $radii... )
@mixin border-radius($radii...) {
	@if length($radii) > 4 {
		@warn("$radii should only accept four argument for each side of the box. Using more may cause undesired results");
	}
	@include prefixer(border-radius, $radii, webkit moz ms o spec);
}

// @single-transition ( string $property, number $duration, string $function, [ number $delay: false ] )
@mixin single-transition($property, $duration, $function, $delay: false) {
	@if($delay == false) {
		$delay: "";
	}
	$transition: $property $duration $function $delay;
	@include prefixer(transition, $transition, webkit moz ms o spec);
}

// @transition ( list $transition... )
@mixin transition($transition...) {
	@include prefixer(transition, $transition, webkit moz ms o spec);
}