// pyg.js @nijikokun AOL <http://aol.nexua.org>
var pyg={options:{theme:"default",loadTheme:!0,loadThemeWithCode:!1,numbered:!1,debugging:!1},run:function(){!0===this.options.debugging&&console.log(this.options);this.options.loadTheme&&this.useStyle(this.options.theme);jQuery("pre").each(function(){var a=jQuery(this),b=a.html(),c=a.attr("language")||a.attr("lang")||a.attr("l"),a=a.attr("lines")||null;c&&!(1>b.length)&&(b=pyg.highlight(c,b,a),null!=b&&jQuery(this).replaceWith(b))});jQuery(".highlight").live("dblclick",function(){var a=jQuery(this),
b=a.html(),c=a.text(),d=a.find("pre").height(),e=a.find("pre").width();a.html('<span style="display: none;">'+b+'</span><textarea class="pyg">'+c.replace(/\s+$/,"")+"</textarea>");a.find("textarea").height(d).width(e).focus().select()});jQuery(document).bind("click",function(a){if(0==jQuery(a.target).closest("textarea.pyg").length){var a=jQuery("textarea.pyg").parent(),b=a.find("span").html();a.html(b)}})},getStyles:function(){},getStyle:function(a){!0===this.options.debugging&&console.log("pyg.getStyle()",
"name: "+a);a||(a="default");var b=null;jQuery.ajax({async:!1,global:!1,url:"http://pyg.nexua.org/api/style/"+a,type:"GET",success:function(a){b=a},fail:function(a,b){pyg.options.debugging&&console.log(a,b);throw"Failed to recieve code back.";}});return b},useStyle:function(a){!0===this.options.debugging&&console.log("pyg.useStyle()","name: "+a);jQuery("body").append("<style>"+pyg.getStyle(a)+"</style>")},highlight:function(a,b,c){!0===this.options.debugging&&console.log("pyg.highlight()","lang: "+
a,"code: "+b,"lines: "+c);if(!a)throw"[p.n.o] Language is missing!";if(!b||1>b.length)throw"[p.n.o] Cannot highlight nothing!";var d=null,a={code:b.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),lang:a};c&&(a.highlight=c);if(this.options.loadThemeWithCode)a.style=this.options.theme;this.options.numbered&&(a.numbered=!0);jQuery.ajax({async:!1,global:!1,url:"http://pyg.nexua.org/api/highlight",type:"POST",data:a,dataType:"html",success:function(a){d=a},fail:function(a,b){pyg.options.debugging&&
console.log(a,b);throw"Failed to recieve code back.";}});return d}};
