document.addEventListener("DOMContentLoaded",function(){const animationDiv=document.getElementById("animation");if(animationDiv){const canvas=document.createElement("canvas");const ctx=canvas.getContext("2d");animationDiv.appendChild(canvas);const scale=window.devicePixelRatio;function resizeCanvas(){canvas.width=animationDiv.offsetWidth*scale;canvas.height=animationDiv.offsetHeight*scale;canvas.style.width=animationDiv.offsetWidth+"px";canvas.style.height=animationDiv.offsetHeight+"px"}
window.addEventListener("resize",resizeCanvas);resizeCanvas();const colors=["#000","#ec5b29","#93fa7d","#a585f7"];const minSize=10;const maxSize=15;const minSpeed=-2;const maxSpeed=2;const minPhase1Duration=2000;const maxPhase1Duration=6000;const phase2Duration=2000;const numberOfPoints=50;const centerAreaRadius=500;const offsetRightPercent=25;const offsetUpPercent=15;const breakpoints={xs:{offsetRightPercent:-22,offsetUpPercent:18},sm:{offsetRightPercent:-24,offsetUpPercent:20},md:{offsetRightPercent:30,offsetUpPercent:15},lg:{offsetRightPercent:30,offsetUpPercent:15},xl:{offsetRightPercent:30,offsetUpPercent:15},xxl:{offsetRightPercent:25,offsetUpPercent:15}};function getCurrentOffsets(){const width=window.innerWidth;if(width<576){return breakpoints.xs}else if(width>=576&&width<768){return breakpoints.sm}else if(width>=768&&width<992){return breakpoints.md}else if(width>=992&&width<1200){return breakpoints.lg}else if(width>=1200&&width<1400){return breakpoints.xl}else{return breakpoints.xxl}}
class Point{constructor(){this.reset();this.phase1EndTime=Date.now()+minPhase1Duration+Math.random()*(maxPhase1Duration-minPhase1Duration);this.inCenterDuration=0}
reset(){do{this.x=Math.random()*canvas.width;this.y=Math.random()*canvas.height;this.size=(Math.random()*(maxSize-minSize)+minSize)*scale;this.color=colors[Math.floor(Math.random()*colors.length)];this.speedX=Math.random()*(maxSpeed-minSpeed)+minSpeed;this.speedY=Math.random()*(maxSpeed-minSpeed)+minSpeed;this.phase1EndTime=Date.now()+minPhase1Duration+Math.random()*(maxPhase1Duration-minPhase1Duration)}while(this.isOverlappingWithAnyPoint());}
isOverlappingWithAnyPoint(){for(let point of points){if(point!==this&&this.distanceTo(point)<this.size+point.size){return!0}}
return!1}
move(){this.x+=this.speedX;this.y+=this.speedY;this.handleCollisions();if(this.x<0||this.x>canvas.width)this.speedX*=-1;if(this.y<0||this.y>canvas.height)this.speedY*=-1}
handleCollisions(){points.forEach((otherPoint)=>{if(otherPoint!==this&&this.isCollidingWith(otherPoint)){const tempSpeedX=this.speedX;const tempSpeedY=this.speedY;this.speedX=otherPoint.speedX;this.speedY=otherPoint.speedY;otherPoint.speedX=tempSpeedX;otherPoint.speedY=tempSpeedY}})}
isCollidingWith(otherPoint){const distance=this.distanceTo(otherPoint);return distance<this.size+otherPoint.size}
distanceTo(otherPoint){return Math.sqrt((this.x-otherPoint.x)**2+(this.y-otherPoint.y)**2)}
moveToCenter(){const{offsetRightPercent,offsetUpPercent}=getCurrentOffsets();const offsetX=(canvas.width*offsetRightPercent)/100;const offsetY=(canvas.height*offsetUpPercent)/100;const centerX=(canvas.width/2)+offsetX;const centerY=(canvas.height/2)-offsetY;const distanceToCenter=this.distanceTo({x:centerX,y:centerY});let movementFactor=20;if(distanceToCenter<centerAreaRadius){movementFactor+=(centerAreaRadius-distanceToCenter)/10}
this.x+=(centerX-this.x)/movementFactor;this.y+=(centerY-this.y)/movementFactor;this.avoidOverlapping()}
avoidOverlapping(){points.forEach((point)=>{if(point!==this&&this.distanceTo(point)<this.size+point.size){const angle=Math.atan2(this.y-point.y,this.x-point.x);const overlapDistance=this.size+point.size-this.distanceTo(point);const repulsionDistance=overlapDistance/2;if(this.isAtCenter()&&point.isAtCenter()){this.x+=Math.cos(angle)*repulsionDistance*2;this.y+=Math.sin(angle)*repulsionDistance*2}else{this.x+=Math.cos(angle)*repulsionDistance;this.y+=Math.sin(angle)*repulsionDistance}}})}
isAtCenter(){const centerX=canvas.width/2;const centerY=canvas.height/2;return this.distanceTo({x:centerX,y:centerY})<centerAreaRadius}
draw(){ctx.beginPath();ctx.arc(this.x,this.y,this.size,0,2*Math.PI);ctx.fillStyle=this.color;ctx.fill()}
update(){if(Date.now()<this.phase1EndTime){this.move();this.inCenterDuration=0}else{this.moveToCenter();if(this.isAtCenter()){this.inCenterDuration+=Date.now()-this.lastUpdateTime}else{this.inCenterDuration=0}}
this.lastUpdateTime=Date.now();this.draw()}}
const points=[];for(let i=0;i<numberOfPoints;i++){points.push(new Point())}
function animate(){ctx.clearRect(0,0,canvas.width,canvas.height);points.forEach((point)=>point.update());requestAnimationFrame(animate)}
function allPointsAtCenter(){return points.every((point)=>point.inCenterDuration>=phase2Duration)}
animate()}});const logoPlaceholders=document.getElementsByClassName('guter-rat-logo');const logosS=['https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-5.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-6.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-4.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-2.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-3.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-1.svg'];const logosM=['https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-5.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-6.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-4.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-2.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-3.svg','https://guterrat.info/wp-content/uploads/2023/12/guter-rat-logo-gr-1.svg'];const logosL=['https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v5.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v3.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v4.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v2.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v1.svg'];const logosXL=['https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v5.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v3.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v4.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v2.svg','https://guterrat.info/wp-content/uploads/2023/12/gr-logo-black-v1.svg'];function getLogosForBreakpoint(){const width=window.innerWidth;if(width<767){return logosS}else if(width>=767&&width<1024){return logosM}else if(width>=1024&&width<1366){return logosL}else{return logosXL}}
let currentBreakpoint=getBreakpoint();let currentLogo='';function getBreakpoint(){const width=window.innerWidth;if(width<767){return'S'}else if(width>=767&&width<1024){return'M'}else if(width>=1024&&width<1366){return'L'}else{return'XL'}}
function updateLogos(){const newBreakpoint=getBreakpoint();if(currentBreakpoint!==newBreakpoint||!currentLogo){currentBreakpoint=newBreakpoint;for(let logoPlaceholder of logoPlaceholders){if(logoPlaceholder.firstChild){logoPlaceholder.removeChild(logoPlaceholder.firstChild)}
const currentLogos=getLogosForBreakpoint();const chosenLogo=currentLogos[Math.floor(Math.random()*currentLogos.length)];currentLogo=chosenLogo;const img=document.createElement('img');img.src=chosenLogo;logoPlaceholder.appendChild(img)}}}
updateLogos();window.addEventListener('resize',updateLogos);document.addEventListener('DOMContentLoaded',function(){const farbschemata={schema1:{a:'#EDEBE8',b:'#EDEBE8',c:'#EDEBE8'},schema2:{a:'#FF6400',b:'#FFA500',c:'#FF7800'},schema3:{a:'#B4FF50',b:'#6EFF64',c:'#D2FF00'},schema4:{a:'#B496FF',b:'#CDBEFF',c:'#A0A0FF'}};const gespeichertesSchema=getCookie('guter-rat');if(gespeichertesSchema){setzeFarbschema(gespeichertesSchema)}
document.querySelectorAll('.farbwahler div').forEach(link=>{link.addEventListener('click',function(event){event.preventDefault();const schemaId=this.id;setzeFarbschema(schemaId);setCookie('guter-rat',schemaId,7)})});function setzeFarbschema(schemaId){const farben=farbschemata[schemaId];document.querySelectorAll('.farbe-a').forEach(div=>{div.style.backgroundColor=farben.a});document.querySelectorAll('.farbe-b').forEach(div=>{div.style.backgroundColor=farben.b});document.querySelectorAll('.farbe-c').forEach(div=>{div.style.backgroundColor=farben.c});document.querySelectorAll('.faerbe-svg svg').forEach(svg=>{svg.style.fill=(schemaId=='schema1')?'#000000':waehleZufaelligeFarbe(farben)})}
function waehleZufaelligeFarbe(farbschema){const farbschluessel=Object.keys(farbschema);let zufaelligerSchluessel=farbschluessel[Math.floor(Math.random()*farbschluessel.length)];return farbschema[zufaelligerSchluessel]}
function setCookie(name,value,days){let expires="";if(days){let date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toUTCString()}
document.cookie=name+"="+(value||"")+expires+"; path=/"}
function getCookie(name){let nameEQ=name+"=";let ca=document.cookie.split(';');for(let i=0;i<ca.length;i++){let c=ca[i];while(c.charAt(0)===' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)===0)return c.substring(nameEQ.length,c.length);}
return null}});document.addEventListener('DOMContentLoaded',function(){const bilder=['https://guterrat.info/wp-content/uploads/2023/12/was-ist-der-gute-rat-1.svg','https://guterrat.info/wp-content/uploads/2023/12/was-ist-der-gute-rat-2.svg','https://guterrat.info/wp-content/uploads/2023/12/was-ist-der-gute-rat-3.svg','https://guterrat.info/wp-content/uploads/2023/12/was-ist-der-gute-rat-4.svg','https://guterrat.info/wp-content/uploads/2023/12/was-ist-der-gute-rat-5.svg',];const zielBild=document.querySelector(".zielBild img");if(!zielBild){console.error('Das zielBild existiert nicht auf der Seite.');return}
function wechsleGrafik(){const zufallsIndex=Math.floor(Math.random()*bilder.length);zielBild.src=bilder[zufallsIndex]}
setInterval(wechsleGrafik,1000);wechsleGrafik()});document.addEventListener('DOMContentLoaded',function(){const bilderEN=['https://guterrat.info/wp-content/uploads/2024/01/who-is-guter-rat.svg','https://guterrat.info/wp-content/uploads/2024/01/where-is-guter-rat.svg','https://guterrat.info/wp-content/uploads/2024/01/when-is-guter-rat.svg','https://guterrat.info/wp-content/uploads/2024/01/what-is-guter-rat.svg',];const zielBildEN=document.querySelector(".zielBildEN img");if(!zielBildEN){console.error('Das zielBildEN existiert nicht auf der Seite.');return}
function wechsleGrafikEN(){const zufallsIndexEN=Math.floor(Math.random()*bilderEN.length);zielBildEN.src=bilderEN[zufallsIndexEN]}
setInterval(wechsleGrafikEN,1000);wechsleGrafikEN()})