var createManifestLoader = require('poem-manifests');
var EventEmitter = require('events').EventEmitter;

var _emitter = new EventEmitter();
var _loader = null;

var init = function( createPoemGraph, manifests ) {
		
	_loader = createManifestLoader( manifests, {
		emitter : _emitter,
		getGraph : function( manifest, slug ) {	return createPoemGraph( manifest, _emitter ); },
		globalManifest : {}
	});
	
	_emitter.on('load', function( e ) {
		window.poem = e.graph;
	});
	
};

var load = function( slug ) {
	return _loader.load( slug );
};

module.exports = {
	init : init,
	load : load,
	emitter : _emitter
};
