/**
 *
 * SVN Infos:
 * Revision				: $Revision: 51 $
 * Date					: $Date: 2011-01-09 02:35:19 +0100 (Sun, 09 Jan 2011) $
 * 
 * Copyright			: http://wiltonsoftware.com/posts/view/geshi-code-to-plain-text-jquery-javascript-toggle#null
 * 
 */

/*
 * toggle for geshi plain to hightlighed box
 */
$(document).ready(function() {
	jQuery(".code").each(function() {
		var block = jQuery(this);
		var htmlText = block.html();
		var plainText = "";
		if (jQuery.browser.msie) {
		  plainText = htmlText.replace(/\n/g, "+");
		  plainText = jQuery(plainText).text().replace(/\+\+/g, "\r");
		} else {
		  plainText = block.text().replace(/code/g, "code\n");
		}
		var state = 1;
		block.prev().click(function() {
		  if (state) {
			jQuery(this).html("Show Highlighted Code");
			block.text(plainText).wrapInner("<pre class=\"plain-text\"></pre>");
			state = 0;
		  } else {
			jQuery(this).html("Show Plain Text");
			block.html(htmlText);
			state = 1;
		  }
		});
	});
});

