jQuery(document).ready(function($) {
scrollControl();
rotateX();
collapseTerms();
legalLogos();
dkRegulations();
seRegulations();
checkWords();
/* CHECK WORDS */
function checkWords() {
var $quote = $("#text h2:first");
var $numWords = $quote.text().split(" ").length;
if (($numWords >= 1) && ($numWords < 6)) {
$quote.css("font-size", "6.2vw");
}
else if (($numWords >= 6) && ($numWords < 8)) {
$quote.css("font-size", "5vw");
}
else if (($numWords >= 8) && ($numWords < 10)) {
$quote.css("font-size", "5.5vw");
}
else if (($numWords >= 10) && ($numWords < 12)) {
$quote.css("font-size", "4vw");
}
else {
$quote.css("font-size", "3.5vw");
}
}
/* ADD BE LEGAL LOGOS / HEADER T&Cs*/
function legalLogos() {
if ((language == "nl_be") || (language == "fr_be")) {
$("#cta-terms").prepend('
');
} else if (language == "ro_ro"){
$("#cta-terms").prepend('
');
}
}
/* SE Regulations / Stodlinjen logo in footer */
function seRegulations() {
if (language == "sv_se") {
$(".authority").append('
Behöver du hjälp? Ring 020-81 91 00')
}
}
/* DK Regulations */
function dkRegulations() {
if (language == "da_dk") {
$(".terms-container").addClass("yes");
$(".terms-wrapper-dk").css("display","block");
//$("#image").css({ "background-size": "100%", "background-position": "center -10%"});
};
}
/* COLLAPSABLE TERMS */
function collapseTerms() {
/* On collapse box click */
var coll = document.getElementsByClassName("collapse");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
/* On terms text click */
var terms = document.getElementById("cta-terms");
terms.addEventListener("click", function() {
var content = document.getElementById("collapseContent");
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
/* ROTATE X ON CLICK */
function rotateX() {
$(".collapse, #cta-terms").click(function() {
if (!$(".expand-terms-icon").hasClass("rotate-x")) {
$(".expand-terms-icon").addClass("rotate-x");
}
else {
$(".expand-terms-icon").removeClass("rotate-x");
}
});
}
/* SCROLL TO TOP */
function scrollControl() {
$(window).scroll(function() {
if ($(this).scrollTop() >= 50) { // If page is scrolled more than 50px
$('#return-to-top').fadeIn(200); // Fade in the arrow
} else {
$('#return-to-top').fadeOut(200); // Else fade out the arrow
}
});
$('#return-to-top').click(function() { // When arrow is clicked
$('body,html').animate({
scrollTop : 0 // Scroll to top of body
}, 500);
});
$("#text p").click(function() {
$('html, body').animate({
scrollTop: $(".terms-container").offset().top -80
}, 1000);
});
}
});