/*
 * Copyright (C) 1995-2011 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 = "";
};

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)
{
	var t = "";
	var fv = "";
	if (PageInterface.GetValue("state") != psDesigning) {
		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:""); //pg2
	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="http://www.macromedia.com/go/getflashplayer" ';
		t += '  width="'+ this.w +'" ';
		t += '  height="'+ this.h +'" ';
		t += '  FlashVars="' + fv + '" ';
		
		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);
};

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() 
{
	this.setHTML(" ");
};
