var rr = window.rr || {};

/******************
 * Twita@talinkahashifyer
 * http://www.dustindiaz.com/basement/ify.html
 */
var ify = function() {
  return {
    "link": function(t) {
      return t.replace(/(^|\s+)(https*\:\/\/\S+[^\.\s+])/g, function(m, m1, link) {
        return m1 + '<a href="' + link + '">' + ((link.length > 25) ? link.substr(0, 24) + '...' : link) + '</a>';
      });
    },
    "at": function(t) {
      return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, function(m, m1, m2) {
        return m1 + '@<a href="http://twitter.com/' + m2 + '">' + m2 + '</a>';
      });
    },
    "hash": function(t) {
      return t.replace(/(^|\s+)\#([a-zA-Z0-9_]+)/g, function(m, m1, m2) {
        return m1 + '#<a href="http://search.twitter.com/search?q=%23' + m2 + '">' + m2 + '</a>';
      });
    },
    "clean": function(tweet) {
      return this.hash(this.at(this.link(tweet)));
    }
  };
}();


rr.common = (function($) {
  var _setupPrettyPrint = function() {
    //syntax highlighting
    prettyPrint();
    
    $('pre.prettyprint').each(function() {
      var $this = $(this);
      
      $this.after($('<div class="code-popup">Show code in new window</div>').click(function(ev){
        ev.preventDefault();
        var win=window.open('','name','height=500,width=900,scrollbars=yes,resizable=yes');
	      var tmp = win.document;
	      tmp.write('<html><head><title>ricky\'s ghetto code</title>');
	      $('head link[rel="stylesheet"]').each(function(){
            href = jQuery(this).attr('href');
            if (href.indexOf('http') != 0) {
              tmp.write('<link rel="stylesheet" type="text/css" href="' + href + '" />');
            }
          });
	      tmp.write('</head><body class="code-popup"><pre class="prettyprint">');
	      tmp.write($this.html());
	      tmp.write('</pre></body></html>');
	      tmp.close();
	      return false;
      }));
    });
  };
  
  return {
    init:function() {
      _setupPrettyPrint();
    }
  }
})(jQuery);

jQuery(document).ready(rr.common.init);
