/* 
 * Encapsulation Pattern: Conjuring YUI from thin air (by Chris Heilmann) 
 * http://www.wait-till-i.com/2008/08/02/conjuring-yui-from-thin-air/
 */
YAHOO_config = function(){
  /* injecting the YUI3 baseline in the current page */	
  var s = document.createElement('script');
  s.setAttribute('type','text/javascript');
  s.setAttribute('src','http://yui.yahooapis.com/2.6.0/build/yuiloader/yuiloader-min.js');
  document.getElementsByTagName('head')[0].appendChild(s);
  return{
    injecting: true, // Set to true if the library will be dynamically loaded after window.onload. Defaults to false
	listener:function(o){
      // waiting for the loader component
	  if(o.name === 'get'){
        window.setTimeout(YAHOO_config.ready,1);
      }
    },
    ready:function(){
//debugging
document.body.innerHTML += '<p>Bootstrap: starting the loading process...</p>';
	  var loader = new YAHOO.util.YUILoader();
	  // defining the custom modules
	  loader.addModule({ 
		  name:'myapp', 
		  type: 'js',
		  fullpath:'app.js', 
		  requires:['get'] 
	  });
      loader.addModule({ 
		  name:'simple_module', 
		  type: 'js',
		  fullpath:'simple-module.js', 
		  requires:['myapp', 'connection', 'json'] 
	  });
	  loader.require(['simple_module', 'myapp']);
      loader.loadOptional = true;
	  loader.timeout = 10000;
	  loader.combine = true;
//debugging
document.body.innerHTML += '<p>Bootstrap: Using YUILoader to load the required modules...</p>';
	  loader.insert({
        onSuccess:function(){
          /* loading the required components onDemand (using relative path, but you can use fullpath ) */
          var _myComponents = [
              "simple-component.js", 
              "another-component.js"
          ];
//debugging
document.body.innerHTML += '<p>Bootstrap: Using Get Utility to load the rest of the components...</p>';
          YAHOO.util.Get.script(_myComponents, { 
              onSuccess: function() {
              	// We are ready to roll.
//debugging
document.body.innerHTML += '<p>Bootstrap: We are ready to roll on top of YUI 2.x</p>'; 
		  }});
        }
      });
    }
  };
}();