
(function(){
  console.log('domain',window.location.hostname);
  var scriptElement = document.getElementById("617865a82235646ff16d");
  var custom = {"showBox":false,"sticky":true,"texts":{"en":{"onlineMessage1":"Start a Video Call","onlineMessage2":"We're Online!","offlineMessage1":"Request Call Back","offlineMessage2":"Set Appointment","headline1":"How can we help?","headline2":"Start a call via your browser to talk to us."},"de":{"onlineMessage1":"Videoberatung","onlineMessage2":"ONLINE","offlineMessage1":"Videoberatung","offlineMessage2":"Termin vereinbaren","headline1":"Sprechen Sie mit einem Berater!","headline2":"Starten Sie einen Anruf über Ihren Browser um mit einem unserer Mitarbeiter zu sprechen."}},"delay":1,"position":"bottom-right","positionAdjustment":{"bottom":0,"right":0}};

  var container = document.createElement('div');
  container.id = "617865a82235646ff16d-container";
  container.style.width = '0';
  container.style.height = '0';
  container.style.display = 'none';

  var iframe = document.createElement("iframe");
  var attributes = {
    id: "617865a82235646ff16d-frame",
    name: "617865a82235646ff16d-framename",
    src: "https://embed.callstr.cloud/widget-loader/"+window.location.hostname+"/617865a82235646ff16d?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7fSwiaWF0IjoxNzEwMzkwMDM5LCJleHAiOjE3MTAzOTM2MzksImF1ZCI6IjYxNzg2NWE4MjIzNTY0NmZmMTZkIiwiaXNzIjoiZW1iZWQifQ.VrRJkQSLUe-fgfOKN19d5Nm7llNEekCFqiLzVtSQvCntS6V-q1W32RSQyQyWq5Pph0mjo4xIqd-KjBinTquvoykWZ1VjXB7oVFDw4z4Qpoe6lRC83-siw1jygU11_LL7LxV1juggno3XyhOX1F4qM3DTx57T5p86Ww0aa4OaWgo",
    allow: "microphone; camera; speaker; fullscreen; display-capture",
    scrolling: "no",
    frameborder: "0"
  };

  for(var attr in attributes){
    iframe[attr] = attributes[attr];
  }

  iframe.style.border = 'none';
  iframe.style.position = "absolute";
  iframe.style.top = "0";
  iframe.style.left = "0";
  iframe.style.bottom = "0";
  iframe.style.right = "0";
  iframe.style.width = "100%";
  iframe.style.height = "100%";
  iframe.style.minHeight = "100%";
  iframe.style.minWidth = "100%";

  container.appendChild(iframe);
  if(custom && custom.showBox){
    scriptElement.parentNode.insertBefore(container, scriptElement.nextSibling);
  }
  else{
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(container);
  }



  window.addEventListener("message", function(e){
    if (event.origin !== "https://embed.callstr.cloud"){
    return;
  }

    if (e.data.hasOwnProperty("callstr")) {
      console.log('receivedMessage',e.data.callstr);

      for(var id in e.data.callstr){
        var item = e.data.callstr[id];
        var el = document.getElementById(id+'-container');
        if(item.style){
          el.setAttribute('style', item.style);
        }

        if(item.tokenExpired){
          document.location.reload();
        }
      }
    }
  });
})();
