(function(){Lighter=new Class({Implements:[Options],name:"Lighter",options:{altLines:"",clipboard:null,container:null,editable:false,flame:"standard",fuel:"standard",id:null,indent:-1,matchType:"standard",mode:"pre",path:null,strict:false},initialize:function(d,c){this.setOptions(c);this.id=this.options.id||this.name+"_"+$time();this.codeblock=$(d);this.container=$(this.options.container);this.code=a(this.codeblock.get("html")).replace(/</gim,"<").replace(/>/gim,">").replace(/&/gim,"&");if(this.options.indent>-1){this.code=b(this.code,this.options.indent)}this.getPath();this.getClass();this.builder=new Hash({inline:this.createLighter.pass("code",this),pre:this.createLighter.pass("pre",this),ol:this.createLighterWithLines.pass([["ol"],["li"]],this),div:this.createLighterWithLines.pass([["div"],["div","span"],true,"span"],this),table:this.createLighterWithLines.pass([["table","tbody"],["tr","td"],true,"td"],this)});Lighter.scripts=Lighter.scripts||{};Lighter.stylesheets=Lighter.stylesheets||{};this.loadStylesheet(this.options.flame,"Flame."+this.options.flame+".css");this.loadFuel()},loadFuel:function(){try{this.fuel=new Fuel[this.options.fuel](this.code,{matchType:this.options.matchType,strict:this.options.strict});this.light()}catch(c){this.loadScript(this.options.fuel,"Fuel."+this.options.fuel+".js",{load:this.loadFuel.bind(this),error:function(){this.options.fuel="standard";this.loadFuel()}.bind(this)})}},light:function(){this.element=this.toElement();if(this.container){this.container.empty();this.element.inject(this.container)}else{this.codeblock.setStyle("display","none");this.element.inject(this.codeblock,"after");if(this.options.clipboard){this.loadClipboard()}}},unlight:function(){$(this).setStyle("display","none");this.codeblock.setStyle("display","inherit")},loadClipboard:function(){try{var c=new ZeroClipboard.Client();c.setPath(this.options.path);c.glue($(this.options.clipboard));c.setText(this.code);c.addEventListener("complete",function(e,f){alert("Copied text to clipboard:\n"+f)})}catch(d){this.loadScript("clipboard","ZeroClipboard.js",{load:this.loadClipboard.bind(this),error:$empty});return false}},getPath:function(){if(!$chk(Lighter.path)){$$("head script").each(function(d){var c=d.src.split("?",1),e=/Lighter(\.full|\.lite)?\.js$/gi;if(c[0].match(e)){Lighter.path=c[0].replace(e,"")}})}if(!this.options.path){this.options.path=Lighter.path}},getClass:function(){var d=this.codeblock.get("class").split(" "),c=[null,null];switch(d.length){case 0:break;case 1:c=d[0].split(":");break;default:c=d[0].split(":")}if(c[0]){this.options.fuel=c[0]}if(c[1]){this.options.flame=c[1]}},loadScript:function(d,e,c){if($chk(Lighter.scripts[d])){Lighter.scripts[d].addEvents({load:c.load,error:c.error,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){c.load()}}})}else{Lighter.scripts[d]=new Element("script",{src:this.options.path+e+"?"+$time(),type:"text/javascript",events:{load:c.load,error:c.error,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){c.load()}}}}).inject(document.head)}},loadStylesheet:function(c,d){if(!$chk(Lighter.stylesheets[c])){Lighter.stylesheets[c]=new Element("link",{rel:"stylesheet",type:"text/css",media:"screen",href:this.options.path+d+"?"+$time()}).inject(document.head)}},createLighter:function(d){var c=new Element(d,{"class":this.options.flame+this.name}),e=0;if(!$defined(this.fuel.wicks[0])){c.appendText(this.code)}else{this.fuel.wicks.each(function(f){c.appendText(this.code.substring(e,f.index));this.insertAndKeepEl(c,f.text,f.type);e=f.index+f.text.length},this);if(e0){var d=new Element("span",{text:f});if(c){d.addClass(this.fuel.aliases[c]||c)}d.inject(e)}},insertAndMakeEl:function(d,e,f,h,c){this.insertAndKeepEl(d,f,c);if(h[1]){d=d.getParent()}d.inject(e);var g=new Element(h[0]);if(h[1]){g=new Element(h[1]).inject(g)}g.addClass(this.options.flame+"line");return g},insertLineNum:function(d,f,c){var e=new Element(c,{text:f++,"class":this.options.flame+"num"});e.inject(d.getParent(),"top");return f},toElement:function(){if(!this.element){this.element=this.builder[this.options.mode]();if(this.options.editable){this.element.set("contenteditable","true")}}return this.element}});Element.implement({light:function(c){return new Lighter(this,c)}});function a(c){return c.replace(/(^\s*\n|\n\s*$)/gi,"")}function b(f,d){for(var e=0,c="";e=this.index&&a.index=a.end)},overlaps:function(a){return(this.index==a.index&&this.length>a.length)},toString:function(){return this.index+" - "+this.text+" - "+this.end}});