/**
##############################################################################################
#
#		Title: BBC RaW - Flash embed with support for AcP (Accessibility control Panel)
#
#		Description: 
#
##############################################################################################
#   $Source: $
#   $Author: Michael Koderisch $
#   $Revision: $
#   $Date: $ 
##############################################################################################
*/

/**
 * Function: thisMovie
 *
 * Description: returns the handle for JS -> Flash communcation depending on browser used
 */
function thisMovie() {
	var movieName = "flash-object";
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}


/**
 * Top-level functions for use by Flash movie
 */

/**
 * Function: getACPSettings
 *
 * Description: returns the user prefs settings as an object formatted for Flash
 */
function getACPSettings() {
	var currentPrefs = PrefsStore.getPrefs();
	var PrefsForFlash = {};
	if (currentPrefs){
		PrefsForFlash = FlashPrefs.Themes[currentPrefs.theme];
		PrefsForFlash.theme = currentPrefs.theme;
		PrefsForFlash.fontsize = FlashPrefs.FontSizes[currentPrefs.fontSize];
		PrefsForFlash.volume = currentPrefs.volume?currentPrefs.volume:FlashPrefs.volume_default;
		PrefsForFlash.subtitles = currentPrefs.subtitles?currentPrefs.subtitles:FlashPrefs.subtitles_default;
	}
	return PrefsForFlash;
}

/**
 * Function: onACPSettingsChange
 *
 * Description: sends user prefs settings to Flash
 */
function onACPSettingsChange() {
	if(thisMovie() && typeof thisMovie().onACPSettingsChange == 'function') { // check the function is actually available
		var PrefsForFlash = getACPSettings();
		thisMovie().onACPSettingsChange(PrefsForFlash);
	}
}
// add onACPSettingsChange as callback function to be invoked when user prefs settings are changed
PrefsStore.addPrefsChangeListener(onACPSettingsChange);

/**
 * Function: onFlashSettingsChange
 *
 * Description: called by Flash to send user prefs settings from Flash to AcP
 *
 * @param {Object} Data - list of user prefs set in Flash
 */
function onFlashSettingsChange(Data) {
	PrefsStore.mergePrefs(Data);
}

var FlashEmbed = {
	version: 9,
	width: 946,
	height: 428,
	swf_filename: '',
	flashvars: '',
	FlashMov: false,
	setParams: function(swf_filename,flashvars) {
		this.swf_filename = swf_filename;
		this.flashvars = flashvars;
	},
	embedFlash: function() {
		if (FlashSwitcher.basicVersion == 0) { // only embed flash if basic version not selected
			// START: temporary if/else block to support old style pages. Can be removed once all templates have been republished
			if (typeof(mov) != 'undefined') {
				mov.insert($('flash-content'));
				if ($('noflash-message')) {
					bbcjs.dom.addClassName(document.documentElement,'noflash'); // display HTML alternative if required Flash version is not present
				}
			} else {
			// END: temporary if/else block to support old style pages. Can be removed once all templates have been republished
				if (bbcjs.plugins.flash) {
					if (!this.FlashMov) this.FlashMov = new bbcjs.plugins.FlashMovie(this.swf_filename, this.version, this.width, this.height);
					this.FlashMov.flashvars = this.flashvars;
					//MK: removed to fix Jaws issue  this.FlashMov.wmode = 'transparent';
					this.FlashMov.id = 'flash-object';
					this.FlashMov.insert($('flash-content'));
					if (this.FlashMov.detected < this.FlashMov.version) {
						bbcjs.dom.addClassName(document.documentElement,'noflash'); // display HTML alternative if required Flash version is not present
					}
				}
			}
			// end
		}
	}
}





/**
  * END
  */