function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Creates random masthead background image
function headerBg() {
  var classes = new Array (
    "masthead",
    "masthead-2",
    "masthead-3"
  );
  
  var chosen_class = classes.length;
  var random = Math.floor(chosen_class * Math.random());
  
  if(!document.getElementById("masthead")) return false;
  var header_img = document.getElementById("masthead");
  header_img.setAttribute("id",classes[random]);
}

addLoadEvent(headerBg);
