window.onload = function() {
//object detection to disable older browsers
if (!document.getElementById) {return;}

//create references to the input buttons
var increaseLsButton = document.getElementById('linespace');
var hiltKwdsButton = document.getElementById('keyword');
var hiltTextButton = document.getElementById('hover');
var hideQuoteButton = document.getElementById('quote');

//assign event handlers and functions for buttons
increaseLsButton.onclick = increaseLinespace;
hiltKwdsButton.onclick = highlightKeywords;
hiltTextButton.onclick = highlightTextOnHover;
hideQuoteButton.onclick = hideQuoteText;

//custom function by Dustin Diaz to get elements by class
function getElementsByClass(searchClass, node, tag) {
  var classElements = [];
  if (node == null) {node = document;}
  if (tag == null) {tag = '*';}
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
  for (var i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
      }
  }
  return classElements;
}

//create reference to single elements that will change
var increaseLS = document.getElementById('left');
var p1 = document.getElementById('par1');
var p2 = document.getElementById('par2');
var p3 = document.getElementById('par3');
var p4 = document.getElementById('par4');
var p5 = document.getElementById('par5');
var p6 = document.getElementById('par6');
var p7 = document.getElementById('par7');
var hideQuo = document.getElementsByTagName('blockquote')[0];

//build the array of keywords
var highlightKw = getElementsByClass('kw',document,'span');

//assign event handlers and functions for paragraphs
p1.onmouseover = hiltPar;
p2.onmouseover = hiltPar;
p3.onmouseover = hiltPar;
p4.onmouseover = hiltPar;
p5.onmouseover = hiltPar;
p6.onmouseover = hiltPar;
p7.onmouseover = hiltPar;

p1.onmouseout = noHiltPar;
p2.onmouseout = noHiltPar;
p3.onmouseout = noHiltPar;
p4.onmouseout = noHiltPar;
p5.onmouseout = noHiltPar;
p6.onmouseout = noHiltPar;
p7.onmouseout = noHiltPar;

//function runs when Increase Line Spacing button is clicked
function increaseLinespace() {
  if (this.value == "Increase Line Spacing") {
    //alter the value property for the button
    this.value = "Decrease Line Spacing";
    //increase line spacing on div left to 2.0
    increaseLS.className += ' incls';
    }
  
  else {
    //put the value property of the button back to original value
    this.value = "Increase Line Spacing";
    //return line spacing on div left to original value
    increaseLS.className = '';
    }
}

//function runs when Highlight Keywords button is clicked
function highlightKeywords() {
  if (this.value == "Highlight Keywords") {
    //alter the value property for the button
    this.value = "No Keyword Highlights";
    //changes bg and bolds keywords in div left
    for (var i=0; i < highlightKw.length; i++) {
      highlightKw[i].className += ' hiltkw';
      }
    }
    
  else {
    //put the value property of the button back to original value
    this.value = "Highlight Keywords";
    //remove bg and bold on keywords in div left
    for (var i=0; i < highlightKw.length; i++) {
      highlightKw[i].className = '';
      }
    }  
}

//function runs when Highlight Text On Hover button is clicked
function highlightTextOnHover() {
  if (this.value == "Highlight Text on Hover") {
    //alter the value property for the button
    this.value = "No Text Highlights";
    }
    
  else {
    //put the value property of the button back to original value
    this.value = "Highlight Text on Hover"
    }
}

function hiltPar() {
  if (hiltTextButton.value == "No Text Highlights") {
    this.className = ' hoveron';
    }
}

function noHiltPar() {
  this.className = 'hover';
}

//function runs when Hide Quotations button is clicked
function hideQuoteText() {
  if (this.value == "Hide Quotations") {
    //alter the value property for the button
    this.value = "Show Quotations";
    //blockquote disappears
    hideQuo.className += ' hidden';
    }
  
  else {
    //put the value property of the button back to original value
    this.value = "Hide Quotations";
    //blockquote reappears
    hideQuo.className = '';
    }
}

}