MCFC.video = function ($) {
	
	var default_flashvars = {
		debug: "false",
		autoPlay: "true",
		onComplete: "closePlayer", // closePlayer, showRelated
		onCloseCallback: "MCFC.video.on_close",
		//onExitFullscreenCallback : "",//"MCFC.video.on_exit_fullscreen",
		//ratingURL: "rating.txt", // script to post user rating to
		//relatedvideosURL: "relatedvideos.xml", // path to related videos service.
		playerID: "27761105001",
		mediaControlsURL:"/flash/videoplayer/mediaControls.swf",
		playerSkinURL:"/flash/videoplayer/playerSkin.swf",
		showClose: "true", // show the top right close button.
		publisherID: "10228001001" // publisher account at bc
	};
	
	var settings = {};
	
	return {
		
		play : function (element_id, spec) {
			// stop the timer if we're on the homepage.
			if(MCFC.carousel) { MCFC.carousel.nav_manager.stop_timer(); }
			var fv = $.extend({}, default_flashvars, spec.flashvars);
			// save down all settings.
			settings[spec.id] = {};
			settings[spec.id].spec = spec;
			settings[spec.id].element_id = element_id;
			settings[spec.id].html = $('#'+element_id).clone().get(0);
			fv.onCloseCallback += ',' + spec.id; // videoplayer callback will split on commas and supply these as arguments on callback.
			fv.onExitFullscreenCallback += ',' + spec.id;
			fv.width = spec.width;
			fv.height = spec.height;
			MCFC.swf.embed('/flash/videoplayer/brightcove_container.swf', element_id, spec.width, spec.height, fv, {}, {});
		},
		
		on_close : function (id) {
			if(settings[id].spec.revert_on_close){
				this.revert_to_html(id);
			}
		},
		
		on_exit_fullscreen : function (id) {
			console.log('on_exit_fullscreen');
			$('#'+settings[id].element_id).focus();
		},
		
		revert_to_html : function (id) {
			$('#'+settings[id].element_id).replaceWith(settings[id].html);
			console.log("revert_to_html");
			MCFC.fontsizes($('#'+settings[id].element_id).parent());
		}
};

} (jQuery);
