/**
 * External Link Script
 * author: James Revillini (written outside of Tunxis)
 * date: 10/30/2008
 * license: lgpl
 * purpose: provide a convenient wrapper for YUI Loader so that scripts can be dynamically attached to the page. 
 * 
 * usage: from any page, at the bottom of the page before the body tag, put
 *

<script type="text/javascript">

YAHOO.dankloader.add('modulename1', 'modulename2', 'modulename3');	//each arg is the name of a yui module http://developer.yahoo.com/yui/yuiloader/#modulenames
YAHOO.dankloader.add(functionref1, functionref1);	//each arg is a valid function reference that should fire once the dependencies are loaded

</script>



 */

if (YAHOO) {
	(function () {
			   
			   


//let the dankness begin
YAHOO.namespace('dankloader');
YAHOO.dankloader.loaders = [];
YAHOO.dankloader.require = [];
YAHOO.dankloader.css = [];

YAHOO.dankloader.init = function () {
	console.info('dankloader: loading dependencies (' + YAHOO.dankloader.require.join(', ') + ')');
	(new YAHOO.util.YUILoader({
		require: YAHOO.dankloader.require,
		loadOptional: true,
		combine: true,
		onSuccess: YAHOO.dankloader.load_o_matic,
		onFailure: function () {console.error('failed to load required yui scripts')}
	})).insert();
};

YAHOO.dankloader.load_o_matic = function () {
	while(l = each(YAHOO.dankloader.loaders)) {
		setTimeout(l, 100);
	}
};

YAHOO.dankloader.add = function () {
	args = arguments;
	
	while(arg = each(args)) {
		
		if (typeof(arg) == 'function') {
			YAHOO.dankloader.loaders.push(arg);
		} else {
			YAHOO.dankloader.require.push(arg);
		}
	}
}



	})();
} else {
	//no diggity?!
	console.error('Dankloader requires YUI Loader.  Add to head tag: <script type="text/javascript" src="http://yui.yahooapis.com/x.x.x/build/yuiloader/yuiloader-min.js" ></script>');	
}
