//makes an email link (spam is bad, mmkay?)
function email( last, first, linktext ) {
  document.write( "<a href=\"mailto:" + first + "@" + last + "\">" + linktext + "</a>" );
}

//may or may not get the "Y" location of an object
//  is recursive, so may break~~~
function gety( obj ) {
  //alert( "in" );
  var d = obj;
  var t = d.offsetTop;

  if ( d.offsetParent != document.getElementsByTagName( "body" )[0] ) {
    t += gety( d.offsetParent );
  }

  return t;
}

//makes a blueish background color depending on the local time
function bgc() {
  var d = new Date();
  var m = d.getHours() * 60 + d.getMinutes();
  var p = m % 720 / 720;
  if ( m > 720 ) {
    p = 1 - p;
  }
  var r = Math.floor( p * 231 + 5 );
  var g = Math.floor( p * 174 + 76 );
  var b = Math.floor( p * 155 + 100 );
  document.getElementsByTagName( "body" )[0].style.backgroundColor = "rgb( " + r + ", " + g + ", " + b + " )";
}

//makes a link to validate the current location
function makevalidator( linktext ) {
  document.write( "<a href=\"http://validator.w3.org/check?uri=" + location + "\">" + linktext + "</a>" );
}

//makes a link to validate the current stylesheet
function makecssvalidator( linktext ) {
  document.write( "<a href=\"http://jigsaw.w3.org/css-validator/validator?uri=" + location + "\">" + linktext + "</a>" );
}

//adds an anchor to each spoiler span
//should be run on window.onload
function makeSpoiler() {
  var spans = document.getElementsByTagName( "span" );
  for ( var i = 0; i < spans.length; i++ ) {
    if ( spans[i].getAttribute( "class" ) == "spoiler" ||
         spans[i].className == "spoiler" ) {
      //append a link to spoil
      var anchor = document.createElement( "a" );
      anchor.style.cursor = "pointer";
      anchor.style.color = "black";
      anchor.onclick = function() { spoil( this ); };
      anchor.appendChild( document.createTextNode( "SPOILERS: click to view" ) );
      //anchor.appendChild( document.createElement( "br" ) );
      spans[i].insertBefore( anchor, spans[i].firstChild );
    }
  }
}

//removes a spoiler anchor and unhides the spoiler text
function spoil( anchor ) {
  //remove the black background color
  anchor.parentNode.style.backgroundColor = "transparent";
  anchor.parentNode.style.color = "black";
  anchor.parentNode.style.borderStyle = "hidden";
  //remove the anchor
  anchor.parentNode.removeChild( anchor );
}


/*********ALL WINDOW.ONLOAD STUFF GOES HERE*************/
function wol() {
  //make the background color change every minute
  bgc();
  setInterval( "bgc();", 60000 );
  
  //create the spoiler spans
  makeSpoiler();
}

window.onload = wol;
