/*
*	pullQuote.js
*	Mike Papageorge, 2nd May, 2004 (updated 14th May, 2004)
*	-------------------------------------------------------
*	Some details: 
*
*	Kudos (once again) to Simon Willison and the links within the following:
* 	http://simon.incutio.com/blockquotesNS.js
*
*	Current version: http://www.fiftyfoureleven.com/j/pullQuote.js
*	Related Blog Post: http://www.fiftyfoureleven.com/sandbox/weblog/2004/jun/javascript-pullquote/
*	
*	Note: The resulting inserted pullquote has the following markup:
*	<blockquote>
*	<p>
*	<span class="">
*	This is some text in a pull quote.
*	</span>
*	</p>
*	</blockquote>
*
*	You can insert a class name into the span by specifying a name between the brackets down 
*	on line 48.
*
*/	

function makepullquote() {
parentDiv = document.getElementById("colA");		// 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);	
		}
	}
}
window.onload = makepullquote;