// ============================================================
//          Height Generation                                  
// ------------------------------------------------------------

//**
// Function: rem 
// Recalculate px to rem
//
// @function  rem
// @param     $px {number} The Size in PX
// @param     $base {number} The Base for the calculation
// @return    {number} Return the size in em
// @usage:    rem($px,$base)
//**
@function rem($px, $base: $body-font-size)
  @if unitless($px)
    @return #{$px / $base}rem
    
  @else
    $pxpx : strip-units($px)
    @return #{$pxpx / $base}rem

//**
// PRIVAT Mixin: _remsize 
// Recalculate the heightvalues to rem
//
// @mixin     _remsize
// @param     $arg {value} The Argument
// @param     $size {value} The size
// @usage:    +_remsize($arg,$size)
//**
@mixin _remsize($arg, $lines, $iecheck: true)
  @if $body-typo-based == px
    #{$arg}: $lines * $body-line-height + 0px
  
  @if $body-typo-based == rem
    @if $iecheck == true
      @if $rem-js-fallback == false
        @if $comp-ie8 == true or $comp-ie7 == true
          @if $comp-ie7 == true
            .ie7 &
              #{$arg}: $lines * $body-line-height + 0px

          @if $comp-ie8 == true
            .ie8 &
              #{$arg}: $lines * $body-line-height + 0px

    #{$arg}: $lines * ($body-line-height / $body-font-size) + rem

//**
// PRIVAT Mixin: _pxsize 
// Recalculate the heightvalues to px
//
// @mixin     _pxsize
// @param     $arg {value} The Argument
// @param     $size {value} The size
// @usage:    +_pxsize($arg,$size)
//**
@mixin _pxsize($arg, $size, $iecheck: true)
  @if $body-typo-based == px
    #{$arg}: $size + 0px

  @if $body-typo-based == rem
    @if $iecheck == true
      @if $rem-js-fallback == false
        @if $comp-ie8 == true or $comp-ie7 == true
          @if $comp-ie7 == true
            .ie7 &
              #{$arg}: $size + 0px 

          @if $comp-ie8 == true
            .ie8 &
              #{$arg}: $size + 0px

    #{$arg}: rem($size)

//**
// Mixin: rem 
// Recalculate the heightvalues
//
// @mixin     rem
// @param     $arg {value} The Argument
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +rem($arg,$size,$baseline)
//**
@mixin rem($arg, $size, $baseline: $activate-baseline, $iecheck: true)
  @if unitless($size)
    $size: strip-units($size)
  @if $baseline == true
    $lines : ceil($size / $body-line-height) 
    +_remsize($arg, $lines, $iecheck)
    
  @else 
    +_pxsize($arg, $size, $iecheck)

//**
// Mixin: lineheight 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     lineheight
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +lineheight($size,$baseline)
//**
@mixin lineheight($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(line-height, $size, $baseline, $iecheck)

//**
// Mixin: marginbottom 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     marginbottom
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +marginbottom($size,$baseline)
//**
@mixin marginbottom($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(margin-bottom, $size, $baseline, $iecheck)

//**
// Mixin: margintop 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     margintop
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +margintop($size,$baseline)
//**
@mixin margintop($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(margin-top,$size, $baseline, $iecheck)

//**
// Mixin: marginleft 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     marginleft
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +marginleft($size,$baseline)
//**
@mixin marginleft($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(margin-left,$size, $baseline, $iecheck)

//**
// Mixin: marginright 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     marginright
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +marginright($size,$baseline)
//**
@mixin marginright($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(margin-right,$size, $baseline, $iecheck)

//**
// Mixin: paddingtop 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     paddingtop
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +paddingtop($size,$baseline)
//**
@mixin paddingtop($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(padding-top, $size, $baseline, $iecheck)

//**
// Mixin: paddingbottom 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     paddingbottom
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +paddingbottom($size,$baseline)
//**
@mixin paddingbottom($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(padding-bottom, $size, $baseline, $iecheck)

//**
// Mixin: paddingleft 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     paddingleft
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +paddingleft($size,$baseline)
//**
@mixin paddingleft($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(padding-left, $size, $baseline, $iecheck)

//**
// Mixin: paddingright 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     paddingright
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +paddingright($size,$baseline)
//**
@mixin paddingright($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(padding-right, $size, $baseline, $iecheck)

//**
// Mixin: padding 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     padding
// @param     $size {value} The size (follow the normal padding syntax)
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +padding($size,$baseline)
//**
@mixin padding($size, $baseline: $activate-baseline, $iecheck: true)
  @if length($size) == 1
    +paddingtop($size, $baseline, $iecheck)
    +paddingbottom($size, $baseline, $iecheck)
  @else if length($size) == 2
    @if nth($size,1) > 0
      +paddingtop(nth($size,1), $baseline, $iecheck)
      +paddingbottom(nth($size,1), $baseline, $iecheck)
    @if nth($size,2) > 0
      +paddingleft(nth($size,2), $baseline, $iecheck)
      +paddingright(nth($size,2), $baseline, $iecheck)
    @if nth($size,1) == t
      +paddingtop(0, $baseline, $iecheck)
      +paddingbottom(0, $baseline, $iecheck)
    @if nth($size,2) == t
      +paddingleft(0, $baseline, $iecheck)
      +paddingright(0, $baseline, $iecheck)
  @else if length($size) == 4
    @if nth($size,1) > 0
      +paddingtop(nth($size,1), $baseline, $iecheck)
    @if nth($size,3) > 0
      +paddingbottom(nth($size,3), $baseline, $iecheck)
    @if nth($size,4) > 0
      +paddingleft(nth($size,4), $baseline, $iecheck)
    @if nth($size,2) > 0
      +paddingright(nth($size,2), $baseline, $iecheck)
    @if nth($size,1) == t
      +paddingtop(0, $baseline, $iecheck)
    @if nth($size,3) == t
      +paddingbottom(0, $baseline, $iecheck)
    @if nth($size,4) == t
      +paddingleft(0, $baseline, $iecheck)
    @if nth($size,2) == t
      +paddingright(0, $baseline, $iecheck)
//**
// Mixin: margin 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     margin
// @param     $size {value} The size (follow the normal margin syntax)
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +margin($size,$baseline)
//**
@mixin margin($size, $baseline: $activate-baseline, $iecheck: true)
  @if length($size) == 1
    +margintop($size, $baseline, $iecheck)
    +marginbottom($size, $baseline, $iecheck)
  @else if length($size) == 2
    @if nth($size,1) > 0
      +margintop(nth($size,1), $baseline, $iecheck)
      +marginbottom(nth($size,1), $baseline, $iecheck)
    @if nth($size,2) > 0
      +marginleft(nth($size,2), $baseline, $iecheck)
      +marginright(nth($size,2), $baseline, $iecheck)
    @if nth($size,1) == t
      +margintop(0, $baseline, $iecheck)
      +marginbottom(0, $baseline, $iecheck)
    @if nth($size,2) == t
      +marginleft(0, $baseline, $iecheck)
      +marginright(0, $baseline, $iecheck)
  @else if length($size) == 4
    @if nth($size,1) > 0
      +margintop(nth($size,1), $baseline, $iecheck)
    @if nth($size,3) > 0
      +marginbottom(nth($size,3), $baseline, $iecheck)
    @if nth($size,4) > 0
      +marginleft(nth($size,4), $baseline, $iecheck)
    @if nth($size,2) > 0
      +marginright(nth($size,2), $baseline, $iecheck)
    @if nth($size,1) == t
      +margintop(0, $baseline, $iecheck)
    @if nth($size,3) == t
      +marginbottom(0, $baseline, $iecheck)
    @if nth($size,4) == t
      +marginleft(0, $baseline, $iecheck)
    @if nth($size,2) == t
      +marginright(0, $baseline, $iecheck)
    
//**
// Mixin: height 
// Recalculate the Lineheight from PX to REM, provides a px Fallback
//
// @mixin     height
// @param     $size {value} The size
// @param     $baseline {boolean} When 'true', the Value follow the Baselinerule
// @usage:    +height($size,$baseline)
//**
@mixin height($size, $baseline: $activate-baseline,$iecheck: true)
  +rem(height, $size, $baseline, $iecheck)

//**
// Mixin: fontsize 
// Recaluclate the Font Size in PX to REM with Fallback
//
// @mixin     fontsize
// @param     $size {value} Font Size
// @usage:    +fontsize($size)
//**
@mixin fontsize($size)
  +_pxsize(font-size, $size)

//**
// Mixin: fontcalc 
// Calculate Fontsize and Lineheight
//
// @mixin     fontcalc
// @param     $fontsize {value} Font Size
// @param     $lineheight {value} Lineheight for the Font - can be false than used the factor [:default = false]
// @param     $factor {value} The Calculationfactor [:default = 1.2]
// @usage:    +fontcalc($fontsize, $lineheight, $factor)
//**
@mixin fontcalc($fontsize, $lineheight: false, $factor: 1.2)
  +fontsize($fontsize)
  @if $lineheight == false
    +lineheight($fontsize * $factor)
  @else
    +lineheight($lineheight)

//**
// Mixin: baseheight 
// Generate the Baseline Height
//
// @mixin     baseheight
// @param     $lines {value} The targeted baselineheight
// @usage:    +baseheight($lines)
//**
@mixin baseheight($lines)
  +_remsize(height, $lines)

//**
// Mixin: baselineheight 
// Generate the Baseline lineheight
//
// @mixin     baselineheight
// @param     $lines {value} The targeted baselineheight
// @usage:    +baselineheight($lines)
//**
@mixin baselineheight($lines)
  +_remsize(line-height, $lines)

//**
// Mixin: basemargintop 
// Generate the Baseline lineheight
//
// @mixin     basemargintop
// @param     $lines {value} The targeted basemargintop
// @usage:    +basemargintop($lines)
//**
@mixin basemargintop($lines)
  +_remsize(margin-top, $lines)

//**
// Mixin: basemarginbottom 
// Generate the Baseline lineheight
//
// @mixin     basemarginbottom
// @param     $lines {value} The targeted basemarginbottom
// @usage:    +basemarginbottom($lines)
//**
@mixin basemarginbottom($lines)
  +_remsize(margin-bottom, $lines)

//**
// Mixin: basepaddingbottom 
// Generate the Baseline lineheight
//
// @mixin     basepaddingbottom
// @param     $lines {value} The targeted basepaddingbottom
// @usage:    +basepaddingbottom($lines)
//**
@mixin basepaddingbottom($lines)
  +_remsize(padding-bottom, $lines)

//**
// Mixin: basepaddingtop 
// Generate the Baseline lineheight
//
// @mixin     basepaddingtop
// @param     $lines {value} The targeted basepaddingtop
// @usage:    +basepaddingtop($lines)
//**
@mixin basepaddingtop($lines)
  +_remsize(padding-top, $lines)

//**
// Mixin: baseline-grid-helper
// Generate an Baseline Helper Grid
//
// @mixin     baseline-grid-helper
// @param     $offset {Number} Offset the Gradient
// @param     $color {Value} Grid Color
// @usage:     +baseline-grid-helper($offset,$color)
//           ...
//**
@mixin baseline-grid-helper( $offset: -0, $color: rgba(turquoise,0.4)) 
  +background-image(linear-gradient($color 1px, transparent 1px))
  +background-size(1px $body-line-height / $body-font-size  +rem)
  background-position-y : $offset +px

// ---- Insert the Baseline Helper on the Body ----
@if $helper-baseline == true 
  @if $activate-baseline == true
    body
      position: relative
      &:before
        content: ''
        position : absolute
        top      : 0 
        left     : 0
        width    : 100%
        height   : 1800px
        z-index  : 0
        +baseline-grid-helper
