var ObjectManager = {
	collection: [],
	head: document.getElementsByTagName("head")[0],
	load: function() {
		var object;
		
		function loadObject(el) {
			var matches = el.match(/((?:.+)\.(css|js))(?:(\:persist)?)/);
			var source = matches[1];
			var extension = matches[2];
			var persist = typeof matches[3] != "undefined";
			switch (extension) {
				case "js":
					object = document.createElement("script");
					object.type = "text/javascript";
					object.src = source;
					break;
				case "css":
					object = document.createElement("link");
					object.type = "text/css";
					object.href = source;
					object.rel = "stylesheet";
					break;
			}
			if (!persist) {
				ObjectManager.unload(source);
				ObjectManager.collection.push(object);
			}
			ObjectManager.head.insertBefore(object, ObjectManager.script);
		}
		
		Array.forEach(arguments, loadObject);
	},
	unload: function(source) {
		var i = 0, object;
		while (i < ObjectManager.collection.length) {
			object = ObjectManager.collection[i];
			if (source && object
					.getAttribute(object.type == "text/css" ? "href" : "src") == source || !source) {
				ObjectManager.head.removeChild(object);
				ObjectManager.collection.splice(i, 1);
			}
			i++;
		}
	},
	script: document.getElementsByTagName("script")[0]
};
