function gteq (a,b) {
    return a >= b;
}

const escapeHTML = (str) =>
  str.replace(
    /[&<>'"]/g,
    (tag) =>
      ({
        "&": "&amp;",
        "<": "&lt;",
        ">": "&gt;",
        "'": "&#39;",
        '"': "&quot;"
      }[tag])
  );
  const unescapeHTML = (str) =>
    str.replace(
      /(&gt;|&lt;|&amp;|&quot;|&apos;)/g,
      (tag) =>
        ({
          "&amp;"  : "&",
          "&lt;"   : "<",
          "&gt;"   : ">",
          "&#39;"  : "'",
          "&quot;" : '"'
        }[tag])
    );


/* see options at
 https://beautifier.io/
 */
var beautify_config = {
  "indent_size" : 2,
  "indent_char" : " ",
  "wrap_line_length" : "120",
  "brace_style" : "collapse",
  "max_preserve_newlines" : 1,
  "indent_empty_lines" : false
};

$(document).ready(function(){

  /* add prism class to prism-styled pre and code blocks
      main reason is so we can style code blocks not handled by prism!
  */
  $('pre[class*="language-"]').addClass('prism');
  $('pre[class*="language-"] code').addClass('prism');
  $('code[class*="language-"]').addClass('prism');
  /* === end === */

  /* beautify code examples for display
      Note that this does spacing, indentation, and line returns
      only.
      the syntax highlighting and colorizing is done through prismjs
      */
  htmlexamples = $("pre[class ~= 'language-html'] code");
  cssexamples  = $("pre[class ~= 'language-css'] code");
  jsexamples   = $("pre[class ~= 'language-javascript'] code");

  for (ex of htmlexamples) {
    markuptxt = ex.textContent;
    var result = html_beautify(markuptxt, beautify_config);
    ex.innerHTML = escapeHTML(result);
  }

  for (ex of cssexamples) {
    csstxt = ex.textContent;
    console.log(csstxt);
    var result = css_beautify(csstxt, beautify_config);
    ex.innerHTML = result;
  }

  for (ex of jsexamples) {
    jstxt = ex.textContent;
    console.log(jstxt);
    var result = js_beautify(jstxt, beautify_config);
    console.log(result);
    ex.innerHTML = result;
  }
  /* === end === */

  /* implement jquery ui tabs for the code blocks
      html, css, js, screenshots
      */
  $('*[id^=example-container]').each(function(index,elem){
    $(elem).tabs({selected: $(elem).attr("data-tabselected")});
  });
  /* === end === */

  /* turn off things that make sense only for local running */
  var $myhost = location.host;
  if ($myhost.match(/localhost/)) {
    //$('.hide-for-localhost').hide();
  }
  /* === end === */


  /* create "See Example in JSFiddle" */
  /* try modifying existing */
  for (ex of $("textarea[name='html']")) {
    markuptxt = ex.textContent;
    var result = html_beautify(markuptxt, beautify_config);
    ex.textContent = result;
  }
  for (ex of $("textarea[name='css']")) {
    txt = ex.textContent;
    var result = css_beautify(txt, beautify_config);
    ex.textContent = result;
  }
  for (ex of $("textarea[name='js']")) {
    markuptxt = ex.textContent;
    var result = js_beautify(markuptxt, beautify_config);
    ex.textContent = result;
  }

  /* Invoke prism manually */
  Prism.highlightAll();
});



document.addEventListener("DOMContentLoaded", function () {
//  Prism.highlightAll();
/* if on slide */
if ($('h2').length == 1) {
  $('h2#thankyou').parents('main').addClass('thankyou');
}

});
