﻿/** @namespace brookings.mm */
var brookings = brookings || {};
brookings.mm = brookings.mm || {};

(function() {

	/**
	* @class EmbedPlayer
	*/
	brookings.mm.EmbedPlayer = function() {

		// copy for closure
		var self = this;

		// private members
		var _brightcoveExperience;
		var _experienceModule;
		var _videoPlayerModule;
		var _socialModule;

		/** 
		* Wires up handlers for video player event
		*/
		self.wireEvents = function() {
			_experienceModule.addEventListener(BCExperienceEvent.TEMPLATE_READY, self.updateShareLink);
			_videoPlayerModule.addEventListener(BCVideoEvent.VIDEO_CHANGE, self.updateShareLink);
		};

		/**
		* Updates the "share" link provided by the player to be the URL of the current page
		*/
		self.updateShareLink = function() {
			_socialModule.setLink(window.location.href);
		};

		// public members
		var pub = {

			/**
			* Performs any necessary initialization
			*/
			initialize: function(brightcoveExperience) {

				_brightcoveExperience = brightcoveExperience;
				_experienceModule = _brightcoveExperience.getModule(APIModules.EXPERIENCE);
				_videoPlayerModule = _brightcoveExperience.getModule(APIModules.VIDEO_PLAYER);
				_socialModule = _brightcoveExperience.getModule(APIModules.SOCIAL);

				self.wireEvents();
			}
		};

		return pub;
	};

})();
