﻿<!--

// Flash functions
	
	function flashEmbedCode(flashVer, getID, getSrc, getWidth, getHeight) {
		// store id, widthn and height values
		this.flashVer = flashVer;
		this.flashID = getID;
		this.flashSrc = getSrc;
		this.flashWidth = getWidth;
		this.flashHeight = getHeight;
		// initialise parameter storage
		this.paramCount = 0;
		this.paramNames = new Array();
		this.paramValues = new Array();
	}
	
	flashEmbedCode.prototype.addParam = function(paramName, paramValue) {
		this.paramNames[this.paramCount] = paramName;
		this.paramValues[this.paramCount] = paramValue;
		this.paramCount += 1;
	}
	
	flashEmbedCode.prototype.buildFlashCode = function() {
		this.objectString = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=" + this.flashVer + ",0,0,0' ";
		this.embedString = "<embed type='application/x-shockwave-flash' ";
		// id
		if(this.flashID != "") {
			this.objectString += "id= '" + this.flashID + "' ";
			this.embedString += "name= '" + this.flashID + "' ";
		}
		// dimensions
		this.objectString += "width = '" + this.flashWidth + "' height = '" + this.flashHeight + "'>";
		this.embedString += "width = '" + this.flashWidth + "' height = '" + this.flashHeight + "' ";
		// path
		if(this.flashSrc.indexOf("?") > 0) {
			this.flashSrc += "&flashID=" + this.flashID
		} else {
			this.flashSrc += "?flashID=" + this.flashID
		}
		this.objectString += "<param name='movie' value='" + this.flashSrc + "'>";
		this.embedString += "src='" + this.flashSrc + "' ";
		// object parameters
		if(this.paramCount > 0) {
			for(this.i = 0; this.i < this.paramCount; this.i++) {
				this.objectString += "<param name='" + this.paramNames[this.i] + "' value='" + this.paramValues[this.i] + "'>";
				this.embedString += this.paramNames[this.i] + "='" + this.paramValues[this.i] + "' ";
			}
		}
		// finish
		this.embedString += "\/>";
		return (this.objectString + this.embedString + "<\/object>");
	}
	
// Custom font replacement
	
	function getTrimmedTextContent(srcElement) {
		if(document.all) {
			getText = srcElement.innerText.toString();
		} else {
			getText = srcElement.textContent.toString();
		}
		// clean leading, ending, + multiple spaces
		getText  = getText .replace(/(^\s*)|(\s*$)/gi,"");
		getText  = getText .replace(/[ ]{2,}/gi," ");
		getText  = getText .replace(/\n /,"\n");
		return getText;
	}
	
	function flashH1(toUpper) {
		if (toUpper === undefined) toUpper = true;
		if(document.getElementsByTagName("H1").length > 0) {
			getH1 = document.getElementsByTagName("H1")[0];
			if(flash.ver[9]) {
				// work out which flash movie to use from body class
				getText = (toUpper ? getTrimmedTextContent(getH1).toUpperCase() : getTrimmedTextContent(getH1));
				getTextHTML = getH1.innerHTML;
				getH1.innerHTML = "<span class='flashH1'>";
				tempFLA = new flashEmbedCode(9, "flashH1Title", "\/flash\/thorpe-h1.swf", 770, 65); // flashVer, getID, getSrc, getWidth, getHeight
				tempFLA.addParam("quality","high");
				tempFLA.addParam("wmode","transparent");
				tempFLA.addParam("flashvars","txt=" + escape(getText));
				getH1.innerHTML = tempFLA.buildFlashCode() + "<\/span><span class='hidden'>" + getTextHTML + "<\/span>";
				tempFLA = null;
			} else {
				getH1.className = "nonFlashH1";
			}
			document.getElementsByTagName("H1")[0].style.visibility = "visible";
		}
	}
	
// Homepage Feature Panel functions

	var homeFeaturePanelActive = false;
	var homeFeatureIndex = 1;
	var homeFeatureFlashObject;
	
	function nudgeHomeFeature(nudgeMode) {
		if(homeFeaturePanelActive) {
			if(nudgeMode == true && homeFeatureIndex < homeFeatureTotal) {
				homeFeatureFlashObject.playNextMovie();
			} else if(nudgeMode == false && homeFeatureIndex > 1) {
				homeFeatureFlashObject.playPrevMovie();
			}
		}
	}
	
	function toggleHomeFeature(toggleMode) {
		if(homeFeaturePanelActive) {
			if(toggleMode) {
				homeFeatureFlashObject.toggleMovie(true);
			} else {
				homeFeatureFlashObject.toggleMovie(false);
			}
		}
	}
	
	function setHomeFeature(setIndex) {
		if(setIndex != homeFeatureIndex && homeFeaturePanelActive == true) homeFeatureFlashObject.playSpecificMovie(setIndex-1);
	}
	
	function setHomeFeaturePanelActive() {
		homeFeaturePanelActive = true;
	}
	
	function setHomeFeatureIndex(getIndex) {
		document.getElementById("homeFeatureIndicator" + homeFeatureIndex).className = "indicatorOff";
		homeFeatureIndex = (getIndex+1);
		document.getElementById("homeFeatureIndicator" + homeFeatureIndex).className = "indicatorOn";
	}
	
// Sig Image Movie functions

	var sigVideoFlashObject;

	function sigImageMovie() {
		if(flash.ver[9] && menuMovie != "") {
			tpMoviePlayer = new flashEmbedCode(9, "sigMoviePlayer", "\/flash\/thorpe-video-player-2011-v1.swf?x=" + flashCache, 770, 275); // flashVer, getID, getSrc, getWidth, getHeight
			tpMoviePlayer.addParam("quality","high");
			tpMoviePlayer.addParam("wmode","transparent");
			tpMoviePlayer.addParam("flashvars","sound=" + menuMovieSound + "&flvSrc=" + menuMovie + ((document.location.toString().indexOf('insanefun') >= 0 || document.location.toString().indexOf('frightnights') >= 0) ? "&playNow=true" : ""));
			document.getElementById("mainImage").innerHTML += tpMoviePlayer.buildFlashCode();
		}
	}
	
	function stopSigVideo() {
		if(document.getElementById("sigMoviePlayer")) sigVideoFlashObject.stopVideo();
	}
	
	function hideSigImage() {
		document.getElementById("mainImage").getElementsByTagName("IMG")[0].style.visibility = "hidden";
	}
	
	function showSigImage() {
		document.getElementById("mainImage").getElementsByTagName("IMG")[0].style.visibility = "visible";
	}
	
// modal video functions

	function getModalVideoCode(flvPath, edgeMask) {
		vidCode = "<div class='modalVideo'>";
		tempFla = new flashEmbedCode(9, "modalVideoPlayer", "\/flash\/thorpe-modal-video-player-v2.swf?x=" + flashCache, 720, 320); // flashVer, getID, getSrc, getWidth, getHeight
		tempFla.addParam("quality","high");
		tempFla.addParam("wmode","transparent");
		tempFla.addParam("flashvars","sound=true&soundon=" + flashSound + "&edge=" + edgeMask + "&flvSrc=" + flvPath);
		vidCode += tempFla.buildFlashCode();
		vidCode += "<\/>";
		return vidCode;
	}
	
	function removeModalVideo() {
		// get index of modalVideoPlayer
		modalVidIndex = -1;
		for(i=0;i<flashObjects.length;i++) {
			if(flashObjects[i]) {
				if(flashObjectIDs[i] == "modalVideoPlayer") {
					flashObjectIDs[i] = null;
					flashObjects[i] = null;
				}
			}
		}
		return true;
	}
	
// Global sound system functions

	var flashObjects = new Array();
	var flashObjectIDs = new Array();
	var flashObjectsCount = 0;
	
	function registerFlashObject(srcFlash) {
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		if(isIE) {
			if(document.getElementById(srcFlash)) {
				flashObjects[flashObjectsCount] = document.getElementById(srcFlash);
			} else if(window[srcFlash]) {
				flashObjects[flashObjectsCount] = window[srcFlash];
			}
		} else {
			flashObjects[flashObjectsCount] = document[srcFlash];
		}
		// store id
		flashObjectIDs[flashObjectsCount] = srcFlash;
		if(srcFlash == "homeFeaturePanels") homeFeatureFlashObject = flashObjects[flashObjectsCount];
		if(srcFlash == "sigMoviePlayer") sigVideoFlashObject = flashObjects[flashObjectsCount];
		if(srcFlash == "swarmSoundPlayerHolder") swarmSoundPlayerObject = flashObjects[flashObjectsCount];
		flashObjectsCount += 1;
		sendFlashSound();
	}
	
	function sendFlashSound() {
		if(flashObjectsCount > 0) {
			for(i=0; i< flashObjectsCount; i++) {
				if(flashObjects[i]) flashObjects[i].setGlobalSound(flashSound);
			}
		}
	}
	
	function toggleFlashSound() {
		// toggle setting
		if(flashSound) {
			flashSound = false;
		} else {
			flashSound = true;
		}
		// update checkbox
		soundCheckbox = document.getElementById("flashSoundControlCheckbox");
		if(soundCheckbox) soundCheckbox.checked = flashSound;
		// save as cookie
		expiryDays = 60;
		var expiryDate = new Date();
		expiryDate.setTime(expiryDate.getTime()+(expiryDays*24*60*60*1000));
		expires = expiryDate.toGMTString();
		document.cookie = "flashSound=" + flashSound + "; expires=" + expires + "; path=/";
		// update all flash movies
		sendFlashSound();
	}

// -->
