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

// Generates random text
function randomFact() {
  var facts = new Array(

    "Back in the old days, our books were displayed in old Canada Dry crates, stacked precariously on top of each other and labeled with sharpie markers!",

    "Although the Chattanooga store has more floor space, the Knoxville store has more shelves.",

    "If you combined all the shelves in all three McKay stores, you'd have over 10 miles of shelf space! Happy Browsing!",

    "It is 92 miles from the Knoxville store to the Chattanooga store (a little longer if you drive in circles in the parking lot!)."
  );
  
  // set the math function to produce a random result
  var chosen_fact = facts.length;
  var random = Math.floor(chosen_fact * Math.random());
  
  // create the markup
  var id = document.getElementById("fun_fact");
  var heading = document.createElement("h2");
  var heading_txt = document.createTextNode("Fun Fact");
  heading.appendChild(heading_txt);
  id.appendChild(heading);
  var para = document.createElement("p");
  id.appendChild(para);
  
  var fact_text = document.createTextNode(facts[random]);
  para.appendChild(fact_text);
}

addLoadEvent(randomFact);