var FF = (function() {
	var FF = {};
	var _included = {};
	
	var HEAD;
	
	FF.Core = {};
	FF.Dom = {};
	
	FF.Dom.instanceOf = function(x, y) {
		return typeof(x) === 'object' && x !== null && x instanceof y;
	};
	FF.Dom.isArray = function(x) {
		return FF.Dom.instanceOf(x, Array);
	};
	
	FF.$ = function(s) {
		return document.getElementById(s);
	};
	
	FF.Core.include = function() {
		var folder='', files=0, done=0, perfs=[];
		if (!HEAD) HEAD = document.getElementsByTagName('head')[0];
		
		function include(file) {
			if (!((folder + '/' + file) in _included)) {
				var el = document.createElement('script');
				el.type = 'application/javascript';
				el.src = folder + '/' + file;
				HEAD.appendChild(el);
				
				files--;
				el.onload = function() {
					done++;
					
					if (files == done) {
						for (var i=0; i<perfs.length; i++) {
							perfs[i].call(this);
						}
					}
				};
			}
		}
		
		for (var i=0; i<arguments.length; i++) {
			if (typeof(arguments[i]) == 'string') {
				if (arguments[i].match(/\.js$/)) {
					include(arguments[i]);
				} else {
					folder = arguments[i];
				}
			} else if (FF.Dom.isArray(arguments[i])) {
				for (var j=0; j<arguments[i].length; j++) {
					include(arguments[i][j]);
				}
			} else if (typeof(arguments[i]) == 'function') {
				perfs.push(arguments[i]);
			} else {
				throw new TypeError("Unsupported argument '" + arguments[i] + "'");
			}
		}
		
		files = -files;
	};
	
	return FF;
})();
