///////////////////// 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
		if (this.browser == "IE") {
			this.swfFormFixProcessing();
		}
	}
}

_this.swfFormFixProcessing = function(aSwfPlayers) {
	swfFormFixDelay = setInterval( function () {swfPlayerSetFormFixStatus()}, 200);
	SWFFormFix(this.aSwfPlayerName[0]);
}			

_this.swfBrowser = function () {
	return this.browser;
}

/*
http://phrogz.net/js/Classes/OOPinJS.html
*/


/////////////////////////// end ////////////////////////


///////////////////// audioControl 2008 /////////////////////

function audioControl(){}

var _this = audioControl.prototype = new swfPlayerControl();

_this.constructor			= audioControl;

_this.className = "audioControl";

_this.name;
_this.parent;
_this.oPlayer;

_this.playerName;
_this.playerDiv; //  "flashcontent_3";
_this.playerUrl; //  "http://martinxp/Flash_2008/Audio_Player.swf";
_this.playerWidth; //  "0";
_this.playerHeight; //  "0";
_this.playerVersion; //  "8";
_this.playerBackground; //  "#ffffff";
_this.playerDomains; //  "http://martinxp, http://www.ccloe.co.uk";
_this.playerElement;
_this.playerRootUrl;

_this.audioTracks;			//	["Track1", "Track2", "Track3", "Track4", "Track5", "Track6"];
_this.initialAudioTrack;	//	0;
_this.audioFolder;			//	"http://www.ccloe.co.uk/Flash_2008/Audio_Player_0/Media/"; 
_this.audioFadeTime;			// 2; seconds

_this.currentTrack;
_this.muted;
_this.paused;
_this.audioStatus;

_this.loadingDelay;
_this.waitingDelay;

_this.formFix;
_this.loaded;


_this.init = function (cName, aPlayer, aTracks, nIniTrack, cFolder, nFadeTime) {
		
	swfPlayerControl.prototype.init.call(this) 

	this.name = cName;
		
	this.loaded = false;		
	
	this.audioStatus = "Initial";
	
	this.setPlayer(aPlayer[0], aPlayer[1], aPlayer[2], aPlayer[3], aPlayer[4], aPlayer[5], aPlayer[6], aPlayer[7]);

	this.setTracks(aTracks, nIniTrack, cFolder, nFadeTime)

	swfPlayerControl.prototype.addSwfControl.call(this, this.name, this.playerName);
	
	this.instantiate();
		
}	
	
_this.playInitialTrack = function () {
	this.play(this.initialTrack);	
}

_this.replay = function () {
	if (this.currentTrack != undefined) { 
		if (this.loaded) {
			this.play(this.currentTrack);
		}
	}
}

_this.play = function (nIndex) {
	var self = this;
	clearInterval(this.loadingDelay);
	if (nIndex != undefined) {
		if (this.soundTracks[nIndex - 1] != undefined) {
			this.currentTrack = this.soundTracks[nIndex - 1];
			this.loadingDelay = setInterval( function () {self.delayedPlay()}, 100); 
		}
	}
}

_this.delayedPlay = function () {
	if (this.loaded) {
		this.startPlaying();
		clearInterval(this.loadingDelay);
	}
}

_this.startPlaying = function() {
	var self = this;
	clearInterval(this.waitingDelay);
	if (this.audioStatus == "Initial" || this.audioStatus == "Stopped" || this.audioStatus == "Finished") {
		this.playerElement.swfStartAudio(this.currentTrack);	
	} else {
		this.playerElement.swfStopAudio();	
		this.waitingDelay = setInterval( function () {self.waitingOnStopped()}, 100); 
	}
}

_this.waitingOnStopped = function() {
	if (this.audioStatus == "Initial" || this.audioStatus == "Stopped" || this.audioStatus == "Finished") {
		clearInterval(this.waitingDelay);
		this.playerElement.swfStartAudio(this.currentTrack);	
	}	
}

_this.stop = function () {
	// alert("Stop")
	if (this.loaded) {
		this.playerElement.swfStopAudio();	
	}
}

_this.pauseResume	= function () {
	if (this.loaded) {
		if (this.audioStatus == "Started") {
			this.playerElement.swfPauseResumeAudio();	
		}
	}
}

_this.mute = function (lMute) {
	if (this.loaded) {
		if (this.audioStatus == "Started") {
			this.playerElement.swfMuteAudio();	
		}
	}
}

_this.volume = function (nVol) {
	if (this.loaded) {
		if (this.audioStatus == "Started") {
			this.playerElement.swfVolume(nVol);	
		}
	}
}

_this.setPlayer = function (cDiv, cRootUrl, cFolder, cWidth, cHeight, cVersion, cColour, cDomains) {
		
	this.playerDiv 				= cDiv;
	if (cRootUrl.substr(cRootUrl.length - 1, 1) == "/") {
		this.playerRootUrl = cRootUrl;	
	} else {
		this.playerRootUrl = cRootUrl + "/";		
	}
	this.playerUrl 				= this.playerRootUrl + cFolder;
	this.playerWidth 				= cWidth;
	this.playerHeight 			= cHeight;
	this.playerVersion 			= cVersion;
	this.playerBackground 		= cColour;
	this.playerDomains 			= cDomains;

	this.playerName = "";
	var cTemp = this.playerUrl.toLowerCase();

	var aParts = cTemp.split("/");
	this.playerName = aParts[aParts.length - 1].replace(".swf", "");
	
}

_this.setTracks = function (aTracks, nIniTrack, cFolder, nFadeTime) {
	
	if (cFolder.substr(cFolder.length - 1, 1) == "/") {
		this.mediaFolder = this.playerRootUrl + cFolder;	
	} else {
		this.mediaFolder = this.playerRootUrl + cFolder + "/";		
	}
	this.soundTracks = [];
	for (nIndex = 0; nIndex < aTracks.length; nIndex = nIndex + 1) {
		this.soundTracks.push(this.mediaFolder + aTracks[nIndex] + ".mp3");	
	}
	this.initialTrack  = +nIniTrack;
	if (this.initialTrack > 0) {
		this.initialTrack = this.initialTrack;
	}	
	this.audioFadeTime = +nFadeTime;
	
}

_this.instantiate = function ( ) {
		
	var cRand = (new Date()).getTime().toString();

	document.getElementById(this.playerDiv).innerHTML  = "The slideshows, sound tracks and videos on this website require the use of Adobe Flash Player Version 8.0 or higher";			

	window[this.playerName] = new Object();  	
		
	this.oPlayer = new SWFObject(this.playerUrl + "?rnd=" + cRand, this.playerName, this.playerWidth, this.playerHeight, this.playerVersion, this.playerBackground); 
	this.oPlayer.addParam("loop", false);
	this.oPlayer.addParam("play", false);
	this.oPlayer.addVariable("swfCallBack", this.parent.name + "." + this.name + ".swfAudioStatus");
	this.oPlayer.addVariable("swfPermittedDomains", 	this.playerDomains);
	this.oPlayer.addVariable("swfAudioFadeTime", 		this.audioFadeTime);		
	this.oPlayer.useExpressInstall(this.playerRootUrl + "ExpressInstall.swf" + "?rnd=" + cRand)
	this.oPlayer.write(this.playerDiv);

}

_this.swfAudioStatus = function(cStatus) {
	var self = this;
	this.parent.swfStatus(this.name, cStatus);
	// alert("Audio " + cStatus)
	// document.getElementById("audioStatus").value = document.getElementById("audioStatus").value + cStatus + "\r\n"; // 19:35 19/2/08
	switch(cStatus) {
		case "Player:Loaded":
			if (swfPlayerControl.prototype.swfBrowser.call() == "IE") {
				this.playerElement = window[this.playerName];
			} else {
				this.playerElement = document[this.playerName];
			}
			this.formFix = setInterval( function () {self.waitingFormFix()}, 100); 
			swfPlayerControl.prototype.swfFormFixInit.call(this, this.name);
			break;
		case "Muted:Off":
			this.muted = false;
			break;
		case "Muted:On":
			this.muted = true;
			break;
		case "Paused:Off":
			this.paused = false;
			break;
		case "Paused:On":
			this.paused = true;
			break;
		case "Play:Started":
			this.audioStatus = "Started";
			break;
		case "Play:Stopped":
			this.audioStatus = "Stopped";
			break;
		case "Play:Finished":
			this.audioStatus = "Finished";
			break;
		default:
			break;
	}
}

_this.waitingFormFix = function () {
	if (swfPlayerCheckFormFixStatus()) {
		clearInterval(this.formFix);
		this.loaded = true;
		this.parent.swfStatus(this.name,"SwfFormFixed");
	}	
}

///////////////////// end ////////////////////////


///////////////////// videoControl 2008 ///////////////


function videoControl(){}

var _this = videoControl.prototype = new swfPlayerControl();

_this.constructor	= videoControl;

_this.className = "videoControl";

_this.name;
_this.parent;
_this.oPlayer;

_this.playerName;
_this.playerDiv; //  "flashcontent_3";
_this.playerUrl; //  "http://martinxp/Flash_2008/Audio_Player.swf";
_this.playerWidth; //  "0";
_this.playerHeight; //  "0";
_this.playerVersion; //  "8";
_this.playerBackground; //  "#ffffff";
_this.playerDomains; //  "http://martinxp, http://www.ccloe.co.uk";
_this.playerElement;
_this.playerRootUrl;

_this.bufferTime; //  6;

_this.spinnerState; //  "Enabled";
_this.spinnerX; //  250;
_this.spinnerY; //  200;
_this.spinnerColour; //  0xf6732d;
_this.spinnerUrl; //  "http://www.ccloe.co.uk/Flash_2008/Video_Player_4/Spinner.swf";

_this.overlayState; //  "Enabled";
_this.overlayColour; //  0xf6732d;
_this.overlayMovieUrl; //  "http://www.ccloe.co.uk/Flash_2008/Video_Player_4/Overlay.swf"
_this.overlayImageUrl; //  "http://www.ccloe.co.uk/Flash_2008/Video_Player_4/Media/Corners.png" 

_this.backgroundState; //  "Enabled";
_this.backgroundMovieUrl; //  "http://www.ccloe.co.uk/Flash_2008/Video_Player_4/Background.swf"
_this.backgroundImageUrl; //  "http://www.ccloe.co.uk/Flash_2008/Video_Player_4/Media/ASandLShowcase.jpg"

_this.formFix;
_this.loaded;

_this.videoStatus;
_this.muted;
_this.paused;
_this.flvStatus;
_this.hidden;

_this.flvName;

_this.delay;

_this.init = function (cName, aPlayer, aSpinner, aOverlay, aBackground) {
// _this.init = function (cName, aPlayer, aVideo, aSpinner, aOverlay, aBackground) {
	
	swfPlayerControl.prototype.init.call(this) 
	
	this.name = cName;
				
	this.loaded = false;

	this.setPlayer(aPlayer[0], aPlayer[1], aPlayer[2], aPlayer[3], aPlayer[4], aPlayer[5], aPlayer[6], aPlayer[7]);
	
	this.bufferTime = aPlayer[8];
	
	if (aSpinner[0]) {
		this.setSpinner(aSpinner[0], aSpinner[1], aSpinner[2], aSpinner[3], aSpinner[4]);	
	} else {
		this.setSpinner(aSpinner[0]);
	}
	if (aOverlay[0]) {
		this.setOverlay(aOverlay[0], aOverlay[1], aOverlay[2], aOverlay[3]);
	} else {
		this.setOverlay(aOverlay[0]);	
	}
	if (aBackground[0]) {
		this.setBackground(aBackground[0], aBackground[1], aBackground[2]);
	} else {
		this.setBackground(aBackground[0]);
	}
	
	swfPlayerControl.prototype.addSwfControl.call(this, this.name, this.playerName);
	
	document.getElementById(this.playerDiv).style.display = "";
	this.hidden = false;

	this.instantiate();
	
}

_this.play = function (cFlv) {
	var self = this;
	// alert(cFlv)
	if (cFlv != undefined) {
		this.cFlvName = cFlv;
		if (this.loaded) {
			this.playerElement.swfStartVideo(this.cFlvName);	
		} else {
			this.delay = setInterval( function () {self.delayedPlay()}, 100); 
		}
	}
}

_this.delayedPlay = function () {
	// alert(this.cFlvName)
	if (this.loaded) {
		clearInterval(this.delay);
		this.playerElement.swfStartVideo(this.cFlvName);	
	}
}

_this.stop = function () {
	clearInterval(this.delay);
	if (this.loaded) {
		this.playerElement.swfStopVideo();
	}
}

_this.pauseResume	= function () {
	if (this.loaded) {
		this.playerElement.swfPauseResumeVideo();
	}
}

_this.mute = function () {
	if (this.loaded) {
		this.playerElement.swfMutePlaySound();
	}
}

_this.volume = function (nVolume) {
	if (this.loaded) {
		this.playerElement.swfVolume(nVolume);
	}
}


_this.hideReveal = function () {
	if (this.hidden) {
		document.getElementById(this.playerDiv).style.display = "";
		this.hidden = false;
	} else{
		document.getElementById(this.playerDiv).style.display = "none";
		this.hidden = true;
	}
}

_this.setPlayer = function (cDiv, cRootUrl, cFolder, cWidth, cHeight, cVersion, cColour, cDomains) {
		
	this.playerDiv 				= cDiv;
	if (cRootUrl.substr(cRootUrl.length - 1, 1) == "/") {
		this.playerRootUrl = cRootUrl;	
	} else {
		this.playerRootUrl = cRootUrl + "/";		
	}
	this.playerUrl 				= this.playerRootUrl + cFolder;
	this.playerWidth 				= cWidth;
	this.playerHeight 			= cHeight;
	this.playerVersion 			= cVersion;
	this.playerBackground 		= cColour;
	this.playerDomains 			= cDomains;

	this.playerName = "";
	var cTemp = this.playerUrl.toLowerCase();

	var aParts = cTemp.split("/");
	this.playerName = aParts[aParts.length - 1].replace(".swf", "");
	
}

// Modified 11:53 20/2/08
_this.instantiate = function ( ) {
		
	var cRand = (new Date()).getTime().toString();
	
	document.getElementById(this.playerDiv).innerHTML  = "The slideshows, sound tracks and videos on this website require the use of Adobe Flash Player Version 8.0 or higher";			

	window[this.playerName] = new Object();  	
		
	this.oPlayer = new SWFObject(this.playerUrl + "?rnd=" + cRand, this.playerName, this.playerWidth, this.playerHeight, this.playerVersion, this.playerBackground); 
	this.oPlayer.addVariable("swfCallBack", this.parent.name + "." + this.name + ".swfVideoStatus");
	this.oPlayer.addVariable("swfPermittedDomains", 	this.playerDomains);
	this.oPlayer.addVariable("swfFlvBufferTime", 		this.bufferTime);
		
	// Spinner
	this.oPlayer.addVariable("swfSpinner", 			this.spinnerState);
	this.oPlayer.addVariable("swfXSpinner", 			this.spinnerX);
	this.oPlayer.addVariable("swfYSpinner", 			this.spinnerY);
	this.oPlayer.addVariable("swfSpinnerColour", 	this.spinnerColour);
	this.oPlayer.addVariable("swfSpinnerUrl", 		this.spinnerUrl + "?rnd=" + cRand);
	
	// Overlay
	this.oPlayer.addVariable("swfOverlay", 			this.overlayState);
	this.oPlayer.addVariable("swfOverlayColour", 	this.overlayColour);	
	this.oPlayer.addVariable("swfOverlayUrl", 		this.overlayMovieUrl + "?rnd=" + cRand);
	this.oPlayer.addVariable("swfOlImageUrl", 		this.overlayImageUrl)	
	
	// Background
	this.oPlayer.addVariable("swfBackground", 		this.backgroundState);
	this.oPlayer.addVariable("swfBackgroundUrl", 	this.backgroundMovieUrl + "?rnd=" + cRand);
	this.oPlayer.addVariable("swfBgImageUrl", 		this.backgroundImageUrl)	

	this.oPlayer.useExpressInstall(this.playerRootUrl + "ExpressInstall.swf" + "?rnd=" + cRand)
	
	this.oPlayer.write(this.playerDiv);
	
}

_this.setSpinner = function(lState, nPosnX, nPosnY, nColour, cSwfFile) {
	if(lState) {
		this.spinnerState 	= "Enabled";
		this.spinnerX 			= nPosnX;
		this.spinnerY 			= nPosnY;
		this.spinnerColour 	= nColour;
		this.spinnerUrl 		= this.playerRootUrl + cSwfFile;
	} else {
		this.spinnerState 	= "Disabled";		
	}
}

_this.setBackground = function(lState, cSwfFile, cImgFile) {
	if(lState) {
		this.backgroundState 	= "Enabled";
		this.backgroundMovieUrl = this.playerRootUrl + cSwfFile;
		this.backgroundImageUrl	= this.playerRootUrl + cImgFile;
	} else {
		this.backgroundState 	= "Disabled";		
	}
}

_this.setOverlay = function(lState, nColour, cSwfFile, cImgFile) {
	if(lState) {
		this.overlayState 		= "Enabled";
		this.overlayColour 		= nColour
		this.overlayMovieUrl 	= this.playerRootUrl + cSwfFile;
		this.overlayImageUrl		= this.playerRootUrl + cImgFile;
	} else {
		this.overlayState 	= "Disabled";		
	}
}

_this.swfVideoStatus = function(cStatus) {
	var self = this; // 19:35 19/2/08
	this.parent.swfStatus(this.name, cStatus);
	switch(cStatus) {
		case "Movie:Loaded":
			// alert("Video " + cStatus)
			if (swfPlayerControl.prototype.swfBrowser.call() == "IE") {
				this.playerElement = window[this.playerName];
			} else {
				this.playerElement = document[this.playerName];
			}
			this.formFix = setInterval( function () {self.waitingFormFix()}, 200); 
			swfPlayerControl.prototype.swfFormFixInit.call(this, this.name);
			break;
		case "Muted:Off":
			this.muted = false;
			break;
		case "Muted:On":
			this.muted = true;
			break;
		case "Paused:Off":
			this.paused = false;
			break;
		case "Paused:On":
			this.paused = true;
			break;
		case "Flv:Started":
			this.flvStatus = "Started";
			break;
		case "Flv:Stopped":
			this.flvStatus = "Stopped";
			break;
		case "Flv:Finished":
			this.flvStatus = "Finished";
			break;
		default:
			break;
	}
}

_this.waitingFormFix = function () {
	if (swfPlayerCheckFormFixStatus()) {
		clearInterval(this.formFix);
		this.loaded = true;
		this.parent.swfStatus(this.name,"SwfFormFixed");
	}	
}

///////////////////// end ////////////////////////


///////////////////// swfControl ///////////////

function swfControl(){}

var _this = swfControl.prototype = new swfPlayerControl();

_this.constructor	= swfControl;

_this.className = "swfControl";

_this.name;
_this.parent;

_this.playerElement;
_this.playerBufferTime; //  6;
_this.playerLoop;			// false
_this.playerWmode;		// "opaque" // 17:58 19/2/08 

_this.videoStatus;
_this.muted;
_this.paused;
_this.flvStatus;
_this.loaded;
_this.hidden;

_this.flvName;

_this.delay;

_this.init = function (cName, aPlayer, aParams) {
	
	swfPlayerControl.prototype.init.call(this) 	

	this.name = cName;
		
	this.loaded = false;
	this.hidden = false;

	this.setPlayer(aPlayer[0], aPlayer[1], aPlayer[2], aPlayer[3], aPlayer[4], aPlayer[5], aPlayer[6], aPlayer[7]);

	this.setParams(aParams[0], aParams[1]); // 9:57 20/2/08
	
	this.addSwfControl(this.name, this.playerName);

	this.instantiate();

	this.swfFormFix(this.name)
	
}

// Modified 11:53 20/2/08
_this.instantiate = function ( ) {
		
	var cRand = (new Date()).getTime().toString();
		
	window[this.playerName] = new Object();  	
		
	this.oPlayer = new SWFObject(this.playerUrl + "?rnd=" + cRand, this.playerName, this.playerWidth, this.playerHeight, this.playerVersion, this.playerBackground); 
	this.oPlayer.addParam("loop", this.playerLoop);
	this.oPlayer.addParam("wmode", this.playerWmode); // 17:58 19/2/08
	this.oPlayer.write(this.playerDiv);
			
}

_this.setParams = function (lLoop, cWmode) {		
	this.playerLoop = lLoop;
    this.playerWmode = cWmode; 	// 17:58 19/2/08
}

///////////////////// 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 ////////////////////////

