Syn.VideoLibraryManager = {
	/**
	 * Tracks loaded 3rd party libraries
	 * The key of this object will be the name of the library.  The value will be either a 1 or 2.
	 * 1 means that the library is in process of being loaded
	 * 2 means that the library has been loaded
	 * @var object
	 */
	loaded_libraries: {},

	/**
	 * Ensures that the third party library is requested only once.
	 * The script.onload and script.onreadystatechange was modified from ejeliot.com (http://www.ejeliot.com/blog/109)
	 * @param {String} lib
	 * @param {String} url
	 * @param {Function} callback
	 */
	loadLibrary: function(lib, url, callback)
	{
		if (!this.loaded_libraries[lib])
		{
			var self = this;
			var fn = function()
			{
				self.loadLibraryComplete(lib, callback);
			}

			var script = document.createElement("script");
			script.type = "text/javascript";
			script.src = url;
			script.onload = fn; // Modern browsers
			script.onreadystatechange = function() // IE 6/7
			{
				if (this.readyState == 'complete' || this.readyState == 'loaded')
				{
					fn();
				}
			}

			this.loaded_libraries[lib] = 1;
			document.getElementById('vich_3rdparty_libraries').appendChild(script);
		}
		else if (this.loaded_libraries[lib] == 2)
		{
			this.loadLibraryComplete(lib, callback);
		}
	},

	/**
	 * Performs the callback once the external library has been loaded
	 * @param {String} lib
	 * @param {Function} callback
	 */
	loadLibraryComplete: function(lib, callback)
	{
		this.loaded_libraries[lib] = 2;
		callback();
	}
};
