﻿/*
    Copyright Simon Willison, 2004-2007
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*
* blockquotes.js
*
* Updated 6 April 2005 by Bill Humphries
*   Changed test for null cite attribute.
*
* Simon Willison, 20th December 2002
*
* Explanation: 
*   http://simon.incutio.com/archive/2002/12/20/#blockquoteCitations
* Inspired by Adrian Holovaty: 
*   http://www.holovaty.com/blog/archive/2002/12/20/0454
* Alternative implementation of the same idea by Paul Hammond: 
*   http://www.paranoidfish.org/boxes/2002/12/20/
*/

function extractBlockquoteCitations() {
  quotes = document.getElementsByTagName('blockquote');
  for (i = 0; i < quotes.length; i++) {
    cite = quotes[i].cite;
    if (cite.length > 0) {
      newlink = document.createElement('a');
      newlink.setAttribute('href', cite);
      newlink.setAttribute('title', cite);
      newlink.appendChild(document.createTextNode('Source'));
      newdiv = document.createElement('div');
      newdiv.className = 'blockquotesource';
      newdiv.appendChild(newlink);
      
      // Append the div with the citation following the quote
      quotes[i].parentNode.insertBefore(newdiv,quotes[i].nextSibling);
      // quotes[i].appendChild(newdiv);
    }
  }
}

addLoadEvent(extractBlockquoteCitations);
