﻿<!--

// 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 ";
		// 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 flashMenuH2s() {
		if(flash.ver[9]) {
			if(document.getElementById("dynamicMenu").getElementsByTagName("H2").length > 0) {
				var allMenuTitles = document.getElementById("dynamicMenu").getElementsByTagName("H2");
				for(i=0;i<allMenuTitles.length;i++) {
					// work out which flash movie to use from body class
					getText = getTrimmedTextContent(allMenuTitles[i]);
					getTextHTML = allMenuTitles[i].innerHTML;
					allMenuTitles[i].innerHTML = "<span class='submenuFlashH2'>";
					tempFLA = new flashEmbedCode(9, ("submenuTitle" + i), "\/flash\/submenu-h2.swf", 170, 26); // flashVer, getID, getSrc, getWidth, getHeight
					tempFLA.addParam("quality","high");
					tempFLA.addParam("wmode","transparent");
					tempFLA.addParam("flashvars","txt=" + escape(getText));
					allMenuTitles[i].innerHTML = tempFLA.buildFlashCode() + "<\/span><span class='hidden'>" + getTextHTML + "<\/span>";
					tempFLA = null;
				}
			}
		}
	}
	
	function flashH1() {
		if(document.getElementsByTagName("H1").length > 0) {
			if(flash.ver[9]) {
				// work out which flash movie to use from body class
				getH1 = document.getElementsByTagName("H1")[0];
				getText = getTrimmedTextContent(getH1).toUpperCase();
				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;
			}
			document.getElementsByTagName("H1")[0].style.visibility = "visible";
		}
	}
	
// Sig Image Movie functions

	function sigImageMovie() {
		if(flash.ver[9] && menuMovie != "") {
			tpMoviePlayer = new flashEmbedCode(9, "sigMoviePlayer", "\/flash\/thorpe-video-player.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.getElementById("mainImage").innerHTML += tpMoviePlayer.buildFlashCode();
			
		}
	}
	
	function hideSigImage() {
		document.getElementById("mainImage").getElementsByTagName("IMG")[0].style.visibility = "hidden";
	}
	
	function showSigImage() {
		document.getElementById("mainImage").getElementsByTagName("IMG")[0].style.visibility = "visible";
	}
	
// Global sound system functions

	var flashObjects = new Array();
	var flashObjectsCount = 0;
	
	function registerFlashObject(srcFlash) {
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		flashObjects[flashObjectsCount] = (isIE) ? window[srcFlash] : document[srcFlash];
		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();
	}