var FlowerDebug=new Class({debug:0,flowerCore:false,setFlowerCore:function(b){this.flowerCore=b;this.debug=this.flowerCore.debug;if(typeof(a)!="object"){var a={}}if(!a.log){a.log=function(){}}if(!a.warn){a.warn=a.log}if(!a.error){a.error=a.warn}},debugMsg:function(b,d){if(this.debug){var a="",c;b=b+0;if(this.flowerCore&&this.name){a="["+this.name+"] "}c=["Flower Error: ","Flower Warning: ","Flower Notice: "];switch(b){case 0:console.error(c[b]+a+d);break;case 1:console.warn(c[b]+a+d);break;default:console.log(c[b]+a+d)}}},debugLoadMsg:function(){if(this.debug){var a="Flower Module Loaded: "+this.name+" (v"+this.version+")",b=this.listAllOptions();if(b){a+="\n\tOptions:\n\t"+b}console.log(a.replace(/, /g,"\n\t"))}},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 FlowerCore=new Class({Implements:[Options,Events,FlowerDebug],options:{debug:0,autoBoot:0,timeout:500},initialize:function(a){this.setOptions(a);this.name="Flower";this.version=1;this.modules=$H();this.commonCache=$H();this.injectedFiles=[];this.debug=0;
this.timeout=this.options.timeout;this.documenthead=$$("head")[0];var b=this.documenthead.getElement("script[src*=flower_core.js]");if(b){var c=b.getProperty("src");this.libpath=c.substring(0,c.lastIndexOf("/")+1)}$$("*.ifjs_visibilityhidden","div.flower_soundplayer").each(function(e){e.setStyle("visibility","hidden")});$$("*.ifjs_visibilityvisible").each(function(e){e.setStyle("visibility","visible")});$$("*.ifjs_displaynone").each(function(e){e.setStyle("display","none")});$$("*.ifjs_displayblock").each(function(e){e.setStyle("display","block")});$$("*.ifjs_displayinline").each(function(e){e.setStyle("display","inline")});this.defineLibrary();if(this.options.autoBoot){this.bootstrap()}if(this.options.debug&&typeof(console)!="undefined"){this.debug=1;var d=this.listAllOptions();if(this.libpath){console.log("Flower (v"+this.version+") loaded.\n\tPath: '"+this.libpath+"'\n\tMooTools version: "+MooTools.version+"\n\tOptions: "+d)}else{console.log("Flower loaded with errors. Version: "+this.version+' Path unknown. Please make sure the flower core JS file is named "flower_core.js"\n\tOptions: '+d)}}},injectScript:function(a,b){var c;if(b){a=this.libpath+a}if(this.injectedFiles.indexOf(a)==-1){c=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){document.id(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(d,c,a){d.implement(new FlowerDebug());
var b=this.getModuleOptions(c),e;if(b){e=new d(b)}else{e=new d()}e.setFlowerCore(this);if(a==true){return e}else{this.moduleCallback(e)}},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("\n\t"))}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/flower_anchor.js","linkexternal",0,"a.external",1,1);this.storeModule("enhancements/flower_anchor.js","linkpopup",0,"a.popup",1,1);this.storeModule("enhancements/flower_anchor.js","linkinside",0,"a.flower_linkinside",1,1);this.storeModule("enhancements/flower_anchor.js","drawer",0,"a.flower_drawertoggle",1,1);
this.storeModule("utility/flower_utility.js","utility",0,0,0,1);this.storeModule("media/flower_overlay.js","overlay",0,0,0,1);this.storeModule("media/flower_imagebox.js","imagebox","utility,overlay","a.flower_imagebox,div.flower_imagebox",1,1);this.storeModule("media/flower_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],a[href^=http://www.vevo.com/watch]",1,1);this.storeModule("soundplayer/flower_soundplayer.js","soundplayer",0,"*.flower_soundplayer,div.flower_soundplayer_pageplayer",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}}});
