var HgDebug=new Class({debug:0,hgCore:false,setHgCore:function(A){this.hgCore=A;this.debug=this.hgCore.debug;},debugMsg:function(B,D){if(this.debug){var A="",C;B=B+0;if(this.hgCore&&this.name){A="["+this.name+"] ";}C=["Hg Error: ","Hg Warning: ","Hg Notice: "];console.log(C[B]+A+D);}},debugLoadMsg:function(){if(this.debug){var A="Hg Module Loaded: "+this.name+" (v"+this.version+")",B=this.listAllOptions();if(B){A+="\nOptions: "+B;}console.log(A);}},listAllOptions:function(){if(!this.donotdebugoptions){var B="",A="",C="";$H(this.options).each(function(E,D){if(typeof (E)=="string"){C="'";}B+=A+D+" = "+C+E+C;A=", ";C="";});if(B){return B;}else{return false;}}else{return false;}}});var HgCore=new Class({Implements:[Options,Events,HgDebug],name:"Hg (mercury) Javascript Library",version:1,options:{debug:0,autoBoot:0,timeout:16},initialize:function(A){this.setOptions(A);this.modules=$H();this.commonCache=$H();this.injectedFiles=[];this.debug=0;this.timeout=this.options.timeout*1000;this.documenthead=$$("head")[0];
if($("hg_core")){this.libpath=$("hg_core").getProperty("src").replace("hg_core.js","");}this.defineLibrary();if(this.options.autoBoot){this.bootstrap();}if(this.options.debug&&typeof (console)!="undefined"){this.debug=1;var B=this.listAllOptions();if(this.libpath){console.log("Hg Library (v"+this.version+") loaded.\nPath: '"+this.libpath+"'\nMooTools version: "+MooTools.version+"\nOptions: "+B);}else{console.log("Hg Library loaded with errors. Version: "+this.hgVersion+' Path unknown. Please add id="hg_core" to script declaration\nOptions: '+B);}}},injectScript:function(A,C){var B;if(C){A=this.libpath+A;}if(this.injectedFiles.indexOf(A)==-1){B=new Element("script",{type:"text/javascript",src:A}).injectInside(this.documenthead);this.injectedFiles.push(A);}},htmlContentChanged:function(A){this.allModulesAutoAttach(A);this.fireEvent("htmlChanged",A);},storeModule:function(C,B,G,F,E,A){var D={path:C,dependencies:G,autoLaunch:F,attach:E,relativePath:A,pointer:null,options:null};this.modules.set(B,D);
},loadModule:function(A){var C=this.modules.get(A),B;if(C){if(C.pointer===null){if(C.dependencies){B=$A(C.dependencies.split(","));B.each(function(D){if(this.modules.get(D).pointer===null){this.loadModule(D);}}.bind(this));this.loadAfterDependencies(A,B,0);}else{this.injectScript(C.path,C.relativePath);}}else{this.debugMsg(2,"requested module ('"+A+"') already loaded");return false;}}else{this.debugMsg(0,"requested module ('"+A+"') is not defined, cannot load");return false;}},loadAfterDependencies:function(C,H,F){var B=H.length,G=0,A,E,D;H.each(function(I){if(this.modules.get(I).pointer){G++;}}.bind(this));if(G<B){if(F<this.timeout){A=F+100;E=[C,H,A];this.loadAfterDependencies.delay(100,this,E);}else{this.debugMsg(0,"requested module ('"+C+"') could not load, dependency loading exceeded timeout");}}else{D=this.modules.get(C);this.injectScript(D.path,D.relativePath);}},getModule:function(B){var A=this.modules.get(B);if(A){return A.pointer;}else{return null;}},getModuleOptions:function(B){var A=this.modules.get(B);
if(A){return A.options;}else{return null;}},setModuleOptions:function(A,B){var C=this.modules.get(A);if(C){C.options=B;}this.modules.set(A,C);},setModulePointer:function(B,A){var C=this.modules.get(B);if(C){C.pointer=A;}this.modules.set(B,C);},moduleCallback:function(A){if(typeof (A)=="object"){if(this.modules.has(A.name)){this.setModulePointer(A.name,A);}else{this.storeModule(0,A.name,0);this.setModulePointer(A.name,A);}this.fireEvent("moduleLoad",A.name);A.debugLoadMsg();this.moduleAutoAttach(A.name);}else{this.debugMsg(0,"moduleCallback() must be provided with an object");}},moduleAutoAttach:function(B,D){var C=this.modules.get(B),A,E;if(C.autoLaunch&&C.attach&&typeof (C.pointer.attachToElement)=="function"){A=$A(C.autoLaunch.split(","));E=$$(A);if(E.length>0){if(!D){$$(A).each(function(F){C.pointer.attachToElement(F);});}else{A.each(function(F){$(D).getElements(F).each(function(G){C.pointer.attachToElement(G);});});}}}},allModulesAutoAttach:function(A){this.modules.each(function(C,B){if(C.autoLaunch&&C.pointer){if(!A){this.moduleAutoAttach(B);
}else{this.moduleAutoAttach(B,A);}}}.bind(this));},registerModule:function(C,B){C.implement(new HgDebug());var A=this.getModuleOptions(B),D;if(A){D=new C(A);}else{D=new C();}D.setHgCore(this);this.moduleCallback(D);},bootstrap:function(){var B=[],A;this.modules.each(function(D,C){if(D.autoLaunch&&!D.pointer){A=$A(D.autoLaunch.split(","));if($$(A).length>0){this.loadModule(C);B.push(C);}}}.bind(this));if(B.length>0){this.debugMsg(2,"boot started, attempting to load necessary modules ("+B.join(", ")+")");}this.checkBootStatus(B,0);},checkBootStatus:function(A,D){if(A.length==0){this.fireEvent("bootComplete",true);}else{var F=A.length,E=0,B,C;A.each(function(G){if(this.modules.get(G).pointer){E++;}}.bind(this));if(E<F){if(D<(this.timeout+2000)){B=D+100;C=[A,B];this.checkBootStatus.delay(100,this,C);}else{this.fireEvent("bootComplete",false);this.debugMsg(1,"boot failure, could not load all modules");}}else{this.fireEvent("bootComplete",true);this.debugMsg(2,"boot successfully completed");}}},defineLibrary:function(){this.storeModule("enhancements/hg_anchor.js","linkexternal",0,"a.external",1,1);
this.storeModule("enhancements/hg_anchor.js","linkpopup",0,"a.popup",1,1);this.storeModule("enhancements/hg_anchor.js","linkinside",0,"a.hg_linkinside",1,1);this.storeModule("enhancements/hg_anchor.js","drawer",0,"a.hg_drawertoggle",1,1);this.storeModule("utility/hg_utility.js","utility",0,0,0,1);this.storeModule("media/hg_overlay.js","overlay",0,0,0,1);this.storeModule("media/hg_imagebox.js","imagebox","utility,overlay","a.hg_imagebox,div.hg_imagebox",1,1);this.storeModule("media/hg_moviebox.js","moviebox","utility,overlay","a[href$=.mov],a[href$=.mp4],a[href$=.MOV],a[href$=.MP4],a[href^=http://www.youtube.com/watch?v],a[href^=http://youtube.com/watch?v],a[href^=http://vimeo.com/],a[href^=http://www.vimeo.com/],a[href^=http://video.google.com/videoplay?docid],a[href^=http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid],a[href^=http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid]",1,1);},clearAutoLoad:function(A){var B=this.modules.get(A);B.autoLaunch=0;},addToAutoLoad:function(A,C){var B=this.modules.get(A);
if(B.autoLaunch){B.autoLaunch+=(","+C);}else{B.autoLaunch=C;}}});