/**
 * All intellectual property rights in this Software throughout the world belong to UK Radioplayer, 
 * rights in the Software are licensed (not sold) to subscriber stations, and subscriber stations 
 * have no rights in, or to, the Software other than the right to use it in accordance with the 
 * Terms and Conditions at www.radioplayer.co.uk/terms. You shall not produce any derivate works 
 * based on whole or part of the Software, including the source code, for any other purpose other 
 * than for usage associated with connecting to the UK Radioplayer Service in accordance with these 
 * Terms and Conditions, and you shall not convey nor sublicense the Software, including the source 
 * code, for any other purpose or to any third party, without the prior written consent of UK Radioplayer.
 *
 * @name FlashEmp
 * @description Flash emp creation functionality
 * 
 * 
 * @author Sergejs Vaskevics <sergejs.vaskevics@ubcmedia.com>
 */

radioplayer.services.FlashEmp = function() {
};

radioplayer.services.FlashEmp.prototype = {

	createFlashEmp : function(obj) {
		// integrating flash emp
		clearTimeout(radioplayer.emp.automaticLaunchTimeout);
		if (!radioplayer.emp.isLaunched) {
			var volume = this.getVolumeValue(obj);
			var flashvars = {
				theme : radioplayer.emp.flashvars.theme,
				volume : volume,
				mode : radioplayer.emp.flashvars.mode,
				content : radioplayer.emp.flashvars.content,
				bufferTime : radioplayer.emp.flashvars.bufferTime
			};
			// code from flash emp suppliers starts
			if (flashvars.mode == 'netstream') {
				flashvars.server = radioplayer.emp.flashvars.server;
				flashvars.endpoint = radioplayer.emp.flashvars.endpoint;
			} else {
				flashvars.url = radioplayer.emp.flashvars.url;
			}
			// code from flash emp suppliers ends
			var radioPlayerFlash = new glow.embed.Flash(
					"flash/RadioPlayerUI.swf", "#playerFlashContainer", "9", {
						width : "362px",
						height : "42px",
						params : {
							wmode : "transparent",
							flashvars : flashvars
						}
					});
			radioPlayerFlash.embed();
			radioplayer.emp.isLaunched = true;
			var getEmpContainerArray = glow.dom.get('#playerFlashContainer');
			var empContainer = getEmpContainerArray[0];
			empContainer.className = "real-emp-container";
		}
	},
	getVolumeValue : function(cookieVolumeData) {
		var volume;

		if ((!cookieVolumeData) || (cookieVolumeData === "null")
				|| (cookieVolumeData === null)) {
			volume = 100;
			radioplayer.controllers.CrossDomain.prototype.saveVolume(volume);
		} else {
			volume = cookieVolumeData;
		}
		return volume;
	}
};

