/*
 * Copyright (C) 1995-2014 by 4system Polska Sp. z o.o.
 * All Rights Reserved.
 */

function getMe(s)
{
	return me[s];
};

function setMe()
{
	var as = new Array();
	var av = new Array();
	var i = 0;

	while(i+1<arguments.length) {
		as[as.length]=arguments[i++];
		av[av.length]=arguments[i++];
	};

	var c=Math.min(as.length, av.length);
	for(var i=0; i<c; i++) {
		me[as[i]]=decodeURI(av[i]);
	};
};

componentSimpleFlash = function(name)
{
	//inherited
	this.componentElement = componentElement;
	this.componentElement(name);
	this.resourcesStatus = "online";
	this.resourcesURL = "";

	this.isOldFlash = false; //pg2-could be local variable, but if preloader is enabled, this.wmode could be initialized during creation

	this.timerLoader = null; //pg2-audioOnOff_new
	this.timerCounterStartValue = 6;
	this.timerCounter = this.timerCounterStartValue;
};

componentSimpleFlash.prototype = new componentElement;
componentSimpleFlash.prototype.type = "componentSimpleFlash";

componentSimpleFlash.prototype.onBaseCreate = function(obj)
{
	this.disableOnlineOfflineMix = true; //mk: flash CAN'T be load from other domain then course
	this.resourcesURL = resourcesURL;
	this.captureMouseEvents();
	if (this.execution) {
		this.resourcesStatus = "online";
		this.resourcesURL = resourcesURL;
		if (PageInterface.GetValue("state") != psDesigning && lms && lms.name != "lmsOffline") {
			this.resourcesStatus = lms.resourcesStatus();
			if (this.disableOnlineOfflineMix) this.resourcesURL = resourcesURL;
			else this.resourcesURL = lms.resourcesURL();
		};
	};
    this.resourcesURL = unescape(this.resourcesURL);
};

componentSimpleFlash.prototype.onCreate = function(obj)
{
};

componentSimpleFlash.prototype.onPaint = function(obj)
{
	if (!this.visible) return; //pg2-
	
	if (PageInterface.GetValue("state") == psDesigning) { //pg2-otherwise in case of new version of FlashPlayer (v11) there is a blank rect
		t = '<img src="' + this.resourcesURL + this.playerBackground + '" width="' + this.w + '" height="' + this.h + '"/>';
		this.setHTML(t);
		this.rendered = true;
		return;
	};
	
	var t = "";
	var fv = "";
	if (PageInterface.GetValue("state") != psDesigning && lms) {
		fv = "mediaStatus=" + lms.mediaStatus() + "&" + this.formatVar(this.flashVars);
	};

	while (fv.indexOf('+') > -1) { //pg2- '+' in .setHTML() is converted in several ways, and finally simple '+' is passed as parameter and is missing in output flash
		fv = fv.replace('+', '_2B_'); //it will be converted to proper value '%2B' in 'element.js'
	};

	var backgroundColor = (this.useDefinedBG?this.bgColor:"#FFFFFF"); //pg2

	//pg2-scenes of old courses (WBTE v7.0.1.93 etc) exported from new WBTExpress- flash/simpleFlash has few additional properties
	if (typeof(this.wmode) == "undefined") {
		this.wmode = "transparent";
		this.isOldFlash = true;
	};

	if (is.ie) {
		t += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="'+ this.w +'" height="'+ this.h +'" id="'+ this.id +'flashPlayer" align="middle">';
		t += '  <param name="movie" value="'+ this.resourcesURL + this.src +'">';
		t += '  <param name="allowScriptAccess" value="sameDomain" />';
		t += '  <param name="BGColor" value="' + backgroundColor + '">';
		t += '  <param name="quality" value="' + this.quality + '">';
		t += '  <param name="loop" value="' + this.loop + '">';
		t += '  <param name="WMode" value="' + this.wmode + '">';
		t += '  <param name="scale" value="' + this.scale + '">';
		t += '  <param name="salign" value="' + this.salign + '">';
		t += '  <param name="FlashVars" value="' + fv + '">'; //&veriable_1=value_1&veriable_2=value_2

		t+= '   <param name="allowFullScreen" value="true">';

		t += '</object>';
	} else {
		t += '<embed';
		t += '  wmode="' + this.wmode + '" ';
		t += '  src="'+ this.resourcesURL + this.src +'" ';
		t += '  quality="' + this.quality + '" ';
		t += '  bgcolor="' + backgroundColor + '" ';
		t += '  id="'+ this.id +'flashPlayer" ';
		t += '  type="application/x-shockwave-flash" ';
		t += '  pluginspage="https://www.macromedia.com/go/getflashplayer" ';
		t += '  width="'+ this.w +'" ';
		t += '  height="'+ this.h +'" ';
		t += '  FlashVars="' + fv + '" ';

		if (!this.isOldFlash) { //pg2
			t += 'scale="' + this.scale + '" '; //pg2- missing parameters
			t += 'loop="' + this.loop + '" '; 
			t += 'salign="' + this.salign + '" ';
		}
		t += '  allowFullScreen="true" ';
		t += 'allowScriptAccess="sameDomain"> ';
		t += '</embed>';
	};
	this.setHTML(t);

	this.startTimer(); //pg2-audioOnOff_new
};

componentSimpleFlash.prototype.componentSimpleFlashBaseSetSizeScaledElement = componentSimpleFlash.prototype.setSizeScaledElement;
componentSimpleFlash.prototype.setSizeScaledElement = function(x, y, w, h)
{
	var flashPlayer = document.getElementById(this.id + "flashPlayer");
	if (flashPlayer){
		flashPlayer.width = w;
		flashPlayer.height = h;
	};
	this.componentSimpleFlashBaseSetSizeScaledElement(x, y, w, h);
};

componentSimpleFlash.prototype.onHide = function() 
{
	//window.clearTimeout(this.timerLoader); //pg2-audioOnOff_new
	//this.timerLoader = null;

	this.setHTML(" ");
};

componentSimpleFlash.prototype.actionFlashStop = function(obj) //pg2-invoke media stop from page.js
{
	//window.clearTimeout(this.timerLoader); //pg2-audioOnOff_new
	//this.timerLoader = null;

	this.setHTML(" ");
};

componentSimpleFlash.prototype.onFree = function() { //pg2-audioOnOff_new
	this.stopTimer();
};

componentSimpleFlash.prototype.stopTimer = function() //pg2-audioOnOff_new
{
	if (this.timerLoader) {
		if (this.timerLoader != null) {
			window.clearTimeout(this.timerLoader);
			this.timerLoader = null;
		};
	};
};

componentSimpleFlash.prototype.startTimer = function() //pg2-audioOnOff_new
{
	this.stopTimer();
	try {
		this.timerLoader = window.setTimeout('pc.' + this.id + '.onPaintDelayed()', 500);
	} catch(e) {
		this.timerLoader = null;
		this.timerCounter = this.timerCounterStartValue;
	};
};

componentSimpleFlash.prototype.onPaintDelayed = function() //pg2-audioOnOff_new
{
	try {
		window.clearTimeout(this.timerLoader);
		this.timerLoader = null;

		this.timerCounterStartValue--;

		var obj = document.getElementById(this.id + 'flashPlayer');
		if (obj) {
			if (obj.flaFunctionID) {
				if (lms && lms.mediaStatus) {
					var mediaStatus = lms.mediaStatus();
					if (mediaStatus == "online") obj.flaFunctionID('turnOnSound'); else obj.flaFunctionID('turnOffSound');
				};
			};
		};
		if (this.timerCounterStartValue > 0) this.startTimer(); else this.timerCounter = this.timerCounterStartValue;
	} catch(e) {};
};

componentSimpleFlash.prototype.onShow = function() //pg2-audioOnOff_new
{
	this.timerCounter += 6;
	this.startTimer();
};
