﻿<!--

// 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;
	}
	
// Sig Image Movie functions

	function sigImageMovie() {
		if(flash.ver[9] && menuMovie != "" && document.getElementById("mainImage")) {
			tpMoviePlayer = new flashEmbedCode(9, "sigMoviePlayer", "\/flash\/cwoa-video-player-2012.swf?x=" + flashCache, 610, 343); // 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 stopSigVideo() {
		if(document.getElementById("sigMoviePlayer")) sigVideoFlashObject.stopVideo();
	}
	
	function hideSigImage() {
		maxVideoHeight();
		document.getElementById("mainImage").getElementsByTagName("IMG")[0].style.visibility = "hidden";
	}
	
	function showSigImage() {
		document.getElementById("mainImage").getElementsByTagName("IMG")[0].style.visibility = "visible";
	}
	
	function maxVideoHeight() {
		if($) {
			$('#mainImage').animate({height: 343}, 200);
		} else {
			document.getElementById("mainImage").style.height = 343 + "px";
		}
	}
	
	function minVideoHeight() {
		if($) {
			$('#mainImage').animate({height: 287}, 200);
		} else {
			document.getElementById("mainImage").style.height = 287 + "px";
		}
	}
	
// modal video functions

	function getModalVideoCode(flvPath) {
		vidCode = "<div class='modalVideo'>";
		tempFla = new flashEmbedCode(9, "modalVideoPlayer", "\/flash\/cwoa-modal-video-2012.swf?x=" + flashCache, 610, 343); // flashVer, getID, getSrc, getWidth, getHeight
		tempFla.addParam("quality","high");
		tempFla.addParam("wmode","transparent");
		tempFla.addParam("flashvars","sound=true&soundon=" + flashSound + "&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;
	}
	
// video jukebox functions
	
	var storeTrigger = null;
	var videoJukeboxObject;
	
	function loadVideo(getFlv,getTrigger) {
		if(storeTrigger != null) storeTrigger.className = "";
		getTrigger.className = "active";
		storeTrigger = getTrigger;
		if(videoJukeboxObject != null) videoJukeboxObject.newVideo(getFlv);
	}
	
	function videoEnded() {
		storeTrigger.className = "";
		storeTrigger = null;
	}
	
// Global sound system functions

	var flashObjects = new Array();
	var flashObjectIDs = new Array();
	var flashObjectsCount = 0;
	
	var logoFlashObject;
	var carouselFlashObject;
	var sigVideoFlashObject;
	
	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;
		// find specific swf files
		if(srcFlash == "flashHeaderLogo") logoFlashObject = flashObjects[flashObjectsCount];
		if(srcFlash == "homeFlashCarousel") carouselFlashObject = flashObjects[flashObjectsCount];
		if(srcFlash == "sigMoviePlayer") sigVideoFlashObject = flashObjects[flashObjectsCount];
		if(srcFlash == "videoJukebox") videoJukeboxObject = flashObjects[flashObjectsCount];
		// increment
		flashObjectsCount += 1;
		// update sound
		sendFlashSound();
	}
	
	function sendFlashSound() {
		if(flashObjectsCount > 0) {
			for(i=0; i< flashObjectsCount; i++) {
				if(flashObjects[i]) {
					if(flashObjectIDs[i] != "flashHeaderLogo" && flashObjectIDs[i] != "homeFlashCarousel"  && flashObjectIDs[i] != "modalVideoPlayer") 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();
	}
	
	function toggleCarousel(toggleMode) {
		if(carouselFlashObject) {
			if(toggleMode) {
				carouselFlashObject.toggleCarousel(true);
			} else {
				carouselFlashObject.toggleCarousel(false);
			}
		}
	}
	
	function toggleLogo(toggleMode) {
		if(logoFlashObject) {
			if(toggleMode) {
				logoFlashObject.toggleLogo(true);
			} else {
				logoFlashObject.toggleLogo(false);
			}
		}
	}


