/**
 * Plank Front End Loader
 * plank_fe_loader.js
 * 
 * Loader to handle front end js req's
 *
 * Minimum file needed for the other componenets. A wrapper for the YUI loader. 
 * All other modules feed off this to know when the scripts have been loaded. 
 * Currently should come after the yuiloader-dom-event file in your html.
 *
 * Sets up the Plank BB namespace - Plank.bb is just the blackboard, 
 * where we store certain info other modules may need.
 * Example - To know whether to load scripts locally or from YAHOO servers, you set 
 * YAHOO.Plank.bb.loaderBase to either the local, relative path, or to false (or remove it entirely)
 *
 * Can set up logger console - pipes to console.log if its available. YUI Logger panel hidden by default.
 *
 * Meant for dev use (easy for integrators to just include).
 * 
 * @package Plank JS
 * @author  Mitchell Amihod
 */

(function () {

  YAHOO.namespace('Plank', 
                  'Plank.bb', //Black Board
                  'Plank.util'
                  );

  var Dom = YAHOO.util.Dom,
      Lang = YAHOO.lang,
      Event = YAHOO.util.Event;  
  
  // We set up a base loader config object, which all the other modules can use for their loaderConfigs
  // It's up here at the top mainly for convenience
  YAHOO.Plank.bb.loaderConfig = {
    
    base : '_js/yui/build/',   //Leave false to load from YAHOO servers.
    
    //Defaults used, override this in each individual module config
    require: [  
               // 'logger',
				'json',
                'plank_util',
                'plank_validator',
                'plank_app_fe' ], 
    
    loadOptional: true,
    onSuccess: function() {YAHOO.log(arguments);},
    onFailure: function() {YAHOO.log(arguments); alert(' There was a problem, please reload. ');}
    //,onProgress: function() { console.log(arguments);return true; }
  };

  //Called to initialize debug.
  var debugInit = function() {

		YAHOO.widget.Logger.enableBrowserConsole();    
    //Set up debug/console log. Using the YUI logger, since its easy to switch over when on ie
		var myLogReader = new YAHOO.widget.LogReader();

    if ("console" in window) {
		  myLogReader.hide();
	  }
	  myLogReader.collapse();
  };


  //Event we can listen for in all the other scripts, since this script always required.
  // YAHOO.Plank.readyEvent = new YAHOO.util.CustomEvent("ready", this);

  var loaderConfig =  {
    //And here we have the config for this specific loader instance.
    scope : YAHOO.Plank,
    
    onSuccess: function() {

      //debugInit();

      this.appfe.init();

    }
  };

  Lang.augmentObject(loaderConfig, YAHOO.Plank.bb.loaderConfig);
  YAHOO.Plank.Loader = new YAHOO.util.YUILoader(loaderConfig);

  //Add any modules the loader can load
  YAHOO.Plank.Loader.addModule({
    name: "plank_util", //module name; must be unique
    type: "js", //can be "js" or "css"
    fullpath: "_js/plank_util.js", //can use a path instead, extending base path
    requires: ['yahoo', 'event', 'container'] //if this module had dependencies, we could define here
  });

  YAHOO.Plank.Loader.addModule({
    name: "plank_validator", 
    type: "js", 
    fullpath: "_js/plank_validator.js", 
    requires: ['yahoo', 'event', 'dom']
  });


  YAHOO.Plank.Loader.addModule({
    name: "plank_app_fe", 
    type: "js",
    fullpath: "_js/app_fe.js", 
    requires: ['dom','event'] 
  });


  Event.onDOMReady(function() {
    YAHOO.Plank.Loader.insert();
  });

}());
