/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mike Papageorge | http://www.fiftyfoureleven.com/ */
*	-------------------------------------------------------
*	Kudos to Simon Willison and the links within the following:
*	http://simon.incutio.com/blockquotesNS.js
*
*	Related Blog Post: http://www.fiftyfoureleven.com/sandbox/weblog/2004/jun/javascript-pullquote/
*
*/

function makepullquote() {
parentDiv = document.getElementById("pullQuote");		// Node for inserting pullquote
spans = parentDiv.getElementsByTagName('span');		// Get all Span elements from the parentDiv

for (i = 0; i < spans.length; i++) {	// For each span
  	var span = spans[i];
  	var up = span.parentNode;	// Needed as a target for insertion.

 		if(span.className == "pullquote") {	// Check if it's a pullquote and generate a pullquote

   		// Create the blockquote with a class of pullquote
   		var pullquote = document.createElement("blockquote");
   		pullquote.className = "pullquote";

   		// Create the paragraph tag for the blockquote
   		var paragraph = document.createElement("p");

   		// I ran into some trouble when cloning the node, Opera went into an infinite loop,
   		// a result of, I suppose, having the 'pullquote' class in the span.
   		// The folliowing two lines solve the problem by removing the class from the span.
   		var zspan = span;
   		zspan.className = ""; // Insert class name here if desired

   		// Sticks the span into the generated paragraph
   		paragraph.appendChild(zspan.cloneNode(true));

   		// Sticks the generated paragraph into the generated blockquote
   		pullquote.appendChild(paragraph);

   		// Inserts the pullquote before the <p> that contains the <span class="pullquote">
   		parentDiv.insertBefore(pullquote,up);
 		 }
 	}
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  makepullquote();
});

