/*
	RequireUtils
	Requires Mootool 1.2 Core
	Requires lib.ok.utils.StringUtils
	Ok!nteractif
*/

var RequireUtils = 
{
	required		: [],
	
	scriptsPath		: 'scripts/js/',
	
	importRequired	: function()
	{
		this.required.each(function(lib){
			this.require(lib)
		}.bind(this));
	},
	
	require			: function(lib, path) 
	{
		if(!path) path = this.scriptsPath;
		if(typeof(lib) == 'object'){
			lib.each(function(item){
				this.require(item, path)
			}.bind(this));
			return;
		}
	
		lib = lib.replace(/\./g,'/') + '.js';
		
		document.write('<script type="text/javascript" src="' + path + lib + '"><\/script>');
	},
	
	checkForAttribute : function(libName, attribute)
	{
		var js = this.getLibTag(libName);
		if(!js) return false;
		
		return this.getAttribute(libName, attribute) ? true : false;
	},
	
	getAttribute : function(libName, attribute)
	{
		var js = this.getLibTag(libName);
		if(!js) return false;
		
		if(js.src.match(/\?/)){
			if(js.src.match(attribute+'='))
				return StringUtils.getQueryVariable(attribute, js.src);
			else if(js.src.match(attribute)) return attribute;
		}
		return false;
	},
	
	getLibTag		: function(libName)
	{
		
		var js;
		var scriptLibs = $$('script');
		for(var i = 0; i < scriptLibs.length; i++){
			js = scriptLibs[i];
			if(js.src.match(libName)){
				return js;
			}
		}
		return false;
	}
};

RequireUtils.require('lib.ok.utils.StringUtils');