<!-- COMMON FUNCTIONS -->

	var currentContent;
	
	function setContentDisplay(getElement,getMode) {
		if(getElement) {
			if(getMode) {
				// SHOW element
				// Spry
				Spry.Effect.DoFade(getElement, {duration: 500, from: 0, to: 100, toggle: false, finish: function() {refreshIeContent(getElement);} });
				// display
				getElement.style.display = "block";
			} else {
				// HIDE element
				// Spry
				Spry.Effect.DoFade(getElement, {duration: 0, from: 100, to: 0, toggle: false});
				// display
				getElement.style.display = "none";
			}
		}
	}
	
	function refreshIeContent(getElement) {
		// fix for ie cleartype rendering
		if(navigator.appName == 'Microsoft Internet Explorer') getElement.style.removeAttribute('filter');
	}
	
	function doSoundFX() {
		// plays bell tree sound effect
		if (flash.ver[8]) {
			document.getElementById("soundFX").innerHTML = embedFlashMovie("\/olivermoon\/flash\/sound_effect.swf?fx=1",1,1,true,0);
		}
	}
	
	function killSoundFX() {
		document.getElementById("soundFX").innerHTML = " ";
	}
	
	function initSoundFX() {
		// cache sound fx flash movie by loading it at start, but not triggering sound
		if (flash.ver[8]) document.getElementById("soundFX").innerHTML = embedFlashMovie("\/olivermoon\/flash\/sound_effect.swf?fx=0",1,1,true,0);
	}
	
	function castSpell() {
		// function called by clicking on side oliver flash movie
		if(document.getElementById("scrollPanelContent")) {
			// increment scroll content
			if(currentContent < contentCount) changeScrollContent(currentContent + 1)
			else changeScrollContent(1);
		}
	}
	

<!-- SCROLL PANEL + MENU PANEL FUNCTIONS -->

	function setupMenuPanel() {
		// count number of links in menu
		menuCount = document.getElementById("sideMenu").getElementsByTagName("dd").length;
		// add behaviours
		if(menuCount > 0) {
			for(i=0;i<menuCount;i++) {
				if(i==0) {
					document.getElementById("sideMenu").getElementsByTagName("dd")[i].className = "menuOn";
				} else {
					document.getElementById("sideMenu").getElementsByTagName("dd")[i].className = "";
				}
				document.getElementById("sideMenu").getElementsByTagName("dd")[i].getElementsByTagName("A")[0].href = "javascript:changeScrollContent(" + (i+1) + ")";
			}
		}
		
	}
	
	function hideScrollContent() {
		currentContent = 1;
		// count number of H2s = number of areas
		contentCount = document.getElementById("scrollPanelContent").getElementsByTagName("H2").length;
		// hide all but first area
		if(contentCount > 1) {
			for(i=2;i<=contentCount;i++) {
				// hide
				setContentDisplay(document.getElementById("scrollContent" + i),false);
			}
		}
	}
	
	function updateSideMenu(getIndex) {
		// change class of previous active button
		document.getElementById("sideMenu").getElementsByTagName("dd")[currentContent-1].className = "";
		// turn on new menu
		document.getElementById("sideMenu").getElementsByTagName("dd")[getIndex-1].className = "menuOn";
		// save current content
		currentContent = getIndex;
	}
	
	function updateScrollContent(getIndex) {
		// hide old area
		setContentDisplay(document.getElementById("scrollContent" + currentContent),false);
		// show new area
		setContentDisplay(document.getElementById("scrollContent" + getIndex),true);
	}
	
	function changeScrollContent(getIndex) {
		if(getIndex != currentContent) {
			// change content
			updateScrollContent(getIndex);
			// sound
			doSoundFX();
			// change button
			updateSideMenu(getIndex);
		}
	}
	
	
<!-- FAMILY FUNCTIONS -->
	
	function hideFamilyContent() {
		currentContent = 1;
		// count number of H2s = number of areas
		contentCount = document.getElementById("familyContent").getElementsByTagName("H2").length;
		// hide all
		if(contentCount > 1) {
			for(i=2;i<=contentCount;i++) {
				// hide
				setContentDisplay(document.getElementById("familyContent" + i),false);
			}
		}
	}
	
	function updateFamilyContent(getIndex) {
		if(currentContent > 0) {
			// hide old area
			setContentDisplay(document.getElementById("familyContent" + currentContent),false);
		}
		// show new area
		setContentDisplay(document.getElementById("familyContent" + getIndex),true);
		// save current content
		currentContent = getIndex;
	}
	
	function changeFamilyContent(getIndex, returnMode) {
		if(getIndex != currentContent) {
			updateFamilyContent(getIndex);
			// sound
			doSoundFX();
		}
		if(returnMode) return false;
	}
	
	
<!-- BOOK FUNCTIONS -->
	
	function hideBooksContent() {
		currentContent = 0;
		// hide all content
		if(bookCount > 1) {
			for(i=1;i<=bookCount;i++) {
				// hide
				setContentDisplay(document.getElementById("book" + i),false);
			}
		}
	}
	
	function updateBooksContent(getIndex) {
		if(currentContent > 0) {
			// hide old area
			setContentDisplay(document.getElementById("book" + currentContent),false);
		}
		// show new area
		setContentDisplay(document.getElementById("book" + getIndex),true);
		// save current content
		currentContent = getIndex;
		// turn off zoomed thumbnail
		clearActive();
		// sound
		doSoundFX();
	}
	
	function changeBooksContent(getIndex) {
		if(getIndex != currentContent) {
			updateBooksContent(getIndex);
		}
	}
	
	var popCounter = 1;
	
	function extractPopUp(linkTag) {
		winWidth = 500;
		winHeight = 500;
		windowName = "popup" + popCounter;
		popCounter += 1;
		window.open(linkTag.href,windowName,'resizable=yes,scrollbars=yes,width='+winWidth+',height='+winHeight);
		doSoundFX();
		return false;
	}
	
	
	
	
	
	
	
	
	
	