var kc_steerings = [8, // Backspace
                    46, // Del
                    37, 38, 39, 40, // Arrows
                    9, // Tab
                    ];
var kc_integers = [13, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105];
var kc_points = [190];
/* *************************************************************************************
****************************************************************************************
****************************************************************************************
**************************** GMaterial Actions *****************************************
*************** Link Between Google Materials and Triments Classes *********************
****************************************************************************************
****************************************************************************************
************************************************************************************* */
//$('head').append('<script src="https://www.tri.ag/triments/gm-web.min.js"></script>');
/*
$(document).ready(function() {
  $('.buttonx').addClass('mdc-button mdc-button--raised');
});
*/
/* *************************************************************************************
****************************************************************************************
****************************************************************************************
**************************** Global Actions ********************************************
****************************************************************************************
****************************************************************************************
****************************************************************************************
************************************************************************************* */
$(document).ready(function() {
  updateGuidelineVars();
  posTrimentsPerfect();
  initFullscreenUploadFileSelection();
});
$(window).on('resize',function() {
  updateGuidelineVars();
  posTrimentsPerfect();
  setTimeout(function() {
    posTrimentsPerfect();
  },500);
});
$(window).on('load',function() {
  updateGuidelineVars();
  posTrimentsPerfect();
  setTimeout(function() {
    posTrimentsPerfect();
  },500);
});
function posTrimentsPerfect() {
  posImgSliderPerfect();
  posCarSliderPerfect();
  posCarSlider2Perfect();
  posNavScrollElmsPerfect();
  resizeButtonsPerfect();
  posAndResizeMainMenu();
  pos_bigTxtBlocks_perfect();
  cropSVGAnimationTxts();
  specialSizingFunctions();
  keepAspectRatio();
}
$(window).scroll(function (event) { documentScrolling(100); });
function documentScrolling(topPos) {
  topPos = $(document).scrollTop();
  if($('.fi_wif').length>0) {
    $('.fi_wif').each(function() {
      if(topPos + ($(window).height()*0.7) >= $(this).offset().top) {
        $(this).addClass('show');
      }
    });
  }
  if($('.fiamfl_wif').length>0) {
    $('.fiamfl_wif').each(function() {
      var value = 0.7;
      if($(this).attr('data-fiamfl_wif')) value = $(this).attr('data-fiamfl_wif');
      if($(this).attr('data-fiamflwif')) value = $(this).attr('data-fiamflwif');
      if(topPos + ($(window).height()*value) >= $(this).offset().top) {
        $(this).addClass('show');
      }
    });
  }
  if($('.fiamfr_wif').length>0) {
    $('.fiamfr_wif').each(function() {
      if($(this).attr('data-fiamfr_wif')) value = $(this).attr('data-fiamfr_wif');
      if(topPos + ($(window).height()*0.7) >= $(this).offset().top) {
        $(this).addClass('show');
      }
    });
  }
  if($('.fiamftr_wif').length>0) {
    $('.fiamftr_wif').each(function() {
      if(topPos + ($(window).height()*0.7) >= $(this).offset().top) {
        $(this).addClass('show');
      }
    });
  }
  if($('.gih_wif').length>0) {
    $('.gih_wif').each(function() {
      if(topPos + ($(window).height()*0.7) >= $(this).offset().top) {
        $(this).addClass('show');
      }
    });
  }

  if($('.svgTextContFill_wif').length>0) {
    $('.svgTextContFill_wif').each(function() {
      if(topPos + ($(window).height()*0.7) >= $(this).offset().top) {
        $(this).addClass('show');
      }
    });
  }

  // Fade out after distance is scrolled...
  if($('[data-scrollfade]').length>0) {
    $('[data-scrollfade]').each(function() {
      var distance = $(this).attr('data-scrollfade');
      var scrollPos = $(document).scrollTop();
      var rest = (distance - scrollPos);
      var opacity = (rest / 100);
      $(this).css('opacity',opacity);
    });
  }

  // Fade in after distance is scrolled...
  if($('[data-scrollfadein]').length>0) {
    $('[data-scrollfadein]').each(function() {
      var distance = $(this).attr('data-scrollfadein');
      var scrollPos = $(document).scrollTop();
      var rest = (distance - scrollPos);
      var opacity = (rest / 100);
      opacity = (opacity*-1);
      $(this).css('opacity',opacity);
    });
  }

  // Sticky when reached Pos...
  if($('[data-scrollsticky]').length>0) {
    ;
  }

}
$(document).on('click','*',function() { handleClicksAll(event,$(this)); });
$(document).on('mouseenter','*',function() { handleMouseenterAll(event,$(this)); });
function handleClicksAll(sender,obj) {
  /* Toogle right function... */
  if($(obj).attr('data-clickAction')) {
    window[$(obj).attr('data-clickAction')](sender,obj);
  }
}
function handleMouseenterAll(sender,obj) {
  /* Toogle right function... */
  if($(obj).attr('data-hoverAction')) {
    window[$(obj).attr('data-hoverAction')](sender,obj);
  }
}
/* Tab Index Jumping */
$(document).on('keydown','input, select',function(event) {
  if(event.keyCode == 9) {
    if($(this).attr('tabindex') && $(this).attr('tabindex').length > 0) {
      event.preventDefault();
      var thisTabIndex = parseInt($(this).attr('tabindex'));
      var nextTabIndex = thisTabIndex+1;
      if($('[tabindex="'+nextTabIndex+'"]')) {
        $('[tabindex="'+nextTabIndex+'"]').focus();
      }
    }
  }
});
/* Tab-Links and Boxes */
$(document).on('click','.tabsBox .tab-link',function() {
  var thisOuter = $(this).closest('.tabsBox');
  if(!$(thisOuter).hasClass('dontReact')) {
    $(thisOuter).find('.tab-link').removeClass('active');
    $(this).addClass('active');
    $(thisOuter).find('.tab-content').removeClass('active');
    $(thisOuter).find('.tab-content[data-tabCnt="'+$(this).attr('data-tabLnk')+'"]').addClass('active');
  }
});
/* *************************************************************************************
****************************************************************************************
****************************************************************************************
************************* Formular Elemente ********************************************
****************************************************************************************
****************************************************************************************
****************************************************************************************
************************************************************************************* */
/* Input Text */
$(document).on('click','.headLogo',function() { self.location.href = 'https://www.tri.ag'; } );
$(document).on('click','.input_text',function() { $(this).find('input').focus(); } );
$(document).on('change keyup focus blur','.input_text input',function() { input_text_frame($(this)); });
$(document).on('keydown','.input_text.integers, .input_text_sm.integers',function() { if(!kc_integers.includes(event.keyCode) && !kc_steerings.includes(event.keyCode)) event.preventDefault(); });
$(document).on('keydown','.input_text.noPoint, .input_text_sm.noPoint',function() { if(kc_points.includes(event.keyCode)) event.preventDefault(); });
$(document).on('focus','.input_text.inputandselect input, .input_text_sm.inputandselect input',function() { $(this).select(); });
$('.input_text, .input_text_suggestions').each(function() {

  if($(this).find('input').attr('data-trailingicon') && $(this).find('input').attr('data-trailingicon').length>0) {
    if($(this).find('input').attr('data-trailingicon')=='edit') {
      $(this).find('.inputArea').addClass('trailingicon_edit');
      if($(this).find('.inputArea').find('.trailingIcon').length<=0) { $(this).find('.inputArea').append('<div class="trailingIcon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.001 18.001"><g id="Gruppe_7373" data-name="Gruppe 7373" transform="translate(-169 -3588)"><path id="Pfad_1122" data-name="Pfad 1122" d="M0,0H18V18H0Z" transform="translate(169 3588)" fill="none"/><path id="Pfad_1123" data-name="Pfad 1123" d="M11.3,7.515l.69.69L5.19,15H4.5v-.69l6.8-6.8M14,3a.751.751,0,0,0-.525.218L12.1,4.59,14.911,7.4,16.283,6.03a.747.747,0,0,0,0-1.058L14.528,3.218A.737.737,0,0,0,14,3ZM11.3,5.393,3,13.688V16.5H5.813l8.3-8.3L11.3,5.393Z" transform="translate(168.25 3587.25)" fill="currentColor"/></g></svg></div>'); }
    } else if($(this).find('input').attr('data-trailingicon')=='search') {
      $(this).find('.inputArea').addClass('trailingicon_search');
      if($(this).find('.inputArea').find('.trailingIcon').length<=0) { $(this).find('.inputArea').append('<div class="trailingIcon"><svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg></div>'); }
    }
  }

  input_text_frame($(this));
});
function input_text_frame(sender) {
  sender = $(sender).closest('.input_text');
  if($(sender).find('.suffixLabel')) {
    var thisMaxLength = $(sender).find('input').attr('maxlength');
    if($.isNumeric(thisMaxLength)) {
      $(sender).find('.suffixLabel .right').html($(sender).find('input').val().length+' / '+thisMaxLength);
    } else { $(sender).find('.suffixLabel .right').html(''); }
  }

  if($(sender).find('input').hasClass('error')) {
    // Input has Error?
    $(sender).find('.suffixLabel span:first-child').css('color','var(--col_pr60)');
  } else if($(sender).find('input').is(':focus')) {
    // Input has Focus?
    $(sender).find('.suffixLabel span').css('color','var(--col_pl50)');
  } else {
    $(sender).find('.suffixLabel span').css('color','');
  }
}
/* Select (Dropdown) */
/*
<div class="input_select design2">
  <select name="runningrange" class="stepformelm required">
    <option value="10">10 km</option>
    <option value="20">20 km</option>
    <option value="30">30 km</option>
  </select>
  <label class="placeholderLabel" style="grid-row: 2 / 3;">Jährliche Laufleistung</label>
  <svg class="arrowDownElm"></svg>
</div>
*/
$(document).ready(function() {
  initInputSelects();
});
$(document).on('focusout','.input_select select',function() {
  $(this).parent('.input_select').find('select option[value=""]').html('');
});
$(document).on('change','.input_select select',function() {
  /* Remove First Empty Line (If selected Value is not Empty) */
  if($(this).val() != null) {
    if($(this).val().trim().length > 0) {
      $(this).parent('.input_select').find('select option[value=""]').remove();
      $(this).parent('.input_select').find('.placeholderLabel').css('grid-row','2/3').css('font-size','var(--unit_x10)');
      $(this).parent('.input_select').find('.arrowDownElm').css('grid-row','2/3');
    } else {
      $(this).parent('.input_select').find('.placeholderLabel').css('grid-row','3/3').css('font-size','var(--unit_x12)');
      $(this).parent('.input_select').find('.arrowDownElm').css('grid-row','3/3');
    }
  }
});
function initInputSelects() {
  $('.input_select').each(function() {
    $(this).find('.arrowDownElm').replaceWith('<svg class="arrowDownElm" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M24,24H0V0H24Z" style="fill:none"/><path d="M16.59,8.59,12,13.17,7.41,8.59,6,10l6,6,6-6Z"/></svg>');
    if($(this).find('select').find('option').first().val().trim().length>0) {
      if(!$(this).hasClass('noChangeInit')) $(this).find('select').change();
    }

    /* Pos Label Right */
    if($(this).find('select').val().trim().length>0) {
      $(this).find('.placeholderLabel').css('grid-row','2/3').css('font-size','var(--unit_x10)');
      $(this).find('.arrowDownElm').css('grid-row','2/3').css('font-size','var(--unit_x10)');
    } else {
      if(!$(this).find('select').find('option[value=""]').length) {
        $(this).find('select').prepend('<option value=""></option>');
      }
      $(this).find('select').find('option[value=""]').prop('selected',true);
      $(this).find('.placeholderLabel').css('grid-row','').css('font-size','');
      $(this).find('.arrowDownElm').css('grid-row','').css('font-size','');
    }
  });
}
/* Custom Select (Dropdown) */
$(document).ready(function() {
  $('.input_select2').each(function() {
    $(this).find('.arrowDownElm').replaceWith('<svg class="arrowDownElm" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M24,24H0V0H24Z" style="fill:none"/><path d="M16.59,8.59,12,13.17,7.41,8.59,6,10l6,6,6-6Z"/></svg>');
  });
});
$(document).on('click','body',function(event) {
  if(!$(event.target).hasClass('input_select2') && $(event.target).closest('.input_select2').length <= 0) {
    $('.input_select2').removeClass('active')
    $('.input_select2').find('.options').css('height','0px');
  }
});
$(document).on('click','.input_select2',function(event) {
  var thisParent = $(this).closest('.input_select2');
  if(!$(thisParent).hasClass('active')) {
    $(thisParent).addClass('active');
    $(thisParent).find('.options').css('height','auto');
  }
});
$(document).on('click','.input_select2 .inputArea .options .option',function(event) {
  var thisParent = $(this).closest('.input_select2');
  $(thisParent).find('input[type="text"]').val($(this).attr('data-value')).change();
  $(thisParent).find('.options').css('height','0px');
  $(thisParent).removeClass('active');
  event.stopPropagation();
});
$(document).on('change','.input_select2 input',function(event) {
  if($(this).val().trim().length <= 0) $(this).closest('.input_select2').find('.arrowDownElm').css('grid-row','3/3');
  else $(this).closest('.input_select2').find('.arrowDownElm').css('grid-row','2/3');
});
/* Switch */
$(document).on('click','.switch',function() {
  if($(this).hasClass('disabled')) return;
  if($(this).hasClass('active')) { $(this).removeClass('active'); }
  else { $(this).addClass('active'); }
});
/* Selection Chip */
$(document).ready(function() {
  $('.selectionChip').each(function() {
    $(this).find('.expandIcon').html('<svg id="Ebene_1" data-name="Ebene 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0,0H24V24H0Z" style="fill:none"/><path d="M10,6,8.59,7.41,13.17,12,8.59,16.59,10,18l6-6Z"/></svg>');
  });
});
$(document).on('click','.selectionChip',function() {

  if($(this).hasClass('darkenBg')) {
    //if($('.triChip_darkenbg').length<=0) $('body').append('<div class="triChip_darkenbg"></div>')
    //$('.triChip_darkenbg').fadeIn('fast',function() { });
  }

  var preState = $(this).hasClass('active');
  $('.selectionChip[data-group="'+$(this).attr('data-group')+'"]').removeClass('active');
  if(preState) $(this).removeClass('active');
  else $(this).addClass('active');
});
$(document).on('click','.selectionChip .body',function(e) {
  e.stopPropagation();
});
/* Close on Click Outside */
$(document).on('click',function(event) {
  if(!$(event.target).closest('.selectionChip').length) {
    $('.selectionChip').removeClass('active');
  }
});

/* Accordion */
$(document).on('click','.acordion .elm',function() {
  var multiOpenAllowed = false;
  if($(this).closest('.acordion').attr('data-multiopen')=='1') multiOpenAllowed = true;

  if(!multiOpenAllowed) {
    var clickedElm = $(this);
    /* First close others */
    $(this).closest('.acordion').find('.elm').each(function() {
      if($(this).is($(clickedElm))) return;
      $(this).removeClass('active');
      $(this).find('.bodyTxt').slideUp(250);
    });
    if($(this).hasClass('active')) {
      $(this).removeClass('active');
      $(this).find('.bodyTxt').slideUp(250);
    } else {
      $(this).addClass('active');
      $(this).find('.bodyTxt').slideDown(250);
    }
  } else {
    if($(this).hasClass('active')) {
      $(this).removeClass('active');
      $(this).find('.bodyTxt').slideUp(250);
    } else {
      $(this).addClass('active');
      $(this).find('.bodyTxt').slideDown(250);
    }
  }
});

/* Dropdown (Dropdown) */
/*
<div class="input_dropdown" data-loadscript="https://www.tri.ag/konfigurator/ajax/getSearchProposals.php">
  <div class="inputSearch">
    <input type="text" placeholder="Suche nach Marke, Modell, Fahrzeugtyp, Kraftstoff, Farbe, uvm." />
  </div>
  <div class="options">
    <div class="elm">Finanzieren</div>
    <div class="elm">Leasen</div>
    <div class="elm">Abbonieren</div>
    <div class="elm">Verschenken</div>
  </div>
</div>
*/
var input_dropdownsLoadScriptsTimeouts = {};
var input_dropdownsCachedOptions = {};
$(document).ready(function() {
  $('.input_dropdown').each(function(i,v) {
    var thisElm = $(this);
    $(this).attr('data-input_dropdown_id',i);
    var thisOptionElmClone = $(thisElm).find('.options').find('.elm').first().clone();

    // Save Cached (Prefilled to show when input is empty!)
    input_dropdownsCachedOptions[i] = $(this).find('.options').html();

    if($(this).attr('data-foldingoutdirection') == 'down') {
      $(this).find('.options').attr('data-foldingoutdirection','down');
    } else if($(this).attr('data-foldingoutdirection') == 'up') {
      $(this).find('.options').attr('data-foldingoutdirection','up');
      // Place options box before search box
      $(this).find('.options').insertBefore($(this).find('.inputSearch'));
    } else {
      /* Auto Fehlt noch!!!!! */
      $(this).find('.options').attr('data-foldingoutdirection','down');
    }
    $(this).find('.inputSearch input').on('blur',function() {
      setTimeout(function() {
        if(input_dropdownsCachedOptions[i] && input_dropdownsCachedOptions[i].length) {
          console.log('LoadCached');
          $(thisElm).find('.options').html(input_dropdownsCachedOptions[i]);
        }
        //$(thisElm).closest('.input_dropdown').find('.options').hide();
      },100);
    });
    $(this).find('.inputSearch input').on('focus',function() {
      /* Set Max Possible Height */
      var fromTop = $(this).closest('.inputSearch').offset().top + $(this).closest('.inputSearch').outerHeight();
      var remainingHeight = $(window).height() - fromTop;
      remainingHeight = remainingHeight - 100;
      $(this).closest('.input_dropdown').find('.options').css('max-height',remainingHeight+'px');
    });

    var loadScript = $(this).attr('data-loadscript');
    /* On Keyup */
    $(this).find('input[type="text"]').on('keyup',function() {

      var thisInput = (this);
      var player = $(thisElm).attr('data-input_dropdown_id');

      clearTimeout(input_dropdownsLoadScriptsTimeouts[player]);
      input_dropdownsLoadScriptsTimeouts[player] = setTimeout(function() {

        $.post(loadScript,{formData: $(thisInput).val()}).done(function(data) {
          if(data) {
            var result = $.parseJSON(data);
            /* Clean Proposal List */
            $(thisElm).find('.options').html('');
            $.each(result,function(index, value) {
              /* Fill Proposal List */
              $(thisOptionElmClone).find('.textVal').html(value[0]);
              if(parseInt(value[3]) == 1) $(thisOptionElmClone).find('.countingVal').html(value[3]+'&nbsp;Angebot');
              else if(parseInt(value[3]) == 0) $(thisOptionElmClone).find('.countingVal').html('');
              else $(thisOptionElmClone).find('.countingVal').html(value[3]+'&nbsp;Angebote');
              $(thisOptionElmClone).attr('data-action','self.location.href="'+se_BASEDOMAIN+'konfigurator'+value[1]+'";');

              $(thisElm).find('.options').append($(thisOptionElmClone)[0].outerHTML);
            });
            $(thisElm).closest('.input_dropdown').find('.options').show();
          } else {
            $(thisElm).removeClass('propsFound');
            //$(thisElm).find('.options').slideUp(200);
            if(input_dropdownsCachedOptions[i] && input_dropdownsCachedOptions[i].length) {
              console.log('LoadCached');
              $(thisElm).find('.options').html(input_dropdownsCachedOptions[i]);
            }
          }
        });

      },250);

    });
  });
});
$(document).on('focus','.input_dropdown .inputSearch input',function() {
  $(this).select();
});
$(document).on('click','.input_dropdown',function() {
  $(this).find('.options').show();
});
$(document).on('click','.input_dropdown .options .elm',function() {
  var parent = $(this).closest('.input_dropdown');
  if($(this).attr('data-action') && $(this).attr('data-action').length) {
    eval($(this).attr('data-action'));
  }
});



/* Checkbox */
$(document).ready(function() {
  initCheckboxesTicks();
});
$(document).on('click','.input_checkbox',function() {
  if(!$(this).hasClass('disabled')) {
    if($(this).hasClass('active')) {
      $(this).removeClass('active');
      $(this).find('input[type="checkbox"]').prop('checked',false);
      $(this).find('input[type="checkbox"]').change();
    } else {
      $(this).addClass('active');
      $(this).find('input[type="checkbox"]').prop('checked',true);
      $(this).find('input[type="checkbox"]').change();
    }
  }
});
$(document).on('change','.input_checkbox input',function() {
  var outerChkBox = $(this).closest('.input_checkbox');
  if(!$(outerChkBox).hasClass('disabled')) {
    if($(this).is(':checked')) {
      $(outerChkBox).addClass('active');
    } else {
      $(outerChkBox).removeClass('active');
    }
  }
});
$(document).on('click','.input_checkbox label',function() {
  var outerChkBox = $(this).closest('.input_checkbox');
  if($(outerChkBox).hasClass('disabled')) event.preventDefault();
});
function initCheckboxesTicks() {
  $('.input_checkbox').each(function() {
    /* Set Check SVG */
    $(this).find('.tickBox').find('svg').replaceWith('<svg id="Ebene_1" data-name="Ebene 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 9.88 7.69"><path id="Pfad_847" data-name="Pfad 847" d="M3.27,5.88,1.08,3.69l-.73.73L3.27,7.33,9.52,1.08,8.79.35Z" transform="translate(0 0)"/></svg>');
    /* Is Checked* */
    if($(this).find('input[type="checkbox"]').is(':checked')) {
      $(this).addClass('active');
    } else $(this).removeClass('active');
    /* ColorCircle? */
    if($(this).attr('data-colorcode')) {
      $(this).find('.tickBox').css('background-color','rgba('+$(this).attr('data-colorcode')+')');
      $(this).find('.tickBox svg').css('fill','rgba('+$(this).attr('data-tickcolorcode')+')');
      $(this).find('.tickBox svg').css('stroke','rgba('+$(this).attr('data-tickcolorcode')+')');
    }
  });
}
function syncCheckboxesTicks() {
  $('.input_checkbox').each(function() {
    if($(this).find('input[type="checkbox"]').is(':checked')) {
      $(this).addClass('active');
    } else {
      $(this).removeClass('active');
    }
  });
}
/* Radio */
$(document).ready(function() {
  initRadiosTicks();
});
$(document).on('click','.input_radio .tickBox',function() {
  var outerChkBox = $(this).closest('.input_radio');
  $(outerChkBox).find('input').click();
});
$(document).on('change','.input_radio input',function() {
  var outerChkBox = $(this).closest('.input_radio');
  var thisName = $(this).attr('name');
  var thisValue = $(this).val();
  $('input[type="radio"][name="'+thisName+'"]').each(function() {
    if($(this).val() != thisValue) {
      $(this).prop('checked',false);
      $(this).closest('.input_radio').removeClass('active');
    } else $(this).closest('.input_radio').addClass('active');
  });
});
function initRadiosTicks() {
  var counter = 0;
  $('.input_radio').each(function() {
      $(this).find('input[type="radio"]').attr('id','customradio_'+counter);
      $(this).find('label').attr('for','customradio_'+counter);
      $(this).find('.tickBox').attr('for','customradio_'+counter);
      if($(this).find('input[type="radio"]').is(':checked')) {
        $(this).addClass('active');
      } else $(this).removeClass('active');
      counter++;
  });
}
function syncRadiosTicks() {
  $('.input_radio').each(function() {
    if($(this).find('input[type="radio"]').is(':checked')) {
      $(this).addClass('active');
    } else {
      $(this).removeClass('active');
    }
  });
}

/* Button */
$(document).ready(function() {
  $('.button').each(function() {
    if(!$(this).find('.label').length) $(this).html('<label>'+$(this).html()+'</label>');
  });
});
function resizeButtonsPerfect() {
  $('.button').each(function() {
    var labelWidth = $(this).find('.label').width();
    var oneUnitSize = getComputedStyle(document.documentElement).getPropertyValue('--unit_x1');
    var beforeLineWidth = getComputedStyle(document.documentElement).getPropertyValue('--unit_x16');
    $(this).css('min-width',labelWidth+(48*parseFloat(oneUnitSize)));
  });
}

/* RangeSelector */
$('.input_rangeSelector').each(function() {
  $(this).attr('data-value1',$(this).attr('data-min'));
  $(this).attr('data-value2',$(this).attr('data-max'));
});
$('.input_rangeSelector .dot1, .input_rangeSelector .dot2').on('mousedown touchstart',function(event) {
  $(this).attr('data-dropactive','1');
});
$('.input_rangeSelector').on('touchmove',function(event) {
  ;
});
$('.input_rangeSelector').on('mousemove touchmove',function(event) {
  var xPosPercent = (((event.pageX-$(this).offset().left ) / $(this).width())*100);
  if(!xPosPercent) xPosPercent = (((event.originalEvent.touches[0].pageX-$(this).offset().left ) / $(this).width())*100);
  //Pos Active Dot
  if(xPosPercent<0) $(this).find('[data-dropactive="1"]').css('left','0%');
  else if(xPosPercent>100) $(this).find('[data-dropactive="1"]').css('left','100%');
  else {
    if($(this).find('[data-dropactive="1"]').hasClass('dot1')) {
      var dot2XPos = (((($(this).find('.dot2').offset().left - ($(this).find('.dot2').width()/2)) - $(this).offset().left) / $(this).width())*100);
      if(xPosPercent >= dot2XPos) return false;
      var newVal = parseInt($(this).attr('data-min')) + Math.round((parseInt($(this).attr('data-max')) - parseInt($(this).attr('data-min'))) * (xPosPercent/100));
      $(this).attr('data-value1',newVal);
      if($(this).attr('data-min-conected')) {
        $($(this).attr('data-min-conected')).val(newVal);
        $($(this).attr('data-min-conected')).change();
      }
    }
    if($(this).find('[data-dropactive="1"]').hasClass('dot2')) {
      var dot1XPos = (((   ($(this).find('.dot1').offset().left + ($(this).find('.dot1').width()*1.5))   - $(this).offset().left) / $(this).width())*100);
      if(xPosPercent <= dot1XPos) return false;
      var newVal = parseInt($(this).attr('data-min')) + Math.round((parseInt($(this).attr('data-max')) - parseInt($(this).attr('data-min'))) * (xPosPercent/100));
      $(this).attr('data-value2',newVal);
      if($(this).attr('data-max-conected')) {
        $($(this).attr('data-max-conected')).val(newVal);
        $($(this).attr('data-max-conected')).change();

      }
    }
    $(this).find('[data-dropactive="1"]').css('left',xPosPercent+'%');
  }
  //Pos/Fill Middle Line
  var dot1RelLeft = $(this).find('.dot1').offset().left - $(this).offset().left;
  var dot2Distance = $(this).find('.dot2').offset().left - $(this).find('.dot1').offset().left;
  $(this).find('.middleLine').find('.fill').css('left',dot1RelLeft);
  $(this).find('.middleLine').find('.fill').css('width',dot2Distance);
});
$(document).on('mouseup touchend',function() {
  $('.input_rangeSelector').find('.dot1, .dot2').attr('data-dropactive','0');
});

/* PopOver */
var popOverDissapeareDistance = 50;
enablePopOverHovers();
function enablePopOverHovers() {
  $('[data-popOver]').mouseover(function() {
    if(isMobileDevice()) return false;
    if($(this).outerWidth() > 50) popOverDissapeareDistance = 100;
    $('.popOverContentBox').remove();
    $('body').append('<div class="popOverContentBox topRight"><div class="body">'+$(this).attr('data-popOver')+'</div></div>');
    $('.popOverContentBox').removeClass('topLeft');
    $('.popOverContentBox').removeClass('topRight');
    $('.popOverContentBox').removeClass('bottomLeft');
    $('.popOverContentBox').removeClass('bottomRight');
    var placeExtension1 = 'bottom'
    var placeExtension2 = 'Right'
    if(($(this).offset().left + $('.popOverContentBox').outerWidth()) > $(window).width()) {
      placeExtension2 = 'Left';
    }
    if(($(this).offset().top + $('.popOverContentBox').outerHeight()) > $(window).height()) {
      placeExtension1 = 'top';
    }
    var placeExtensionX = placeExtension1+placeExtension2;
    $('.popOverContentBox').addClass(placeExtensionX);
    // Pos PopOver Box
    if(placeExtensionX=='bottomLeft') {
      $('.popOverContentBox').css('left',$(this).offset().left - $('.popOverContentBox').outerWidth() + ($(this).outerWidth()*0.5) + 20);
      $('.popOverContentBox').css('top',$(this).offset().top+$(this).height() + 10);
    } else if(placeExtensionX=='topLeft') {
      $('.popOverContentBox').css('left',$(this).offset().left - $('.popOverContentBox').outerWidth() + ($(this).outerWidth()*0.5) + 20);
      $('.popOverContentBox').css('top',$(this).offset().top+$(this).height() - $('.popOverContentBox').outerHeight() - $(this).outerHeight() - 10);
    } else if(placeExtensionX=='topRight') {
      $('.popOverContentBox').css('left',$(this).offset().left + ($(this).outerWidth()*0.5) - 20);
      $('.popOverContentBox').css('top',$(this).offset().top+$(this).height() - $('.popOverContentBox').outerHeight() - $(this).outerHeight() - 10);
    } else {
      $('.popOverContentBox').css('left',$(this).offset().left + ($(this).outerWidth()*0.5) - 20);
      $('.popOverContentBox').css('top',$(this).offset().top+$(this).height() + 10);
    }
  });
}
$(document).on('mousemove',function(event) {
  if($('.popOverContentBox').is(':visible')) {
    if((event.pageX < ($('.popOverContentBox').offset().left - popOverDissapeareDistance)) || 
       (event.pageX > ($('.popOverContentBox').offset().left + $('.popOverContentBox').outerWidth() + popOverDissapeareDistance)) || 
       (event.pageY < ($('.popOverContentBox').offset().top - popOverDissapeareDistance)) || 
       (event.pageY > ($('.popOverContentBox').offset().top + $('.popOverContentBox').outerHeight() + popOverDissapeareDistance))) {
         $('.popOverContentBox').fadeOut('fast',function() {
           $('.popOverContentBox').remove();
         });
       }
  }
});
$(document).on('click','[data-popOver]',function() {
  if(isMobileDevice()) showTriPopUp($(this).attr('data-popOver'));
});
/* PopOver Drowpdown */
$(document).on('mouseover','.popOverDrowpdown',function() {
  $('.popOverDrowpdownContentBox').remove();
  $('body').append('<div class="popOverDrowpdownContentBox">'+$(this).find('.bodyBx').html()+'</div>');
  var placeExtension1 = 'bottom'
  var placeExtension2 = 'Right'
  if(($(this).offset().left + $('.popOverDrowpdownContentBox').outerWidth()) > $(window).width()) {
    placeExtension2 = 'Left';
  }
  if(($(this).offset().top + $('.popOverDrowpdownContentBox').outerHeight()) > $(window).height()) {
    placeExtension1 = 'top';
  }
  var placeExtensionX = placeExtension1+placeExtension2;
  $('.popOverDrowpdownContentBox').addClass(placeExtensionX);
  // Pos PopOver Box
  if(placeExtensionX=='bottomLeft') {
    $('.popOverDrowpdownContentBox').css('left',$(this).offset().left - $('.popOverDrowpdownContentBox').outerWidth() + ($(this).outerWidth()*0.5) + 20);
    $('.popOverDrowpdownContentBox').css('top',$(this).offset().top+$(this).height() + 10);
  } else if(placeExtensionX=='topLeft') {
    $('.popOverDrowpdownContentBox').css('left',$(this).offset().left - $('.popOverDrowpdownContentBox').outerWidth() + ($(this).outerWidth()*0.5) + 20);
    $('.popOverDrowpdownContentBox').css('top',$(this).offset().top+$(this).height() - $('.popOverDrowpdownContentBox').outerHeight() - $(this).outerHeight() - 10);
  } else if(placeExtensionX=='topRight') {
    $('.popOverDrowpdownContentBox').css('left',$(this).offset().left + ($(this).outerWidth()*0.5) - 20);
    $('.popOverDrowpdownContentBox').css('top',$(this).offset().top+$(this).height() - $('.popOverDrowpdownContentBox').outerHeight() - $(this).outerHeight() - 10);
  } else {
    $('.popOverDrowpdownContentBox').css('left',$(this).offset().left + ($(this).outerWidth()*0.5) - 20);
    $('.popOverDrowpdownContentBox').css('top',$(this).offset().top+$(this).height() + 10);
  }
});
$(document).on('mousemove',function(event) {
  if($('.popOverDrowpdownContentBox').is(':visible')) {
    if((event.pageX < ($('.popOverDrowpdownContentBox').offset().left - popOverDissapeareDistance)) || 
       (event.pageX > ($('.popOverDrowpdownContentBox').offset().left + $('.popOverDrowpdownContentBox').outerWidth() + popOverDissapeareDistance)) || 
       (event.pageY < ($('.popOverDrowpdownContentBox').offset().top - popOverDissapeareDistance)) || 
       (event.pageY > ($('.popOverDrowpdownContentBox').offset().top + $('.popOverDrowpdownContentBox').outerHeight() + popOverDissapeareDistance))) {
         $('.popOverDrowpdownContentBox').fadeOut('fast',function() {
           $('.popOverDrowpdownContentBox').remove();
         });
       }
  }
});
/* Info Icon */
$('.infoIcon').html('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0,0H24V24H0Z" style="fill:none"/><path d="M11,18h2V16H11ZM12,2A10,10,0,1,0,22,12,10,10,0,0,0,12,2Zm0,18a8,8,0,1,1,8-8A8,8,0,0,1,12,20ZM12,6a4,4,0,0,0-4,4h2a2,2,0,0,1,4,0c0,2-3,1.75-3,5h2c0-2.25,3-2.5,3-5A4,4,0,0,0,12,6Z"/></svg>');
$('.attentionIcon').html('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path d="M22.65 34h3V22h-3ZM24 18.3q.7 0 1.175-.45.475-.45.475-1.15t-.475-1.2Q24.7 15 24 15q-.7 0-1.175.5-.475.5-.475 1.2t.475 1.15q.475.45 1.175.45ZM24 44q-4.1 0-7.75-1.575-3.65-1.575-6.375-4.3-2.725-2.725-4.3-6.375Q4 28.1 4 23.95q0-4.1 1.575-7.75 1.575-3.65 4.3-6.35 2.725-2.7 6.375-4.275Q19.9 4 24.05 4q4.1 0 7.75 1.575 3.65 1.575 6.35 4.275 2.7 2.7 4.275 6.35Q44 19.85 44 24q0 4.1-1.575 7.75-1.575 3.65-4.275 6.375t-6.35 4.3Q28.15 44 24 44Zm.05-3q7.05 0 12-4.975T41 23.95q0-7.05-4.95-12T24 7q-7.05 0-12.025 4.95Q7 16.9 7 24q0 7.05 4.975 12.025Q16.95 41 24.05 41ZM24 24Z"/></svg>');
/* ******************************************
+ Stepping Progress Bar
****************************************** */
$(document).ready(function() { createOrUpdateProgressbarSteps(); });
$(document).on('change','.progressBarSteps',function() { });

function createOrUpdateProgressbarSteps() {
  $('.progressBarSteps').each(function() {
    var minVal = parseInt($(this).attr('data-min'));
    var maxVal = parseInt($(this).attr('data-max'));
    var curVal = parseInt($(this).attr('data-current'));
    /* Add Line */
    if($(this).find('.line').length<=0) $(this).append('<div class="line"></div>');
    if($(this).find('.lineBG').length<=0) $(this).append('<div class="lineBG"></div>');
    if($(this).find('.lineDots').length<=0) $(this).append('<div class="lineDots"></div>');
    /* Add Thumb */
    if($(this).find('.thumb').length<=0) $(this).append('<div class="thumb">'+curVal+'/'+maxVal+'</div>');
    /* Add/Modify Dots */
    $(this).find('.lineDots .dot').remove();
    var dotsCount = $(this).attr('data-max') - $(this).attr('data-min');
    for(var i=0;i<=dotsCount;i++) {
      $(this).find('.lineDots').append('<div class="dot"></div>');
    }
    /* Audiust */
    var percentPos = (((curVal-1) / (maxVal-1)) * 100);
    $(this).find('.thumb').css('left',percentPos+'%');
    $(this).find('.lineBG').css('width',percentPos+'%');

    if(curVal==maxVal) $(this).find('.thumb').css('margin-left',(($(this).find('.thumb').outerWidth())*-1));
    else if(curVal==1) $(this).find('.thumb').css('margin-left',0);
    else if(curVal>1) $(this).find('.thumb').css('margin-left',(($(this).find('thumb').outerWidth()/2)*-1));

    $(this).find('.thumb').html(curVal+'/'+maxVal);

  });
}
/* *************************************************************************************
****************************************************************************************
****************************************************************************************
*********************************** Bausteine ******************************************
****************************************************************************************
****************************************************************************************
****************************************************************************************
************************************************************************************* */
/* ******************************************
+ headerElm + menu
****************************************** */
function toggleMainMenu(sender,obj) {
  if($('.headerElement').find('.hamburger').hasClass('cross')) {
    $('.headerElement').find('.hamburger').removeClass('cross');
    /* Open Main Menu */
    $('#mainMenu').css('display','none').removeClass('active');
  } else {
    $('.headerElement').find('.hamburger').addClass('cross');
    /* Close Main Menu */
    $('#mainMenu').css('display','flex').addClass('active');
    posAndResizeMainMenu();
  }
}
function hoverMainMenuLeft(sender,obj) {
  $('#mainMenu').find('.leftRow').find('[data-hoveraction]').removeClass('active');
  $(obj).addClass('active');
  if($(window).width()<992) {
    $('#mainMenu').find('[data-submenu]').slideUp('fast');
    $('#mainMenu').find('[data-submenu="'+$(obj).attr('data-submenulink')+'"]').slideDown('fast');
    /* Animate Lines In (Top to Bottom) */
    var startTime = 0;
    $('#mainMenu').find('[data-submenu="'+$(obj).attr('data-submenulink')+'"]').find('div').each(function() {
      var thisObj = $(this);
      setTimeout(function() { $(thisObj).addClass('visible'); },startTime);
      startTime += 100;
    });

  } else {
    /* Set/Remove Active Classes on Left Items */
    $('#mainMenu .leftRow').find('div').removeClass('active');
    $(obj).parent('div').addClass('active');
    /* Fill Content */
    if($(obj).attr('data-submenulink') && $(obj).attr('data-submenulink').length>0) {
      var subMenuContent = $('#mainMenu').find('[data-submenu="'+$(obj).attr('data-submenulink')+'"]');
      if(subMenuContent.length>0) $('#mainMenu').find('.rightRow').html(subMenuContent.html());
      else $('#mainMenu').find('.rightRow').html('');
    } else $('#mainMenu').find('.rightRow').html('');
    /* Move to Right Top Pos */
    var leftLnkTopPos = $(obj).position().top + ($(obj).height() / 2) - ($('#mainMenu').find('.rightRow').find('div').height() / 2);
    /* To height? Slide up, not down!? */
    $('#mainMenu').find('.rightRow').css('top',leftLnkTopPos+'px');
    if(($('#mainMenu').find('.rightRow').offset().top + $('#mainMenu').find('.rightRow').height()) > $(window).height()) {
      $('#mainMenu').find('.rightRow').css('top',(leftLnkTopPos-$('#mainMenu').find('.rightRow').height())+($('#mainMenu').find('.rightRow').find('div').height())+'px');
      /* Animate Lines In (Bottom to Top) */
      var startTime = $('#mainMenu').find('.rightRow').find('div').length * 100;
      $('#mainMenu').find('.rightRow').find('div').each(function() {
        var thisObj = $(this);
        setTimeout(function() { $(thisObj).addClass('visible'); },startTime);
        startTime -= 100;
      });
    } else {
      /* Animate Lines In (Top to Bottom) */
      var startTime = 0;
      $('#mainMenu').find('.rightRow').find('div').each(function() {
        var thisObj = $(this);
        setTimeout(function() { $(thisObj).addClass('visible'); },startTime);
        startTime += 100;
      });
    }
  }
}
function posAndResizeMainMenu() {
  //$('#mainMenu').css('height',$(window).height()*1.3);
  $('#mainMenu').css('padding-top',($('.headerElement').height()));
  /* Only if Mobile and Portrait! */
  if($(window).width()<=992 && $(window).height()>$(window).width()) {
    $('#mainMenu').css('padding-top',($('.headerElement').height()*1.8));
    $('#mainMenu').css('padding-bottom',($('.headerElement').height()*0.2)+($(window).height()*0.3));
  } else {
    $('#mainMenu').css('padding-bottom',($('.headerElement').height()));
    if($('#mainMenu')[0] && $(window).height()<$('#mainMenu')[0].scrollHeight) {
      $('#mainMenu').css('padding-top',($('.headerElement').height()*1.2));
      $('#mainMenu').css('align-items','flex-start');
    } else {
      $('#mainMenu').css('align-items','center');
    }
  }
}
/* ******************************************
+ bigTxtBlock
****************************************** */
function pos_bigTxtBlocks_perfect() {
  $('.bigTxtBlock').each(function() {
    $(this).find('.colorLines').css('height',$(this).find('.headline').height()+$(this).find('.subhead').height());
  });
};
$(document).ready(function() {
  /* Remove ColorLines when no Headline */
  $('.bigTxtBlock').each(function() {
    if($(this).find('.headline').length <= 0) $(this).find('.colorLines').remove();
  });
});
/* ******************************************
+ Nav Scroll Elm
****************************************** */
$('.nav_scrollElm').each(function() {
  for(var i=0;i<6;i++) {
    $(this).find('.line').append('<div class="block"></div>');
  }
});
$(window).scroll(function (event) {
  $('.nav_scrollElm').each(function() {
    if(parseFloat($(this).css('opacity'))<=0) { $(this).css('display','none'); }
    else { $(this).css('display','inherit'); }
  });
});
$(document).on('click','.nav_scrollElm',function() {
  if($(this).find('[data-scrollto]').length > 0) {
    if($(this).find('[data-scrollto]').attr('data-scrolltoanchor')) {
      if($(this).find('[data-scrollto]').attr('data-scrolltoanchor')=='center') {
        var objHeight = $($(this).find('[data-scrollto]').attr('data-scrollto')).height();
        var windowHeight = $(window).height();
        if((windowHeight-objHeight)<=0) var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top;
        else {
          var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top - ((windowHeight-objHeight)/2);
        }
      } else if($(this).find('[data-scrollto]').attr('data-scrolltoanchor').indexOf('top+')!=-1) {
        var splitted = $(this).find('[data-scrollto]').attr('data-scrolltoanchor').split('+');
        var objHeight = $($(this).find('[data-scrollto]').attr('data-scrollto')).height();

        if(splitted[1].indexOf('px')!=-1) {
          var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top + (parseInt(splitted[1]))+'px';
        } else {
          var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top + (objHeight*(parseInt(splitted[1])/100))+'%';
        }
      } else if($(this).find('[data-scrollto]').attr('data-scrolltoanchor').indexOf('top-')!=-1) {
        var splitted = $(this).find('[data-scrollto]').attr('data-scrolltoanchor').split('-');
        var objHeight = $($(this).find('[data-scrollto]').attr('data-scrollto')).height();

        if(splitted[1].indexOf('px')!=-1) {
          var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top - (parseInt(splitted[1]))+'px';
        } else {
          var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top - (objHeight*(parseInt(splitted[1])/100))+'%';
        }
      } else if($(this).find('[data-scrollto]').attr('data-scrolltoanchor')=='top') {
        var objHeight = $($(this).find('[data-scrollto]').attr('data-scrollto')).height();
        var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top + (objHeight/2);
      } else var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top;
    }
    else {
      var scrollToPos = $($(this).find('[data-scrollto]').attr('data-scrollto')).offset().top
    }
    $('html, body').stop().animate({
      'scrollTop': scrollToPos
     }, 900, 'swing', function () {

     });

  }
});
/* ******************************************
+ Image Slider
****************************************** */
$(document).on('click','.imgSlider .images .center',function() { actionSlider($(this),'left'); } );
$(document).on('click','.imgSlider .steerings .leftChevron',function() { actionSlider($(this),'left'); } );
$(document).on('click','.imgSlider .steerings .rightChevron',function() { actionSlider($(this),'right'); } );
$(document).ready(function() {
  $('.imgSlider').each(function() {
    var thisSliderBox = $(this);
    var sliderLoaded = $(this).data('loaded');
    if(typeof(sliderLoaded)=='undefined') {
      /* Inialisize Slider */
      $(this).data('loaded','true');
      if($(this).find('.images img').length<5) {
        //Need Min. 5 Images!
        var howManyLeft = 5 - $(this).find('.images img').length;
        for(var i=0;i<howManyLeft;i++) {
          var newElm = $(this).find('.images').find('img:nth-child('+(i+1)+')').clone();
          $(this).find('.images').append(newElm);
        }
      }
      $(this).find('.images').append('<div style="clear:both;"></div>');
      var newElm = $(this).find('.images').find('img').each(function(index) {
        if(index==0) $(this).addClass('center');
        else if(index==1) $(this).addClass('left');
        else if((index+1)==thisSliderBox.find('.images').find('img').length) $(this).addClass('right');
        else $(this).addClass('back');
      });
    }
  });
});
function posImgSliderPerfect() {
  try {
    if($('.imgSlider').length > 0) {
      $('.imgSlider').each(function() {
        $(this).find('.images').css('height',$(this).find('.images').find('.center').height());
        $(this).find('.images img.center').width();
        document.documentElement.style.setProperty('--imageSLiderCenterImgMarginleft', (($(this).find('.images img.center').width()/2)*-1)+ "px");
        document.documentElement.style.setProperty('--imageSLiderRightImgMarginleft', (($(this).find('.images img.right').width())*-1)+ "px");
      });
    }
  } catch(err) {}
}
function actionSlider(senderObj,direction) {
  if(!direction) var direction = 'left';
  var slidernumber = $(senderObj).data('slidernumber');
  var sliderObj = $('.imgSlider[data-slidernumber="'+slidernumber+'"]');
  var actMainImg = $('.imgSlider[data-slidernumber="'+slidernumber+'"]').data('actmainimg');

  if($(sliderObj).attr('data-inrun') == '1') return;
  $(sliderObj).attr('data-inrun','1');
  setTimeout(function() { $(sliderObj).attr('data-inrun','0'); },500);

  if(direction == 'left') {
    var classesMemory = new Array();
    $(sliderObj).find('.images').find('img').each(function(index) {
      classesMemory.push($(this).attr('class'));
    });
    var classesMemoryNew = new Array();
    $(classesMemory).each(function(index,value) {
      if(index==($(sliderObj).find('.images').find('img').length-1)) classesMemoryNew.push(classesMemory[0]);
      else classesMemoryNew.push(classesMemory[index+1]);
    });
    $(sliderObj).find('.images').find('img').each(function(index) {
      $(this).removeClass('center').removeClass('left').removeClass('right').removeClass('back')
      $(this).addClass(classesMemoryNew[index]);
    });
  } else {
    var classesMemory = new Array();
    $(sliderObj).find('.images').find('img').each(function(index) {
      classesMemory.push($(this).attr('class'));
    });
    var classesMemoryNew = new Array();
    $(classesMemory).each(function(index,value) {
      if(index==0) classesMemoryNew.push(classesMemory[($(sliderObj).find('.images').find('img').length-1)]);
      else classesMemoryNew.push(classesMemory[index-1]);
    });
    $(sliderObj).find('.images').find('img').each(function(index) {
      $(this).removeClass('center').removeClass('left').removeClass('right').removeClass('back')
      $(this).addClass(classesMemoryNew[index]);
    });
  }
}
/* ******************************************
+ Car Slider
****************************************** */
$(document).on('click','.carSlider .images .left',function() { actionCarSlider($(this),'left'); } );
$(document).on('click','.carSlider .images .center',function() { actionCarSlider($(this),'left'); } );
$(document).on('click','.carSlider .images .right',function() { actionCarSlider($(this),'right'); } );
$(document).on('click','.carSlider .steerings .leftChevron',function() { actionCarSlider($(this),'left'); } );
$(document).on('click','.carSlider .steerings .rightChevron',function() { actionCarSlider($(this),'right'); } );
$(document).ready(function() {
  $('.carSlider').each(function() {
    var thisSliderBox = $(this);
    var sliderLoaded = $(this).data('loaded');
    if(typeof(sliderLoaded)=='undefined') {
      /* Inialisize Slider */
      $(this).data('loaded','true');
      if($(this).find('.images img').length<4) {
        //Need Min. 5 Images!
        var howManyLeft = 4 - $(this).find('.images img').length;
        for(var i=0;i<howManyLeft;i++) {
          var newElm = $(this).find('.images').find('img:nth-child('+(i+1)+')').clone();
          $(this).find('.images').append(newElm);
        }
      }
      $(this).find('.images').append('<div style="clear:both;"></div>');
      var newElm = $(this).find('.images').find('img').each(function(index) {
        if(index==0) $(this).addClass('center');
        else if(index==1) $(this).addClass('left');
        else if((index+1)==thisSliderBox.find('.images').find('img').length) $(this).addClass('right');
        else $(this).addClass('back');
      });
      /* Swap Infos in InfoBox */
      var datObj= new Object();
      $($(this).find('.images').find('img.center')[0].attributes).each(function() {
        if(this.name.startsWith('data-dat_')) {
          $(thisSliderBox).find('.'+this.name.replace('data-','')).html(this.value);
        }
      });
      /* Set Link on Action Buttons */
      var link = $(this).find('.images').find('img.center').data('link');
      $(this).find('.actions .actionLnk').each(function() {
        $(this).attr('href',$(this).data('lnkpraefix')+'/'+link);
      });
    }
  });
});
function posCarSliderPerfect() {
  try {
    if($('.carSlider').length > 0) {
      $('.carSlider').each(function() {

        if($(window).width()>=992) {
          $(this).find('.images').find('img').css('max-width',$(this).find('.images').width()*0.50);
        } else {
          $(this).find('.images').find('img').css('max-width',$(this).find('.images').width()*1);
        }

        $(this).find('.images').css('height',$(this).find('.images').find('.center').height());
        $(this).find('.images img.center').width();

        $(this).find('.actions').css('width',$(this).find('.steerings .infoBox').outerWidth());

        document.documentElement.style.setProperty('--carSLiderCenterImgMarginleft', (($(this).find('.images img.center').width()/2)*-1)+ "px");
        document.documentElement.style.setProperty('--carSLiderRightImgMarginleft', (($(this).find('.images img.right').width())*-1)+ "px");
      });
    }
  } catch(err) {}
}
var timeoutFadefreelyConfigurableBanner;
function actionCarSlider(senderObj,direction) {
  /* fade In&Out freelyConfigurableBanner */
  clearTimeout(timeoutFadefreelyConfigurableBanner);
  if($('.freelyConfigurableBanner').length) {
    $('.freelyConfigurableBanner').fadeTo(150,0);
    timeoutFadefreelyConfigurableBanner = setTimeout(function() { $('.freelyConfigurableBanner').fadeTo(150,1); },500);
  }

  if(!direction) var direction = 'left';
  var slidernumber = $(senderObj).data('slidernumber');
  var sliderObj = $('.carSlider[data-slidernumber="'+slidernumber+'"]');
  var actMainImg = $('.carSlider[data-slidernumber="'+slidernumber+'"]').data('actmainimg');

  if($(sliderObj).attr('data-inrun') == '1') return;
  $(sliderObj).attr('data-inrun','1');
  setTimeout(function() { $(sliderObj).attr('data-inrun','0'); },500);

  if(direction == 'left') {
    var classesMemory = new Array();
    $(sliderObj).find('.images').find('img').each(function(index) {
      classesMemory.push($(this).attr('class'));
    });
    var classesMemoryNew = new Array();
    $(classesMemory).each(function(index,value) {
      if(index==($(sliderObj).find('.images').find('img').length-1)) classesMemoryNew.push(classesMemory[0]);
      else classesMemoryNew.push(classesMemory[index+1]);
    });
    $(sliderObj).find('.images').find('img').each(function(index) {
      $(this).removeClass('center').removeClass('left').removeClass('right').removeClass('back')
      $(this).addClass(classesMemoryNew[index]);
    });
  } else {
    var classesMemory = new Array();
    $(sliderObj).find('.images').find('img').each(function(index) {
      classesMemory.push($(this).attr('class'));
    });
    var classesMemoryNew = new Array();
    $(classesMemory).each(function(index,value) {
      if(index==0) classesMemoryNew.push(classesMemory[($(sliderObj).find('.images').find('img').length-1)]);
      else classesMemoryNew.push(classesMemory[index-1]);
    });
    $(sliderObj).find('.images').find('img').each(function(index) {
      $(this).removeClass('center').removeClass('left').removeClass('right').removeClass('back')
      $(this).addClass(classesMemoryNew[index]);
    });
  }
  /* Swap Infos in InfoBox */
  var datObj= new Object();
  $($(sliderObj).find('.images').find('img.center')[0].attributes).each(function() {
    if(this.name.startsWith('data-dat_')) {
      $(sliderObj).find('.'+this.name.replace('data-','')).html(this.value);
    }
  });
  /* Set Link on Action Buttons */
  var link = $(sliderObj).find('.images').find('img.center').data('link');
  $(sliderObj).find('.actions .actionLnk').each(function() {
    $(this).attr('href',$(this).data('lnkpraefix')+'/'+link);
  });
}
/* ******************************************
+ Car Slider2
****************************************** */
$(document).on('click','.carSlider2 .images .left',function() { actionCarSlider2($(this),'left'); } );
$(document).on('click','.carSlider2 .images .center',function() { actionCarSlider2($(this),'lnk'); } );
$(document).on('click','.carSlider2 .images .right',function() { actionCarSlider2($(this),'right'); } );
$(document).on('click','.carSlider2 .steerings .leftChevron',function() { actionCarSlider2($(this),'left'); } );
$(document).on('click','.carSlider2 .steerings .rightChevron',function() { actionCarSlider2($(this),'right'); } );
$(document).ready(function() {
  $('.carSlider2').each(function() {
    var thisSliderBox = $(this);
    var sliderLoaded = $(this).data('loaded');
    if(typeof(sliderLoaded)=='undefined') {
      /* Inialisize Slider */
      $(this).data('loaded','true');
      if($(this).find('.images img').length<4) {
        //Need Min. 5 Images!
        var howManyLeft = 4 - $(this).find('.images img').length;
        for(var i=0;i<howManyLeft;i++) {
          var newElm = $(this).find('.images').find('img:nth-child('+(i+1)+')').clone();
          $(this).find('.images').append(newElm);
        }
      }
      $(this).find('.images').append('<div style="clear:both;"></div>');
      var newElm = $(this).find('.images').find('img').each(function(index) {
        if(index==0) $(this).addClass('center');
        else if(index==1) $(this).addClass('left');
        else if((index+1)==thisSliderBox.find('.images').find('img').length) $(this).addClass('right');
        else $(this).addClass('back');
      });
      /* Swap Infos in InfoBox */
      var datObj= new Object();
      $($(this).find('.images').find('img.center')[0].attributes).each(function() {
        if(this.name.startsWith('data-dat_')) {
          $(thisSliderBox).find('.'+this.name.replace('data-','')).html(this.value);

          /* Hide When Zero? */
          if($(thisSliderBox).find('.'+this.name.replace('data-','')).hasClass('hideWhenZero')) {
            if(this.value==0) {
              $(thisSliderBox).find('.'+this.name.replace('data-','')).closest('.hideWhenZeroBlock').css('display','none');
            } else {
              $(thisSliderBox).find('.'+this.name.replace('data-','')).closest('.hideWhenZeroBlock').css('display','initial');
            }
          }
        } else if(this.name.startsWith('data-attr_')) {
          $(thisSliderBox).find('['+this.name.replace('attr_','')+']').attr(this.name.replace('attr_',''),this.value);
        }
      });

      /* Set Link on Action Buttons */
      var link = $(this).find('.images').find('img.center').data('link');
      $(this).find('.actions .actionLnk').each(function() {
        $(this).attr('href',link);
      });
    }
  });
});
function posNavScrollElmsPerfect() {
  $('.nav_scrollElm').each(function() {
    $(this).css('margin-left',($(this).width()/2)*-1);
  });
}
function posCarSlider2Perfect() {
  try {
    if($('.carSlider2').length > 0) {
      $('.carSlider2').each(function() {

        if($(window).width()>=992) {
          $(this).find('.images').find('img').css('max-width',$(this).find('.images').width()*0.50);
        } else {
          $(this).find('.images').find('img').css('max-width',$(this).find('.images').width()*1);
        }

        $(this).find('.images').css('height',$(this).find('.images').find('.center').height());
        $(this).find('.images img.center').width();

        $(this).find('.actions').css('width',$(this).find('.steerings .infoBox').outerWidth());

        /*$(this).find('.infoBox').css('top','50px');*/

        document.documentElement.style.setProperty('--carSLiderCenterImgMarginleft', (($(this).find('.images img.center').width()/2)*-1)+ "px");
        document.documentElement.style.setProperty('--carSLiderRightImgMarginleft', (($(this).find('.images img.right').width())*-1)+ "px");
      });
    }
  } catch(err) {}
}
timeoutFadeInfoBox = false;
timeoutFadeInfoBox2 = false;
timeoutFadeInfoBox3 = false;
function actionCarSlider2(senderObj,direction) {

  if(direction=='lnk') {
    if($(senderObj).attr('data-link').indexOf('http')!=-1) self.location.href=$(senderObj).attr('data-link');
    ;
    return;
  }

  /* fade In&Out infoBox */
  clearTimeout(timeoutFadeInfoBox);
  if($('.carSlider2 .infoBox').length) {
    $('.carSlider2 .infoBox').fadeTo(150,0.001);
    timeoutFadeInfoBox = setTimeout(function() { $('.carSlider2 .infoBox').fadeTo(150,1); },500);
  }
  /* fade In&Out infoBox2 */
  clearTimeout(timeoutFadeInfoBox2);
  if($('.carSlider2 .infoBox2').length) {
    $('.carSlider2 .infoBox2').fadeTo(150,0.001);
    timeoutFadeInfoBox2 = setTimeout(function() { $('.carSlider2 .infoBox2').fadeTo(150,1); },700);
  }
  /* fade In&Out infoBox3 */
  clearTimeout(timeoutFadeInfoBox3);
  if($('.carSlider2 .infoBox3').length) {
    $('.carSlider2 .infoBox3').fadeTo(150,0.001);
    timeoutFadeInfoBox3 = setTimeout(function() { $('.carSlider2 .infoBox3').fadeTo(150,1); },700);
  }

  if(!direction) var direction = 'left';
  var slidernumber = $(senderObj).data('slidernumber');
  var sliderObj = $('.carSlider2[data-slidernumber="'+slidernumber+'"]');
  var actMainImg = $('.carSlider2[data-slidernumber="'+slidernumber+'"]').data('actmainimg');

  /* Brand Background SVG */
  if($(senderObj).find('.headerBox').find('.brandLogo')) {
    $(sliderObj).find('.headerBox').find('.brandLogo').html(atob($(sliderObj).find('.images').find('img.center').attr('data-brandsvg')));
  }

  if($(sliderObj).attr('data-inrun') == '1') return;
  $(sliderObj).attr('data-inrun','1');
  setTimeout(function() { $(sliderObj).attr('data-inrun','0'); },500);

  if(direction == 'left') {
    var classesMemory = new Array();
    $(sliderObj).find('.images').find('img').each(function(index) {
      classesMemory.push($(this).attr('class'));
    });
    var classesMemoryNew = new Array();
    $(classesMemory).each(function(index,value) {
      if(index==($(sliderObj).find('.images').find('img').length-1)) classesMemoryNew.push(classesMemory[0]);
      else classesMemoryNew.push(classesMemory[index+1]);
    });
    $(sliderObj).find('.images').find('img').each(function(index) {
      $(this).removeClass('center').removeClass('left').removeClass('right').removeClass('back')
      $(this).addClass(classesMemoryNew[index]);
    });
  } else {
    var classesMemory = new Array();
    $(sliderObj).find('.images').find('img').each(function(index) {
      classesMemory.push($(this).attr('class'));
    });
    var classesMemoryNew = new Array();
    $(classesMemory).each(function(index,value) {
      if(index==0) classesMemoryNew.push(classesMemory[($(sliderObj).find('.images').find('img').length-1)]);
      else classesMemoryNew.push(classesMemory[index-1]);
    });
    $(sliderObj).find('.images').find('img').each(function(index) {
      $(this).removeClass('center').removeClass('left').removeClass('right').removeClass('back')
      $(this).addClass(classesMemoryNew[index]);
    });
  }

  $(sliderObj).find('.steerings').find('.actShwonImgNr').html((parseInt($(sliderObj).find('.center').attr('data-imgnumber'))+1));
  /* Swap Infos in InfoBox */
  var datObj= new Object();
  $($(sliderObj).find('.images').find('img.center')[0].attributes).each(function() {
    if(this.name.startsWith('data-dat_')) {
      $(sliderObj).find('.'+this.name.replace('data-','')).html(this.value);

      /* Hide When Zero? */
      if($(sliderObj).find('.'+this.name.replace('data-','')).hasClass('hideWhenZero')) {
        if(this.value==0) {
          $(sliderObj).find('.'+this.name.replace('data-','')).closest('.hideWhenZeroBlock').css('display','none');
        } else {
          $(sliderObj).find('.'+this.name.replace('data-','')).closest('.hideWhenZeroBlock').css('display','initial');
        }
      }
    } else if(this.name.startsWith('data-attr_')) {
      $(sliderObj).find('['+this.name.replace('attr_','')+']').attr(this.name.replace('attr_',''),this.value);
    }
  });
  /* Set Link on Action Buttons */
  var link = $(sliderObj).find('.images').find('img.center').data('link');
  $(sliderObj).find('.actions .actionLnk').each(function() {
    $(this).attr('href',link);
  });
}
/* ******************************************
+ PopUp
****************************************** */
var popUpStartZIndex = 100;
$(document).on('click','.triPopUp_darkenbg',function() { closeTriPopUp(); });
$(document).on('click','.tri_popUp .closeCrossBx',function() { closeTriPopUp($(this).closest('.tri_popUp').attr('data-popupnr')); });
$(window).on('resize',function() { audiust_tri_popUp(); });
function showTriPopUp(value) {
  var sender = $(this);
  var thisPopUpNr = $('.tri_popUp').length + 1;
  /* Remove Old */
  //$('.triPopUp_darkenbg').remove();
  //$('.tri_popUp').remove();
  /* Build BG */
  if($('.triPopUp_darkenbg').length<=0) $('body').append('<div class="triPopUp_darkenbg"></div>')

  $('.triPopUp_darkenbg').fadeIn('fast',function() {
    $('body').append('<div class="tri_popUp" data-popupnr="'+thisPopUpNr+'"><div class="closeCrossBx"><svg class="closeCross" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26.2 26.22"><path d="M19,21.12a1.91,1.91,0,0,1,0-.92,1.62,1.62,0,0,1,.46-.8A1.74,1.74,0,0,1,20.2,19a1.79,1.79,0,0,1,.92,0,1.77,1.77,0,0,1,.8.45L44.58,42.09a1.57,1.57,0,0,1,.47.79,2,2,0,0,1,0,.92,1.57,1.57,0,0,1-.47.8,1.66,1.66,0,0,1-.78.45,1.76,1.76,0,0,1-.91,0,1.65,1.65,0,0,1-.79-.45L19.41,21.91A1.74,1.74,0,0,1,19,21.12ZM42.1,19.41a1.67,1.67,0,0,1,.79-.46,1.72,1.72,0,0,1,.9,0,1.63,1.63,0,0,1,.79.46,1.55,1.55,0,0,1,.46.79,2,2,0,0,1,0,.92,1.55,1.55,0,0,1-.46.79L21.92,44.6a1.68,1.68,0,0,1-.8.45,1.79,1.79,0,0,1-.92,0,1.65,1.65,0,0,1-.79-.45,1.54,1.54,0,0,1-.46-.8,1.91,1.91,0,0,1,0-.92,1.62,1.62,0,0,1,.45-.78Z" transform="translate(-18.9 -18.89)"/></svg></div><div class="content">'+value+'</div></div>');
    $('[data-popupnr="'+thisPopUpNr+'"]').css('margin-left',(($('[data-popupnr="'+thisPopUpNr+'"]').outerWidth()*0.5)*-1));
    $('[data-popupnr="'+thisPopUpNr+'"]').css('margin-top',(($('[data-popupnr="'+thisPopUpNr+'"]').outerHeight()*0.5)*-1));
    $('[data-popupnr="'+thisPopUpNr+'"]').fadeIn('fast');
    audiust_tri_popUp();
  })
}
function closeTriPopUp(nr) {
  if(!nr) var nr = 'all';
  if(nr == 'all' || nr == 1) {
    $('.tri_popUp').fadeOut('fast',function() {
      $('.tri_popUp').remove();
      $('.triPopUp_darkenbg').fadeOut('fast');
    });
  } else {
    $('.tri_popUp[data-popupnr="'+nr+'"]').fadeOut('fast',function() { $('.tri_popUp[data-popupnr="'+nr+'"]').remove(); });
  }
}
function audiust_tri_popUp() {
  $('.tri_popUp').each(function() {
    $(this).find('.content').css('max-height',($(this).outerHeight()-$(this).find('.closeCrossBx').height()));
  })
}
/* ******************************************
+ Input Text Suggestions
****************************************** */
$(document).ready(function() {
  $('.input_text_suggestions').each(function(index, value) {
    var thisElm = $(this);
    $(this).on('click',function() { $(this).find('input').focus(); });
    var loadScript = $(this).attr('data-loadscript');
    /* On Keyup */
    $(this).find('input[type="text"]').on('keyup',function() {
      $.post(loadScript,{formData: $(this).val()}).done(function(data) {
        if(data) {
          var result = $.parseJSON(data);
          /* Clean Proposal List */
          $(thisElm).find('.suggestionList').html('');
          $.each(result,function(index, value) {
            /* Fill Proposal List */
            var addElmStr = '<div class="propObj" data-propValue="'+value[1]+'">';
            if(value[2].length>0) addElmStr += '<div class="img" style="background-image: url('+se_DOMAIN+value[2]+');"></div>';
            addElmStr += '<div class="txt">'+value[0]+'</div>';
            addElmStr += '</div>';

            $(thisElm).find('.suggestionList').append(addElmStr);
          });
          /* Show Proposal List */
          if(result.length>0) {
            $(thisElm).addClass('propsFound');
            $(thisElm).find('.suggestionList').slideDown(200);
          } else {
            $(thisElm).removeClass('propsFound');
            $(thisElm).find('.suggestionList').slideUp(200);
          }
        } else {
          $(thisElm).removeClass('propsFound');
          $(thisElm).find('.suggestionList').slideUp(200);
        }
      });
    });
    /* Click on Result ELM */
    $($(thisElm).find('.suggestionList')).on('click','.propObj',function() {
      var clickedPropValue = $(this).attr('data-propValue');
      var clickedPropValueTxt = $(this).text();
      $(thisElm).find('input[name="search"]').val(clickedPropValueTxt);
      $(thisElm).find('input[name="searchParam"]').val(clickedPropValue);
      $(thisElm).removeClass('propsFound');
      $(thisElm).find('.suggestionList').slideUp(200);
    });
  });
});

/* ******************************************
+ Accordion
****************************************** */
$(document).on('click','.accordion .elm .head',function() {
  if($(this).parent('.elm').find('.body').height() > 0) {
    $(this).parent('.elm').find('.body').animate({height:'0'},200);
    $(this).find('svg').css('transform','rotate(0deg)');
  } else {
    $(this).parent('.elm').find('.body').animate({height:$(this).parent('.elm').find('.body')[0].scrollHeight},200);
    $(this).find('svg').css('transform','rotate(180deg)');
  }
});
/* ******************************************
+ Own Scroll Bar
****************************************** */
$(document).on('ready',function() {
  $('.triScrollBar').each(function() {
    //$(this).
  });
});
/* ******************************************
+ Stepping Contact Form
****************************************** */
var steppingContactFormsMemory = new Array();
$(document).ready(function() {
  /* Build Box */
  $('.steppingContactForm').each(function(index, value) {
    steppingContactFormsMemory.push(new Array());
    if($(this).find('.stepIndicatorBox').length > 0) {
      /* StepIndicatorBox with Bullets... */
      var thisStepingContactBox = $(this);
      var circleIcon = $(thisStepingContactBox).find('.dots').find('div').first().html();
      var stepsCount = $(thisStepingContactBox).find('.stepElms').find('.stepElm').length;
      $(thisStepingContactBox).find('.middleLine').css('grid-template-columns','repeat('+stepsCount+',1fr)');
      $(thisStepingContactBox).find('.dots').css('grid-template-columns','repeat('+stepsCount+',1fr)');
      /* Build Indicator Line */
      $(thisStepingContactBox).find('.stepIndicatorBox').find('.middleLine').html('');
      $(thisStepingContactBox).find('.stepIndicatorBox').find('.dots').html('');
      $(thisStepingContactBox).find('.stepElms').find('.stepElm').each(function() {
        $(thisStepingContactBox).find('.stepIndicatorBox').find('.middleLine').append('<div></div>');
        $(thisStepingContactBox).find('.stepIndicatorBox').find('.dots').append('<div>'+circleIcon+'</div>');
      });
    } else if($(this).find('.stepIndicatorBox2').length > 0) {
      /* StepIndicatorBox with Line... */
      var thisStepingContactBox = $(this);
      var stepsCount = $(thisStepingContactBox).find('.stepElms').find('.stepElm').length;
      var stepLength = 100/stepsCount;
      $(this).find('.stepIndicatorBox2').find('.middleLine').find('div').css('width',stepLength+'%');
    } else if($(this).find('.progressBarSteps').length > 0) {
      var thisStepingContactBox = $(this);
      $(thisStepingContactBox).find('.progressBarSteps').attr('data-current',1);
      $(thisStepingContactBox).find('.progressBarSteps').attr('data-max',$(thisStepingContactBox).find('.stepElms').find('.stepElm').length);
      createOrUpdateProgressbarSteps();
    }
  });
});
$(document).on('click','.steppingContactForm .jumpToStartBtn',function() {
  var actStepNr = 0;
  var thisStepingContactBox = $('.steppingContactForm[data-steppingcontactformboxnr="'+$(this).data('steppingcontactformboxnr')+'"]');
  var stepsCount = $(thisStepingContactBox).find('.stepElms').find('.stepElm').length;
  var stepLength = 100/stepsCount;
  /* Hide all Steps */
  $(thisStepingContactBox).find('.stepElm').fadeOut('fast',function() {
    /* Show first Step */
    $(thisStepingContactBox).find('.stepElm[data-stepnr="0"]').fadeIn('fast');
  });
  /* Reset Step indicator Box */
  $(thisStepingContactBox).find('.middleLine').find('div').css('width',((1)*stepLength)+'%');
  /* Reset all Select Fields */
  $(thisStepingContactBox).find('.input_select select').prepend('<option value="" selected=""></option>');
  $(thisStepingContactBox).find('.input_select select').val(' ').removeClass('success');
  $(thisStepingContactBox).find('.placeholderLabel').css('grid-row','');
  $(thisStepingContactBox).find('.arrowDownElm').css('grid-row','');
  /* Reset Input Fields */
  $(thisStepingContactBox).find('.input_text input').val('').removeClass('success');
  /* Reset Input Textareas */
  $(thisStepingContactBox).find('.input_text textarea').val('').removeClass('success');
  /* Show Button */
  $(thisStepingContactBox).find('.nextStepBtn').fadeIn('fast');

  $(thisStepingContactBox).find('.progressBarSteps').attr('data-current',1);
  createOrUpdateProgressbarSteps();
});
$(document).on('click','.steppingContactForm .nextStepBtn',function() {
  /* Check Direct Redirect? */
  var selected = $(this).closest('.steppingContactForm').find('select[name="form_thema"]').find('option:selected');
  if(jQuery.type($(selected).attr('data-directlnk')) !== 'undefined') {
    self.location.href = $(selected).attr('data-directlnk');
    return false;
  }
  /* Load Next Step */
  /* Which step is visible? */
  var actStepNr = 0;
  var thisStepingContactBox = $(this).parent('.steppingContactForm');
  var stepsCount = $(thisStepingContactBox).find('.stepElms').find('.stepElm').length;
  var stepLength = 100/stepsCount;
  $(thisStepingContactBox).find('.stepElms').find('.stepElm').each(function() {
    if($(this).is(':visible')) actStepNr = $(this).data('stepnr');
  });

  /* Save This Step Data */
  var thisStepFormElmVal = $(thisStepingContactBox).find('.stepElms').find('.stepElm[data-stepnr="'+actStepNr+'"]').find('.stepformelm');

  if(thisStepFormElmVal.val().length<=0 && thisStepFormElmVal.hasClass('required')) {
    thisStepFormElmVal.addClass('error');
    return;
  } else if(thisStepFormElmVal.data('datatype')=='email' && !validEmail(thisStepFormElmVal.val().trim()) && thisStepFormElmVal.hasClass('required')) {
    thisStepFormElmVal.addClass('error');
    return;
  } else if(thisStepFormElmVal.data('datatype')=='zip' && (isNaN(parseInt(thisStepFormElmVal.val().trim())) || parseInt(thisStepFormElmVal.val().trim())<10) && thisStepFormElmVal.hasClass('required')) {
    thisStepFormElmVal.addClass('error');
    alert('Bitte geben Sie wenigstens die ersten 2 Stellen Ihrer Postleitzahl an.');
    return;
  } else {
    steppingContactFormsMemory[0].push(thisStepFormElmVal.attr('name')+'|||'+thisStepFormElmVal.val());
    thisStepFormElmVal.addClass('success');
  }
  /* Exists Next Step ? */
  var nextStepNr = (actStepNr+1);
  if($(thisStepingContactBox).find('.stepElm[data-stepnr="'+nextStepNr+'"]')) {
    /* Fade Out this Step */
    $(thisStepingContactBox).find('.stepElms').find('.stepElm[data-stepnr="'+actStepNr+'"]').fadeOut('fast',function() {
      $(thisStepingContactBox).find('.stepElms').find('.stepElm[data-stepnr="'+nextStepNr+'"]').fadeIn('fast',function() {
        steppingContactFormhandleButtonDisabling(thisStepingContactBox);
      });
      if($(thisStepingContactBox).find('.stepIndicatorBox').length > 0) {
        $(thisStepingContactBox).find('.middleLine').find('div:nth-child('+(nextStepNr+1)+')').addClass('active');
        $(thisStepingContactBox).find('.dots').find('div:nth-child('+(nextStepNr+1)+')').addClass('active');
      } else if($(thisStepingContactBox).find('.stepIndicatorBox2').length > 0) {
        $(thisStepingContactBox).find('.middleLine').find('div').css('width',((nextStepNr+1)*stepLength)+'%');
      }
      if(stepsCount == (nextStepNr+1)) $(thisStepingContactBox).find('.nextStepBtn').fadeOut('fast');
    });
    /* Show Next Step */
    if($(thisStepingContactBox).find('.stepElm[data-stepnr="'+nextStepNr+'"]').hasClass('finalStep')) {
      // Send Form!
      $.post(se_DOMAIN+'/ajax/sendSteppingContactForm.php',{formData: JSON.stringify(steppingContactFormsMemory[0])}).done(function(data) {

      });
    }
  }

  $(thisStepingContactBox).find('.progressBarSteps').attr('data-current',(nextStepNr+1));
  createOrUpdateProgressbarSteps();
});
$(document).on('click keyup change','.steppingContactForm',function() {
  steppingContactFormhandleButtonDisabling($(this));
});
$(document).ready(function() {
  $('.steppingContactForm').each(function() {
    steppingContactFormhandleButtonDisabling($(this));
  });
});
function steppingContactFormhandleButtonDisabling(sender) {
  /* If there is a required field and button -> Disable Button? */
  var nextButtonDisabled = false;
  var thisForm = $(sender);
  thisForm.find('input.required:visible').each(function() {
    if($(this).val().length<=0) nextButtonDisabled = true;
  });
  thisForm.find('textarea.required:visible').each(function() {
    if($(this).val().length<=0) nextButtonDisabled = true;
  });
  thisForm.find('input[type="email"].required:visible').each(function() {
    if($(this).val().length<=0 || !validEmail($(this).val())) nextButtonDisabled = true;
  });
  thisForm.find('select.required:visible').each(function() {
    if($(this).val().length<=0) nextButtonDisabled = true;
  });
  thisForm.find('.input_checkbox:visible input[type="checkbox"].required').each(function() {
    if(!$(this).is(':checked')) nextButtonDisabled = true;
  });
  if(nextButtonDisabled) {
    thisForm.find('.button').addClass('stop-transition');
    thisForm.find('.button').addClass('disabled');
  } else {
    thisForm.find('.button').removeClass('stop-transition');
    thisForm.find('.button').removeClass('disabled');
  }
}
/* ******************************************
+ SVG Texte
****************************************** */
function cropSVGAnimationTxts() {
  $('.headline.svgAnimationText').each(function() {
    var thisHeadlineFontSize = window.getComputedStyle($(this)[0]).fontSize;
    var compElmHeight = 0;
    $(this).find('svg').each(function(index,value) {
      $(this).find('text').each(function(index,value) {
        var elmHeight = parseInt(thisHeadlineFontSize) * (index+1)
        compElmHeight = elmHeight;
        $(this).parent('svg').attr('height',elmHeight);
        $(this).attr('y',parseInt(elmHeight));
      });
    });
  });
}
/* ******************************************
+ Loading & Cookie Overlay
****************************************** */
$(window).on('load',function() {
  handleLoadingOverlay();
});
function handleLoadingOverlay() {
  $('.loadingOverlay').fadeOut('fast',function() { $('.loadingOverlay').remove(); })
}
/* ******************************************
+ ZigZag Images Box
****************************************** */
if($('.zigZagImages .imagesArea2_l').length > 0 ) {
  try {
    $('.zigZagImages .imagesArea2_l').each(function() {
      var img1Height = $(this).find('.image1').height();
      var img2Height = $(this).find('.image2').height();
      $(this).find('.image1_outer').css('height',img1Height);
      $(this).css('height',img1Height+img2Height-(img2Height*0.25));
      $(this).find('.text').css('top',img1Height+25);
    });
  } catch(err) {}
}
if($('.zigZagImages .imagesArea2_r').length > 0 ) {
  try {
    $('.zigZagImages .imagesArea2_r').each(function() {
      var img1Height = $(this).find('.image1').height();
      var img2Height = $(this).find('.image2').height();
      $(this).find('.image1_outer').css('height',img1Height);
      $(this).css('height',img1Height+img2Height-(img2Height*0.25));
      $(this).find('.text').css('top',img1Height+25);

    });
  } catch(err) {}
}
/* ******************************************
+ Special Sizing functions
****************************************** */
function specialSizingFunctions() {
  /* Same Height as Width */
  if($('.sameHeightAsWidth').length > 0) {
    $('.sameHeightAsWidth').each(function() {
      $(this).css('height',$(this).outerWidth());
    });
  }
}
/* ******************************************
+ IE Disable Screen
****************************************** */
function isIE() {
  var ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
  var msie = ua.indexOf('MSIE '); // IE 10 or older
  var trident = ua.indexOf('Trident/'); //IE 11
  return (msie > 0 || trident > 0);
}
if(isIE()){
   document.getElementById('ieDisableScreen').style.display='block';
}
/* ******************************************
+ LIGHT & DARKMODE Switching
****************************************** */
$(document).on('click','[data-action="lightMode_switch"]',function() {
  changeLightMode('light');
});
/* Auto Set Light Mode */
if(getCookie('colorMode') == 'light') {
  $(document).ready(function() {
    changeLightMode('light');
  });
}

function changeLightMode(to) { return;
  if(to == 'light') {
    /* Switch Label Txt */
    if($('.colorModeLabelTxt').html().trim() == 'Darkmode') {
      $('.colorModeLabelTxt').html('Lightmode');
      $('[data-action="lightMode_switch"]').find('.switch').addClass('active');
      $('[data-action="lightMode_switch"]').find('.switch').find('.thumb').find('.svgOuter').first().css('display','none');
      $('[data-action="lightMode_switch"]').find('.switch').find('.thumb').find('.svgOuter').last().css('display','flex');
      setCookie('colorMode','light',31);
    } else {
      $('.colorModeLabelTxt').html('Darkmode');
      $('[data-action="lightMode_switch"]').find('.switch').removeClass('active');
      $('[data-action="lightMode_switch"]').find('.switch').find('.thumb').find('.svgOuter').first().css('display','flex');
      $('[data-action="lightMode_switch"]').find('.switch').find('.thumb').find('.svgOuter').last().css('display','none');
      setCookie('colorMode','dark',31);
    }
    var switchableColors = ['col_pd100',
                            'col_pd90',
                            'col_pd90_0a',
                            'col_pd90_50a',
                            'col_pd80',
                            'col_pd80_75a',
                            'col_pd80_85a',
                            'col_pd80_95a',
                            'col_pd70',
                            'col_pd60',
                            'col_pd50',
                            'col_pl0',
                            'col_pl10',
                            'col_pl20',
                            'col_pl30',
                            'col_pl40',
                            'col_pl50',
                            'col_white',
                            'col_white_50a',
                            'col_white_25a',
                            'col_white_15a',
                            'col_white_5a',
                            'col_black',
                            'col_black_y1',
                            'col_black_c1',
                            'col_black_c1_80a',
                            'col_black_c2',
                            'col_gray_30',
                            'col_gray_120',
                            'col_c2',
                            'col_c3',
                            'col_headerBG',
                            'col_headerBG_50a',
                            'col_headerShadow',
                            'col_footerGray',
                            'col_dropShadow',
                            'col_dropShadow_50a'];
    var switchableImages = [
                            ['lightning.jpg','lightning_r.jpg'],
                            ['ioniq_outlineLogo.png','ioniq_outlineLogoBlack.png'],
                           ];
    if(typeof switchableImages_extra !== 'undefined') switchableImages = $.merge(switchableImages,switchableImages_extra);
    $(switchableImages).each(function() {
      var thisImg = $(this);
      try {
        if($('img[src*="'+$(this)[0]+'"]').length) $('img[src*="'+$(this)[0]+'"]').attr('src',$('img[src*="'+$(this)[0]+'"]').attr('src').replace($(this)[0],$(this)[1]));
        else $('img[src*="'+$(this)[1]+'"]').attr('src',$('img[src*="'+$(this)[1]+'"]').attr('src').replace($(this)[1],$(this)[0]));
      } catch(err) {}
      /* Dot it also for Background-Images (Not that ones where declared in CSS!) */
      try {
        $('[style*="background-image"]').each(function() {
          if($(this).css('background-image').indexOf(thisImg[0])!=-1) {
            $(this).css('background-image',$(this).css('background-image').replace(thisImg[0],thisImg[1]));
          } else if($(this).css('background-image').indexOf(thisImg[1])!=-1) {
            $(this).css('background-image',$(this).css('background-image').replace(thisImg[1],thisImg[0]));
          }
        });
      } catch(err) {}
    });
    var switchableElements = [
                            ['.pointsBg.dark','.pointsBg.light'],
                            ['.header_mode_icon','.header_mode_icon_r'],
                            ['.horizontalBrandsLineBg','.horizontalBrandsLineBg_r'],
                           ];
    if(typeof switchableElements_extra !== 'undefined') switchableElements = $.merge(switchableElements,switchableElements_extra);
    $(switchableElements).each(function() {
      try {
        if($($(this)[0]).is(':visible')) {
          $($(this)[0]).css('display','none');
          $($(this)[1]).css('display','inherit');
        } else {
          $($(this)[1]).css('display','none');
          $($(this)[0]).css('display','inherit');
        }
      } catch(err) {}
    });
    $(switchableColors).each(function(index, value) {
      var old_col = getComputedStyle(document.documentElement).getPropertyValue('--'+value);
      if(getComputedStyle(document.documentElement).getPropertyValue('--'+value+'_r').trim() != '') {
        var new_col = getComputedStyle(document.documentElement).getPropertyValue('--'+value+'_r');
        /* Switch Colors */
        document.documentElement.style.setProperty('--'+value, new_col);
        document.documentElement.style.setProperty('--'+value+'_r', old_col);
      }
    });
  } else {
    alert('To Dark');
  }
}
/* ******************************************
+ CALC Units
****************************************** */
function calcUnitSize(xWidth) {
  var minY    = 1;
  var maxY    = 1;
  var minX    = 300;
  var maxX    = 401;

  if(xWidth>=401) {
    minY      = 1;
    maxY      = 1.1428571429;
    minX      = 401;
    maxX      = 1439;
  }
  if(xWidth>=1440) {
    minY      = 1.1428571429;
    maxY      = 4.5;
    minX      = 1440;
    maxX      = 5760;
  }

  var alphaRadiant  = Math.atan((maxY-minY)/(maxX-minX));
  var alphaGrad     = alphaRadiant;
  var teilstrecke_x = xWidth - minX;
  var teilstrecke_y = teilstrecke_x * Math.tan(alphaRadiant);
  var sfx           = teilstrecke_y + minY;
  return sfx;
}
function updateGuidelineVars() {

  // Calc Size for Unit x1 ...
  //document.documentElement.style.setProperty('--unit_x1', calcUnitSize($(window).width())+ "px");
  document.documentElement.style.setProperty('--unit_x1', calcUnitSize(         ($(window).width()*calcContentWidth($(window).width()))         )+ "px");


  /* Set Content max width */
  document.documentElement.style.setProperty('--contentMaxWidth', ($(window).width()*calcContentWidth($(window).width()))+ "px");
  document.documentElement.style.setProperty('--contentMaxWidthSide', (($(window).width()-($(window).width()*calcContentWidth($(window).width())))/2)+ "px");
  /* Other Usefull Vars */
  document.documentElement.style.setProperty('--windowHeight', $(window).height()+ "px");
}

function calcContentWidth(xWidth) {
  var minY    = 0.9375;
  var maxY    = 0.9375;
  var minX    = 320;
  var maxX    = 428;

  if(xWidth>=428) {
    minY      = 0.9375;
    maxY      = 0.75;
    minX      = 428;
    maxX      = 1920;
  }
  if(xWidth>=1920) {
    minY      = 0.75;
    maxY      = 0.75;
    minX      = 1920;
    maxX      = 7680;
  }



  var alphaRadiant  = Math.atan((maxY-minY)/(maxX-minX));
  var alphaGrad     = alphaRadiant;
  var teilstrecke_x = xWidth - minX;
  var teilstrecke_y = teilstrecke_x * Math.tan(alphaRadiant);
  var sfx           = teilstrecke_y + minY;
  return sfx;
}
/* ******************************************
+ Speedometer
****************************************** */
var speedometerTimeout = false;
var speedometerManually = false;
$(window).bind('mousewheel DOMMouseScroll scroll',function() { if(!speedometerManually) handleSpeedometer(event); });
function handleSpeedometer(sender,gear,txt) {
  if(!gear) var gear = false;
  if(!txt) var txt = false;
  try {
    if(sender == 'manual') {
      // Manual Shifting
      $('#nav_speedometer #speedometerGearOuter').addClass('active');
      setTimeout(function() {
        $('#speedometerGear').html(gear);
        $('#nav_speedometer #speedometerGearOuter').removeClass('active');
      },500);
      /* Animate Note in Speedemeter */
      if($('#nav_speedometer').find('.note').html() != txt) {
        $('#nav_speedometer').find('.note').addClass('active');
        speedometerTimeout2 = setTimeout(function() {
          $('#nav_speedometer').find('.note').html(txt);
          $('#nav_speedometer').find('.note').removeClass('active');
        }, 500);
      }
      $('#nav_speedometer').find('#speedometerArrow').addClass('active');
      speedometerTimeout = setTimeout(function() {$('#nav_speedometer').find('#speedometerArrow').removeClass('active');}, 600);

    } else {
      // Automatic Shifting
      if(!sender) {
        var senderTmp = { wheelDelta:1,automatic:true  };
      } else var senderTmp = sender;


      if(speedometerTimeout) clearTimeout(speedometerTimeout);
      /* Run over all to find de right/last! */
      var lastGear = 1;
      $('[data-speedometerpos]').each(function() {
        if($(window).scrollTop() > parseInt($('[data-speedometerpos="'+$(this).attr('data-speedometerpos')+'"]').offset().top) - 100) {
          lastGear = $(this).attr('data-speedometerpos');
        }
      });
      var notetxt = $('[data-speedometerpos="'+lastGear+'"]').data('speedometertxt');
      /* Switch Gear Number */
      if(lastGear != parseInt($('#speedometerGear').html().trim())) {
        $('#nav_speedometer #speedometerGearOuter').addClass('active');
        setTimeout(function() {
          $('#speedometerGear').html(lastGear);
          $('#nav_speedometer #speedometerGearOuter').removeClass('active');

          /* Automatic Mode? */
          if(senderTmp.automatic) {
            $('#nav_speedometer').find('#speedometerArrow').addClass('active');
            speedometerTimeout = setTimeout(function() {$('#nav_speedometer').find('#speedometerArrow').removeClass('active');}, 1000);
          }

        },500);
      }
      /* Animate Arrow in Speedemeter */
      if(senderTmp.wheelDelta > 0 || senderTmp.detail < 0) {
        $('#nav_speedometer').find('#speedometerArrow').removeClass('active');
      } else {
        $('#nav_speedometer').find('#speedometerArrow').addClass('active');
        speedometerTimeout = setTimeout(function() {$('#nav_speedometer').find('#speedometerArrow').removeClass('active');}, 75);
      }
      /* Animate Note in Speedemeter */
      if($('#nav_speedometer').find('.note').html() != notetxt) {
        $('#nav_speedometer').find('.note').addClass('active');
        speedometerTimeout2 = setTimeout(function() {
          $('#nav_speedometer').find('.note').html(notetxt);
          $('#nav_speedometer').find('.note').removeClass('active');
        }, 500);
      }

    }

  } catch(e) {}
}
/* Set Text and Gear Manually */
function manualSpeedometer(gear,txt) {
  handleSpeedometer('manual',gear,txt);
}
/* ******************************************
+ Fullscreen Drag & Drop Upload File Selection
<input type="file" name="uploadFile" data-draganddropselect="1"> (Must be Found on Page)
****************************************** */
function initFullscreenUploadFileSelection() {
  if($('input[data-draganddropselect="1"]').length > 0) {

  }
}

/* *************************************************************************************
****************************************************************************************
****************************************************************************************
************************* Other & Helpy Functions **************************************
****************************************************************************************
****************************************************************************************
****************************************************************************************
************************************************************************************* */
function copyToClippboard(copyString,callback) {
  $('#copyToClippboardUsableField').remove();
  $('body').append('<input type="text" id="copyToClippboardUsableField" value="'+copyString+'" />');
  $('#copyToClippboardUsableField')[0].select();
  $('#copyToClippboardUsableField')[0].setSelectionRange(0, 99999); /* For mobile devices */
  document.execCommand("copy");
  $('#copyToClippboardUsableField').remove();
  if(typeof callback == 'function') callback();
}
function validEmail(str) {
	var pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return !!str.match(pattern);
}
function validUrl(str) {
	var pattern = /(http(s)?:\/\/.)?(ftp(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{0,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
	return !!str.match(pattern);
}
function setCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}
function sleep(milliseconds) {
 return new Promise(resolve => setTimeout(resolve, milliseconds));
}
function isMobileDevice() {
  var isMobile = false; //initiate as false
  // device detection
  if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
      || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) {
      isMobile = true;
  }
  return isMobile;
}
/*
    Behält Seitenverhältnis (base = die breite o. hoehe die zur berechnung verwendet wird)
    100 = 1:1
    50  = 2:1
    ...
*/
function keepAspectRatio() {
  $('[data-keepaspectratiobasewidth]').each(function() {
    $(this).css('height',$(this).outerWidth()*($(this).attr('data-keepaspectratiobasewidth')/100));
  });
  $('[data-keepaspectratiobaseheight]').each(function() {
    $(this).css('width',$(this).outerHeight()*($(this).attr('data-keepaspectratiobaseheight')/100));
  });
}
function scrollSmoothTo(topPos,offset) {
  $('html, body').stop().animate({
    'scrollTop': topPos
   }, 900, 'swing', function () {

   });
}
function capitalize(str) {
  strVal = '';
  str = str.split(' ');
  for (var chr = 0; chr < str.length; chr++) {
    strVal += str[chr].substring(0, 1).toUpperCase() + str[chr].substring(1, str[chr].length) + ' '
  }
  return strVal
}
function calcCirclePoints(elmCount, circleRadius, center) {
    if(!startAngle) var startAngle = 0;
    var points = [];
    var slice = 2 * Math.PI / elmCount;
    for (var i = 0; i < elmCount; i++) {
      var angle = (slice * i);
      var newX = parseInt(center.x + circleRadius * Math.cos(angle));
      var newY = parseInt(center.y + circleRadius * Math.sin(angle));
      var p = {x:newX,y:newY};
      points.push(p);
    }
    return points;
}
