jQuery(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;
      }
    });
  });
});
