///////////////////// swfPlayerGobalFunctions /////////////////////

var swfFormFixStatus = false;
var swfFormFixDelay = 0;

swfPlayerSetFormFixStatus = function () {
	clearInterval(swfFormFixDelay);
	swfFormFixStatus = true;
}

swfPlayerCheckFormFixStatus = function () {
	return swfFormFixStatus;
}

/////////////////////////// end ////////////////////////


///////////////////// swfPlayerControl /////////////////////

function swfPlayerControl(){}

var _this = swfPlayerControl.prototype = new Object();

_this.constructor			= swfPlayerControl;

_this.className = "swfPlayerControl";

_this.browser = "";

_this.aSwfControls = [];
_this.aSwfPlayerName = [];
_this.aSwfControlStatus = [];

_this.init = function () {

	if (navigator.appName.indexOf("Microsoft") != -1) {
		// IE
		this.browser = "IE";
	} else {
		// FireFox
		this.browser = "FF";
	}
	
}

_this.addSwfControl = function (cControl, cPlayer) {
	this.aSwfControls.push(cControl);
	this.aSwfPlayerName.push(cPlayer);
	this.aSwfControlStatus.push(false);
}

_this.swfFormFixInit = function (cControl) {
	var lOk = true;	
	for (nIndex = 0; nIndex <= this.aSwfControls.length - 1; nIndex = nIndex + 1) {
		if (this.aSwfControls[nIndex] == cControl) {
			this.aSwfControlStatus[nIndex] = true;	
		}
	}
	for (nIndex = 0; nIndex <= this.aSwfControls.length - 1; nIndex = nIndex + 1) {
		if (!this.aSwfControlStatus[nIndex]) {
			lOk = false;
		}			
	}
	if (lOk) {
		//  All form fix requests received
		this.swfFormFixProcessing();
	}
}

_this.swfFormFixProcessing = function(aSwfPlayers) {
	swfFormFixDelay = setInterval( function () {swfPlayerSetFormFixStatus()}, 200);
	if (this.browser == "IE") {
		SWFFormFix(this.aSwfPlayerName[this.aSwfPlayerName.length - 1]);
	}
}			

_this.swfBrowser = function () {
	return this.browser;
}

/////////////////////////// end ////////////////////////


///////////////////// InstallSwf ///////////////

function InstallSwf(){}

var _this = InstallSwf.prototype = new Object();

_this.constructor	= InstallSwf;

_this.className = "InstallSwf";

_this.name;
_this.parent;
_this.version;

_this.playerVersion;
_this.majorVersion;
_this.minorVersion;
_this.releaseVersion;
_this.message;
_this.playerDiv;
_this.minimumMajor;
_this.requiredMajor;
_this.requiredMinor;
_this.requiredRelease;

_this.init = function (cName, cPlayerDiv, cPlayerRoot) {
	this.playerDiv = cPlayerDiv;
	this.version = true;
	this.playerVersion 		= swfobject.getFlashPlayerVersion(); 
	this.majorVersion 		= this.playerVersion.major;
	this.minorVersion 		= this.playerVersion.minor;
	this.releaseVersion 	= this.playerVersion.release;	
	this.minimumMajor     = "9";
	this.requiredMajor 		= "9";
	this.requiredMinor    = "0";
	this.requiredRelease  = "115";
	document.getElementById(this.playerDiv).style.display='none';
	if ( (this.majorVersion == "0") && (this.minorVersion == "0") && (this.releaseVersion == "0") ) {
		this.flashInstallMessage(cPlayerRoot);
		document.getElementById(this.playerDiv).style.display='block';
		document.getElementById(this.playerDiv).innerHTML  = this.message
		this.version = false;			
	} else {
		if (this.majorVersion < this.minimumMajor) {
			this.flashUpgradeMessage(cPlayerRoot);
			document.getElementById(this.playerDiv).style.display='block';
			document.getElementById(this.playerDiv).innerHTML  = this.message	
			this.version = false;
		} else {
			if (this.majorVersion == this.requiredMajor) {
				if (this.releaseVersion < this.requiredRelease) {
					this.flashUpgradeMessage(cPlayerRoot);
					document.getElementById(this.playerDiv).style.display='block';
					document.getElementById(this.playerDiv).innerHTML  = this.message
					this.version = false;
				}
			}
		}
	}
}

_this.flashInstallMessage = function (cPlayerRoot) {
	this.message = '<p>You do no have Adobe Flash Player installed.</p>'
	this.message = this.message + '<br>'
	this.message = this.message + '<p>It is recommended that you install the latest version of Adobe Flash Player by clicking on the following button: - </p>';
	this.message = this.message + '<a style="position:absolute; float:left; top:80px; right:50px;" target="_blank" href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" style="border:0px;" alt="Get Adobe Flash player" /></a>'	
	this.message = this.message + '<br><br>'
	this.message = this.message + 'If you wish to enter the website without updating, then please click on the following button: -</p><br>'	
	this.message = this.message + '<a onclick="bypassFlashUpdate()" style="position:absolute; float:left; top:160px; right:50px;" href="#"><img src=' + cPlayerRoot + '/enterbutton.gif style="border:0px;" alt="Enter Website" /></a>'
	this.message = this.message + '<br><p>If you find that aspects of the website do not function correctly, then please re-enter and download the Flash update.</p>'	
}

_this.flashUpgradeMessage = function (cPlayerRoot) {
	this.message = '<p>You have Adobe Flash Player Version ' + this.majorVersion + '.' + this.minorVersion + '.' + this.releaseVersion + '.0 installed.</p>'
	this.message = this.message + '<br>'
	this.message = this.message + '<p>It is recommended that you upgrade to the latest version of Adobe Flash Player by clicking on the following button: - </p>';
	this.message = this.message + '<a style="position:absolute; float:left; top:80px; right:50px;" target="_blank" href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" style="border:0px;" alt="Get Adobe Flash player" /></a>'	
	this.message = this.message + '<br><br>'
	this.message = this.message + 'If you wish to enter the website without updating, then please click on the following button: -</p><br>'	
	this.message = this.message + '<a onclick="bypassFlashUpdate()" style="position:absolute; float:left; top:160px; right:50px;" href="#"><img src=' + cPlayerRoot + '/enterbutton.gif style="border:0px;" alt="Enter Website" /></a>'
	this.message = this.message + '<br><p>If you find that aspects of the website do not function correctly, then please re-enter and download the Flash update.</p>'	
}

_this.hide = function () {
	document.getElementById(this.playerDiv).style.display='none';		
}

_this.loaded = function () {
	return this.version;	
}

///////////////////// end ////////////////////////


///////////////////// slideshowControl /////////////////////

function slideshowControl(){}

var _this = slideshowControl.prototype = new swfPlayerControl();

_this.constructor = slideshowControl;

_this.className = "slideshowControl";

_this.name;
_this.parent;
_this.oPlayer;
_this.playerName;
_this.playerElement;
_this.playerDiv; 
_this.playerRootUrl;
_this.playerUrl; 
_this.playerWidth; 
_this.playerHeight; 
_this.playerVersion; 
_this.playerBackground; 

_this.slideshowStatus;

_this.loaded;
_this.formFix;

_this.delay;

_this.xmlData;
_this.xmlContent;

_this.init = function (cName, aPlayer, cXmlData, cXmlContent) {
		
	swfPlayerControl.prototype.init.call(this, cName) 
	
	this.name = cName;
			
	this.loaded = false;		
	
	this.slideshowStatus = "Initial";
		
	if (aPlayer[1].substr(aPlayer[1].length - 1, 1) == "/") {
		this.playerRootUrl = aPlayer[1];	
	} else {
		this.playerRootUrl = aPlayer[1] + "/";		
	}

	this.setPlayer(aPlayer);

	this.xmlData 		= cXmlData;
	this.xmlContent = cXmlContent;
	
	this.instantiate();
		
}	

_this.swfInit = function () {
	this.playerElement.swfInit(this.xmlData, this.xmlContent);			
}

_this.swfStart = function () {
	var self = this;
	if (this.loaded) {
		this.playerElement.swfStart();	
	} else {
		this.delay = setInterval( function () {self.delayedStart()}, 50); 
	}	
}

_this.delayedStart = function () {
	if (this.loaded) {
		clearInterval(this.delay);
		this.playerElement.swfStart();
	}
}

_this.swfDeletePlayer = function () {	
	if (this.playerElement) {
		this.playerElement.swfReset();
	}
	swfobject.removeSWF(this.playerDiv);
	delete this.oPlayer;
}

_this.swfStop = function () {	
	if (this.loaded) {
		this.playerElement.swfStop();
	}
}

_this.swfGotoImage = function (nImg) {
	this.playerElement.swfGoToImage(nImg);
}

_this.swfPauseResume	= function () {
	this.playerElement.swfPauseResume();
}

_this.swfPreviousImage	= function () {
	this.playerElement.swfPreviousImage();
}

_this.swfNextImage	= function () {
	this.playerElement.swfNextImage();
}

_this.setPlayer = function (aPlayer) {
		
	this.playerDiv 					= aPlayer[0];
	this.playerUrl 					= this.playerRootUrl + aPlayer[2];
	this.playerWidth 				= aPlayer[3];
	this.playerHeight 			= aPlayer[4];
	this.playerVersion 			= aPlayer[5];
	this.playerBackground 	= aPlayer[6];

	this.playerName = "";
	var cTemp = this.playerUrl.toLowerCase();

	var aParts = cTemp.split("/");
	var cName = aParts[aParts.length - 1].replace(".swf", "");
	if ( typeof top[cName] == "undefined") {
		top[cName] = 0;
	}
	top[cName] = top[cName] + 1;
	this.playerName = cName + top[cName];
		
}

_this.instantiate = function ( ) {
		
	var swfVariables 		= {swfCallBack:this.name + ".swfStatus"};
	var swfParameters 	= {wmode:"transparent"};
	var swfAttributes 	= {id:this.playerName, name:this.playerName};
	var swfInstall			= "";
	swfobject.embedSWF(this.playerUrl + "?rnd=" + (new Date()).getTime().toString(), this.playerDiv, this.playerWidth, this.playerHeight, this.playerVersion, swfInstall, swfVariables, swfParameters, swfAttributes);
	
}

_this.swfStatus = function(cStatus) {
	var self = this;
	switch(cStatus) {
		case "Movie:Loaded":
 			this.playerElement = document.getElementById(this.playerName);		
 			this.swfFormFixInit();	
			break;
		case "Paused:Off":
			this.slideshowStatus = "Playing";
			break;
		case "Paused:On":
			this.slideshowStatus = "Paused";
			break;
		case "Play:Started":
			this.slideshowStatus = "Started";
			break;
		default:
			break;
	}
	this.parent.swfStatus(this.name, cStatus);
}

_this.swfFormFixInit = function () {
	var self = this; 	
	this.formFix = setInterval( function () {self.waitingFormFix()}, 50); 
	this.addSwfControl(this.name, this.playerName);
	swfPlayerControl.prototype.swfFormFixInit.call(this, this.name);
}

_this.waitingFormFix = function () {
	if (swfPlayerCheckFormFixStatus()) {
		clearInterval(this.formFix);
		this.loaded = true;
		this.swfInit();
		// this.parent.swfStatus(this.name,"SwfFormFixed");
	}	
}

///////////////////// end ////////////////////////


