///////////////////// audioControl /////////////////////

function audioControl(){}

var _this = audioControl.prototype = new Object();

_this.constructor			= audioControl;
_this.player;
_this.paused;
_this.position;
_this.hDelay;
_this.aTracks;
_this.nCurTrack;
_this.cTrackName;
_this.nInterval;
_this.lEnable;
_this.cMediaFolder;
_this.cPlayerId;
_this.lMute;

_this.requestAlert;
_this.swfAudioTrack;
_this.fnPlayAudio;
_this.fnEndAudio;
_this.fnPauseResumeAudio;
_this.fnMuteAudio;
_this.swfAudioPosition;
_this.swfFadeAudioTime;


_this.init = function ( aVars ) {
		
// 	this.swfAudioControl.play(this.cMediaFolder + this.cInitialTrack + ".mp3", 6); // delay is in seconds

	this.requestAlert				= "reqAlt";
	this.swfAudioTrack			= "varAT";
	this.fnPlayAudio				= "fnPA";
	this.fnEndAudio				= "fnEA";
	this.fnPauseResumeAudio		= "fnPRA";
	this.fnMuteAudio				= "fnMA";
	this.swfAudioPosition		= "varAP";
	this.swfFadeAudioTime		= "varFAT";	
	
	this.paused				= false;
	this.position			= 0;
	this.hDelay		 		= 0;
	this.cTrackName		= "";
	this.nInterval			= 0;
	this.lMute				= false;
	
	this.cPlayerId			= aVars[0];
	this.cMediaFolder		= aVars[1];
	this.aTracks			= aVars[2];
	this.nCurTrack			= aVars[3];
	
	var ie = navigator.appName.indexOf("Microsoft") != -1;
//	this.player = (ie) ? window[cPlayerId] : document[cPlayerId];
	if (ie)
	{
		this.player = window[this.cPlayerId];
	
		this.lEnable = true;	
		//this.play(this.nCurTrack, 6);
	}
	else
	{
		this.player = document[this.cPlayerId]
	
		this.lEnable = true;	
		//this.play(this.nCurTrack, 10);
	}


	// this.player = document.getElementById(cPlayerId);	
		
}

_this.rePlay = function (nInterval) {
	this.play(this.nCurTrack, nInterval);
}

_this.play = function (nIndex, nInterval) {	
	var self = this;
	clearTimeout(this.hDelay);
	if (this.lEnable) {
		this.nCurTrack = nIndex;
		this.cTrackName = this.aTracks[nIndex];
		this.nInterval = 1000 * nInterval;
		if (this.nInterval > 0) {
			// hAudioDelay = setTimeout(function() {delayedAudio(cTrackName)}, nInterval); 
			this.hDelay = setTimeout( function () {self.delayedPlay()}, this.nInterval); 
		}
		else {	
			this.assign(this.swfAudioTrack, 	this.cMediaFolder + this.cTrackName + ".mp3");
			this.assign(this.fnPlayAudio, 	true);
			this.assign(this.requestAlert, 	true);
		}
	}
}

_this.delayedPlay = function () {
	clearTimeout(this.hDelay);
	this.assign(this.swfAudioTrack, 	this.cMediaFolder + this.cTrackName + ".mp3");
	this.assign(this.fnPlayAudio, 	true);
	this.assign(this.requestAlert, 	true);
}

_this.stop = function () {
	this.assign(this.fnEndAudio, 					true);
	this.assign(this.requestAlert, 				true);
}

_this.pauseResume	= function () {
	if (this.paused) {
		this.setPosition();
		this.assign(this.fnPauseResumeAudio, 	true);
		this.assign(this.requestAlert, 			true);
		this.paused = false;
	}
	else {
		this.assign(this.fnPauseResumeAudio, 	true);
		this.assign(this.requestAlert, 			true);
		this.paused = true;
	}
}

_this.mute = function (lMute) {
	if (lMute != this.lMute) {
		this.assign(this.fnMuteAudio, 				true);
		this.assign(this.requestAlert, 				true);
		this.lMute = lMute;
	}
}

_this.getPosition = function () {
	// Need to wait after issuing pause request for the variable to be updated by Flash	
	this.position = this.access(this.swfAudioPosition);
	alert(this.position);
}

_this.setPosition = function () {
	this.assign(this.swfAudioPosition, this.position);
}
		
_this.fadeTime = function () {
	this.assign(this.swfFadeAudioTime, 2);
	/*
	This is the time to fade in or out in seconds.
	The fade takes 10 steps over this period.
	The minimum period is 1 second.
	The default period is 5 seconds.
	*/
}

	
_this.assign = function (cVarName, cVarData) {
	this.player.SetVariable("/:" + cVarName, cVarData);			
}
 	
_this.access = function(cVarName) {	
	return this.player.GetVariable("/:" + cVarName);
}

_this.enable = function () {
	this.lEnable = true;	
}

_this.disable = function () {
	this.lEnable = false;	
}

///////////////////// end ////////////////////////


///////////////////// videoControl ///////////////

function videoControl(){}

var _this = videoControl.prototype = new Object();

_this.constructor	= videoControl;
_this.player;
_this.hDelay;
_this.cVideoName;
_this.nInterval;
_this.cPlayerId;
_this.lMute;

_this.requestAlert;
_this.swfVideoName;
_this.fnPlayVideo;
_this.swfVideoStartTime;
_this.fnStopVideo;
_this.fnPauseResumeVideo;
_this.fnMuteVideo;

_this.init = function ( cVar ) {
	
	this.requestAlert				= "reqAlt";
	this.swfVideoName				= "varVN";
	this.fnPlayVideo				= "fnPV";
	this.swfVideoStartTime		= "varVST";
	this.fnStopVideo				= "fnSV";
	this.fnPauseResumeVideo		= "fnPRV";
	this.fnMuteVideo				= "fnMV";
	
	this.cPlayerId 	= cVar;
	this.lMute			= false;
	
	this.hDelay			= 0;
	this.cVideoName	= "";
	this.nInterval		= 0;
	
	var ie = navigator.appName.indexOf("Microsoft") != -1;
	this.player = (ie) ? window[this.cPlayerId] : document[this.cPlayerId];	
	//this.player = document.getElementById(cPlayerId);	
}

_this.play			= function (cVideoName, nInterval) {
	var self = this;
	this.cVideoName = cVideoName;
	this.nInterval = 1000 * nInterval;
	if (this.nInterval > 0) {
		this.hDelay = setTimeout( function () {self.delayedPlay()}, this.nInterval); 
	}
	else {
		this.assign(this.swfVideoName, 	cVideoName);
		this.assign(this.fnPlayVideo, 	true);
		this.assign(this.requestAlert, 	true);
	}
}

_this.delayedPlay = function () {
	clearTimeout(this.hDelay);
	// aps added 13.04.2006
	this.assign(this.swfVideoStartTime, 5); // set to 5 seconds delay - default is also 5 seconds	
	this.assign(this.swfVideoName, 	this.cVideoName);
	this.assign(this.fnPlayVideo, 	true);
	this.assign(this.requestAlert, 	true);
}

_this.stop = function () {
	this.assign(this.fnStopVideo, 				true);
	this.assign(this.requestAlert, 				true);
}

_this.pauseResume	= function () {
	this.assign(this.fnPauseResumeVideo, 		true);
	this.assign(this.requestAlert, 				true);
}

_this.mute = function (lMute) {
	if (lMute != this.lMute) {
		this.assign(this.fnMuteVideo, 				true);
		this.assign(this.requestAlert, 				true);
		this.lMute = lMute;
	}
}

_this.startTime = function () {
	this.assign(this.swfVideoStartTime, 5); // set to 5 seconds delay - default is also 5 seconds	
}

_this.assign = function (cVarName, cVarData) {
	this.player.SetVariable("/:" + cVarName, cVarData);			
}
 	
_this.access = function(cVarName) {	
	return this.player.GetVariable("/:" + cVarName);
}

///////////////////// end ////////////////////////


//////////////////// logoWrapper /////////////////

function logoWrapper(){}

var _this = logoWrapper.prototype = new Object();
_this.constructor		= logoWrapper;
_this.aLogoIds;
_this.aDivElements;
_this.aFlashObjects;
_this.cCurFlashId;

_this.init = function ( aVars ) {
	
	this.aDivElements		= [];
	this.aFlashObjects	= [];
	this.cCurFlashId		= "";
	
	this.aLogoIds = aVars;
	for (var nIndex = 0; nIndex < this.aLogoIds.length; nIndex = nIndex + 1) {
		var cDivId 		= this.aLogoIds[nIndex][0];
		var cFlashId 	= this.aLogoIds[nIndex][1];
		
		this.aDivElements[cFlashId] = document.getElementById(cDivId);
		this.aDivElements[cFlashId].style.display = "none";
		
		this.aFlashObjects[cFlashId] = new logoControl();	
		this.aFlashObjects[cFlashId].init(cFlashId);
		// alert(this.aDivElements[cFlashId].innerHTML);
	}	
}

_this.play = function (cNewFlashId) {
	if (this.cCurFlashId != "") {
		this.aDivElements[this.cCurFlashId].style.display = "none";
	}
	this.aDivElements[cNewFlashId].style.display = "";
	this.aFlashObjects[cNewFlashId].play();
	this.cCurFlashId = cNewFlashId;

}

_this.replay = function () {
	this.aFlashObjects[this.cCurFlashId].play();	
}

//////////////////////// end /////////////////////


///////////////////// logoControl ///////////////

function logoControl(){}

var _this = logoControl.prototype = new Object();
_this.constructor	= logoControl;
_this.player;

_this.init = function (cPlayerId) {
	var ie = navigator.appName.indexOf("Microsoft") != -1;
	this.player = (ie) ? window[cPlayerId] : document[cPlayerId];	
	// this.player = document.getElementById(cPlayerId);	
}

_this.play = function () {	
	this.assign("requestAlert", 	true);
}

_this.assign = function (cVarName, cVarData) {
	try{this.player.SetVariable("/:" + cVarName, cVarData);	}catch(e){}
}
 	
_this.access = function(cVarName) {	
	return this.player.GetVariable("/:" + cVarName);
}

///////////////////// end ////////////////////////

