<!--

// Set dropdown menus to inactive - onload makes them active

	var menuSystemActive = false;
	

// Set the window name

	window.name = "main";
	


// onload triggers

	function pageTrigger() {
		if(graphicVersion) {
			menuSystemActive = true;
			if(document.getElementById("coversScroller")) initCoverScroller();
			// add xmas theming
			if (xmasTheme) xmasSetup();
			
			// fix for submit forms by hitting 'return'
			inputSubmitByReturn();
			
			//addLinkTracking();
		}
	}
	
// fix for submit forms by hitting 'return'

	function addInputSubmitEvent(form, input) {
		input.onkeydown = function(e) {
			e = e || window.event;
			if (e.keyCode == 13) {
				form.submit();
				return false;
			}
		};
	}

	function inputSubmitByReturn() {
		var forms = document.getElementsByTagName('form');
		for (var i=0;i < forms.length;i++) {
			var inputs = forms[i].getElementsByTagName('input');
			for (var j=0;j < inputs.length;j++) {
				addInputSubmitEvent(forms[i], inputs[j]);
			}
		}
	}
	
// Function to track links with Google Analytics
	// see http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html for details on Event tracking
	// category (required) - The name you supply for the group of objects you want to track.
	// action (required) - A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
	// label (optional) - An optional string to provide additional dimensions to the event data.
	// value (optional) - An integer that you can use to provide numerical data about the user event.
	
	function trackLink(category,action,label,value) {
		//alert(category + " - " + action + " - " + label + " - " + value);
		if (action === undefined) action = "clicked";
		
		try { _gaq.push(['_trackEvent', category, action, label, value]); } // New Asynchronous Google tracking code for events
		catch(e) {
			try { _gaq.push(['_trackPageview', category + '/' + action]); } // revert to standard page view tracking
			catch(e) { }
		}
		
		return false;
	}


// Track links - catch outgoing links and downloads + add onclicks to track them
	//function addLinkTracking() {
//		//find links on page
//		var links = document.getElementsByTagName('a');
//		
//		for(var i = 0; i < links.length; i++) {
//			//see if it's an external link (look for http)
//			if(links[i].href != "" && links[i].href.indexOf("javascript:") == -1) {
//				
//				// if it's not an internal link
//				if(!/rhinegold(\.co\.uk|\.com|\.semantic.dev)\//.test(links[i].href)) {
//					// add onclick attributes to link for tracking
//					links[i].onclick=function(){trackLink("Outgoing Link","Clicked",this.href);};
//				} else if(links[i].href.indexOf("/downloads/") > -1) {
//					// track downloads
//					// check to see if it's a special case link
//					if(links[i].href.indexOf("/magazines_catalogue.asp?m=1&id=144/") > -1) {
//						links[i].onclick=function(){trackLink("Download","Teaching Drama",this.href);};
//					} else if(links[i].href.indexOf("/music_teacher/") > -1) {
//						links[i].onclick=function(){trackLink("Download","Music Teacher",this.href);};
//					} else {
//						links[i].onclick=function(){trackLink("Download","General",this.href);};
//					}
//				}
//			}
//			//}
//		}
//	}
		
	
// Funciton to open a pop-up window

	function openPopUp(myUrl,myWidth,myHeight) {
		window.open(myUrl, "popup", "width=" + myWidth + ",height=" + myHeight + ",left=" + ((screen.width / 2) - (myWidth / 2)) + ",top=" + ((screen.height / 2) - (myHeight / 2)) + ",status=no,scrollbars=yes,titlebar=no,toolbar=no");
		return false;
	}

// Function to check if a field string is empty
	
	function isEmptyField(srcField) {
		srcText = srcField.value;
		srcText = srcText.replace(/^\s+/g, '').replace(/\s+$/g, '');
		if(srcText == "") {
			srcField.value = "";
			return true;
		} else return false;
	}
	
// Email address validation
	
	function isValidEmail(src) {
		var emailReg = "^\\w+[\\+\\.\\w-]*@([\\w-]+\\.)*\\w+[\\w-]*\\.([A-Za-z]{2,4}|\\d+)$";
		var regex = new RegExp(emailReg);
		return regex.test(src);
	}
	
	
// Image size checking + resizing

	function checkImageSize(srcImage,maxWidth,maxHeight) {
		if(document.images) {
			getWidth = srcImage.width;
			getHeight = srcImage.height;
			if(getWidth>maxWidth || getHeight>maxHeight) {
				widthVariance = maxWidth/getWidth;
				heightVariance = maxHeight/getHeight;
				if(widthVariance<=heightVariance) scalePercentage = getWidth/maxWidth;
				else scalePercentage = getHeight/maxHeight;
				srcImage.width = getWidth/scalePercentage;
				srcImage.height = getHeight/scalePercentage;
			}
		}
	}


// Header search form stuff

	var initSearchText = "Search for...";
	
	function checkSearchField(fieldMode) {
		if(fieldMode) {
			// enters field
			if(document.getElementById("headerSearchText").value == initSearchText) document.getElementById("headerSearchText").value = "";
		} else {
			// exits field
			if(isEmptyField(document.getElementById("headerSearchText"))) document.getElementById("headerSearchText").value = initSearchText;
		}
	}

	function validateHeaderSearch() {
		if(isEmptyField(document.getElementById("headerSearchText")) || document.getElementById("headerSearchText").value == initSearchText) {
			alert("You have not entered anything to search for!");
			return false;
		} else return true;
	}
	
	function submitHeaderSearch() {
		if(validateHeaderSearch()) document.getElementById("headerSearch").submit();
	}
	
	
// Sidepanel form stuff

	function checkSubmitField(fieldElement,initValue,fieldMode) {
		if(fieldMode) {
			// enters field
			if(fieldElement.value == initValue) fieldElement.value = "";
		} else {
			// exits field
			if(isEmptyField(fieldElement)) fieldElement.value = initValue;
		}
	}


// Print function

	function printPage() {
		if(window.print) {
			window.print();
		} else {
			alert("Your browser does not support the javascript 'print' function.\nPlease use your operating system's print menu to print this page.")
		}
		return false;
	}


// Menu Stuff

	if(navigator.userAgent.indexOf("Opera")!=-1) GetBrowserType = "opera"
	else if(navigator.appName == "Microsoft Internet Explorer") GetBrowserType = "ie"
	else if(navigator.appName == "Netscape") GetBrowserType = "ns";
	
	// playstation
	if(navigator.userAgent.indexOf("PLAYSTATION 3")!=-1) GetBrowserType = "ns";
	
	safariMode = false;
	if(navigator.userAgent.indexOf("AppleWebKit")!=-1) safariMode = true;
	
	GetBrowserPlatform = "";
	if(navigator.userAgent.indexOf("Mac_PowerPC")!=-1 || navigator.userAgent.indexOf("Macintosh")!=-1) GetBrowserPlatform = "mac";
	
	storeMenuIndex = null;
	storeButtonState = null;
	storeThisElement = null;
	menuActive = false;
	menuTimeout = null;
	
	function getMenuClass(src,hoverState) {
		if(src.className.indexOf("first") > -1) {
			if(hoverState) return "firstMenuOver"
			else {
				if(storeButtonState) return "firstMenuOn"
				else return "firstMenuOff";
			}
		} else if(src.className.indexOf("last") > -1) {
			if(hoverState) return "lastMenuOver"
			else {
				if(storeButtonState) return "lastMenuOn"
				else return "lastMenuOff";
			}
		} else {
			if(hoverState) return "MenuOver"
			else {
				if(storeButtonState) return "MenuOn"
				else return "MenuOff";
			}
		}
	}
	
	function showMenu(menuIndex,buttonState,thisElement) {
		if(menuSystemActive) {
			cancelHideMenu();
			if(menuActive && menuIndex!= storeMenuIndex) doHideMenu();
			if(!menuActive) {
				storeMenuIndex = menuIndex;
				storeButtonState = buttonState;
				storeThisElement = thisElement;
				thisElement.className = getMenuClass(thisElement,true);
				
				if(SubMenuStrings[menuIndex]) {
					
					// Work out menu position
					SubMenuWidth = parseFloat(document.getElementById('DropDownMenu').offsetWidth);
					MenuOffset = parseFloat(document.getElementById('centeredPage').offsetLeft) + parseFloat(document.getElementById('menuArea').offsetLeft);
					MenuAreaWidth = parseFloat(document.getElementById('menuArea').offsetWidth);
					ButtonOffset = thisElement.offsetLeft;
					menuTop = parseFloat(document.getElementById('menuArea').offsetTop) + parseFloat(document.getElementById('menuArea').offsetHeight);
					xPos = ButtonOffset + MenuOffset - 7;
					MenuAlign = "left";
					if((ButtonOffset + SubMenuWidth) > MenuAreaWidth) {
						// Work menu position aligned right to next spacer div
						ButtonOffset = thisElement.offsetLeft + thisElement.offsetWidth;
						xPos = (ButtonOffset + MenuOffset) - (SubMenuWidth - 7);
						MenuAlign = "right";
					}
				
					// Write menu links
					buildMenu = "<div align='" + MenuAlign + "'><div id='DropDownMenuTop'></div><dl>" + SubMenuStrings[menuIndex] + "</dl></div>";
					document.getElementById('DropDownMenu').innerHTML = buildMenu;
					
					// Set position of menu + make visible
					if(GetBrowserType == "ns" || GetBrowserType == "opera") {
						document.getElementById('DropDownMenu').style.top = menuTop + "px";
						document.getElementById('DropDownMenu').style.left = xPos + "px";
					} else {
						document.getElementById('DropDownMenu').style.posTop = menuTop;
						document.getElementById('DropDownMenu').style.posLeft = xPos;
					}
					document.getElementById('DropDownMenu').style.zIndex = 100;
					document.getElementById('DropDownMenu').style.visibility = "visible";
				
				}
				menuActive = true;
			}
		}
	}
	
	function hideMenu() {
		if(menuSystemActive) {
			refreshMenu();
			menuTimeout = setTimeout("doHideMenu();",200);
		}
	}
	
	function doHideMenu() {
		if(menuSystemActive && storeThisElement != null) {
			storeThisElement.className = getMenuClass(storeThisElement,false);
			document.getElementById('DropDownMenu').style.visibility = "hidden";
			storeMenuIndex = null;
			storeButtonState = null;
			storeThisElement = null;
			menuActive = false;
		}
	}
	
	function cancelHideMenu() {
		if(menuSystemActive) {
			clearTimeout(menuTimeout);
			menuTimeout = null;
		}
	}
	
	function menuAreaClick(menuIndex,buttonState,thisElement) {
		if(menuSystemActive) {
			if(menuActive && storeThisElement == menuIndex) {
				doHideMenu();
			} else if(!menuActive) {
				showMenu(menuIndex,buttonState,thisElement);
			}
		}
	}
	
	function refreshMenu() {
		if(menuSystemActive && safariMode) document.getElementById('DropDownMenu').style.zIndex += 1;
	}


// Featured jobs panels stuff

	var featuredJobsWidth = 244;
	var featuredJobsPadding = 9;
	var maxFeaturedJobs = 3;
	var numFeaturedJobs = 0;
	var jobsPanelPanels = new Object();
	var currJobStartPanel = 1;
	var currJobAnimating = false;
	var jobArrowsVisible = false;
	var jobTimeout = null;
	
	function setupFeaturedJobs() {
		var jobsPanel = document.getElementById("featuredJobsPanel");
		if (!jobsPanel) {
			jobsPanel = document.getElementById("featuredJobs");
			featuredJobsWidth = 162;
			featuredJobsPadding = 8;
		}
		if (jobsPanel) {		
			if ($) {
				$(jobsPanel).mouseenter(function() {
					if (numFeaturedJobs > maxFeaturedJobs) {
						$("#featuredJobsLeft").show("slide", { direction: "left" }, 100);
						$("#featuredJobsRight").show("slide", { direction: "right" }, 100);
						clearTimeout(jobTimeout);
						jobArrowsVisible = true;
					}
				});
				$(jobsPanel).mouseleave(function() {
					if (numFeaturedJobs > maxFeaturedJobs) {
						$("#featuredJobsLeft").hide("slide", { direction: "left" }, 100);
						$("#featuredJobsRight").hide("slide", { direction: "right" }, 100);
						jobTimeout = setTimeout("moveFeaturedJobs(true)", 10000);
						jobArrowsVisible = false;
					}
				});
			} else {
				jobsPanel.onmouseover = function() {
					if (numFeaturedJobs > maxFeaturedJobs) {
						document.getElementById("featuredJobsLeft").style.display = "block";
						document.getElementById("featuredJobsRight").style.display = "block";
						clearTimeout(jobTimeout);
						jobArrowsVisible = true;
					}
				};
				jobsPanel.onmouseout = function() {
					if (numFeaturedJobs > maxFeaturedJobs) {
						document.getElementById("featuredJobsLeft").style.display = "none";
						document.getElementById("featuredJobsRight").style.display = "none";
						jobTimeout = setTimeout("moveFeaturedJobs(true)", 10000);
						jobArrowsVisible = false;
					}
				};
			}
			var currPanels = jobsPanel.getElementsByTagName("div");
			var panelX = 0;
			for (var i = 0; i < currPanels.length; i++) {
				if (currPanels[i].className.indexOf("threeColPanel") >= 0 || currPanels[i].className.indexOf("jobPanel") >= 0) {
					currPanels[i].style.position = "absolute"; // Make sure we can move the panels
					currPanels[i].style.margin = "0px"; // Remove all margin values
					currPanels[i].style.left = panelX.toString() + "px"; // Position panel correctly
					jobsPanelPanels[numFeaturedJobs + 1] = new Object();
					jobsPanelPanels[numFeaturedJobs + 1]['panel'] = currPanels[i];
					jobsPanelPanels[numFeaturedJobs + 1]['showing'] = (numFeaturedJobs < maxFeaturedJobs ? true : false);
					panelX += (featuredJobsWidth + featuredJobsPadding); // Move to the next panel
					numFeaturedJobs++;
				}
			}
			// Set up auto animation
			if (numFeaturedJobs > maxFeaturedJobs) jobTimeout = setTimeout("moveFeaturedJobs(true)", 4000);
		}
	}
	
	function moveFeaturedJobs(direction) {
		if (!currJobAnimating) {
			if (direction) { // Right
				
				// Work out which panel is next in line
				var nextPanel = currJobStartPanel + maxFeaturedJobs;
				if (nextPanel > numFeaturedJobs) nextPanel = (nextPanel - numFeaturedJobs);
				// Move the next panel into position
				currJobAnimating = true;
				jobsPanelPanels[nextPanel]['panel'].style.left = ((featuredJobsWidth + featuredJobsPadding) * maxFeaturedJobs).toString() + "px";
				for (var i = 1; i < (numFeaturedJobs + 1); i++) {
					if ($) {
						$(jobsPanelPanels[i]['panel']).animate({ "left": "-=" + (featuredJobsWidth + featuredJobsPadding).toString() + "px" }, 500, "swing", function() { currJobAnimating = false; });
					} else {
						jobsPanelPanels[i]['panel'].style.left = (jobsPanelPanels[i]['panel'].offsetLeft - (featuredJobsWidth + featuredJobsPadding)).toString() + "px";
						currJobAnimating = false;
					}
				}
				currJobStartPanel++;
				if (currJobStartPanel > numFeaturedJobs) currJobStartPanel = 1;
				
				// Re-initiate timeout
				if (!jobArrowsVisible) jobTimeout = setTimeout("moveFeaturedJobs(true)", 4000);
				
			} else { // Left
				
				// Work out which panel is next in line
				var nextPanel = currJobStartPanel - 1;
				if (nextPanel < 1) nextPanel = numFeaturedJobs;
				// Move the next panel into position
				currJobAnimating = true;
				jobsPanelPanels[nextPanel]['panel'].style.left = (0 - (featuredJobsWidth + featuredJobsPadding)).toString() + "px";
				for (var i = 1; i < (numFeaturedJobs + 1); i++) {
					if ($) {
						$(jobsPanelPanels[i]['panel']).animate({ "left": "+=" + (featuredJobsWidth + featuredJobsPadding).toString() + "px" }, 500, "swing", function() { currJobAnimating = false; });
					} else {
						jobsPanelPanels[i]['panel'].style.left = (jobsPanelPanels[i]['panel'].offsetLeft - (featuredJobsWidth + featuredJobsPadding)).toString() + "px";
						currJobAnimating = false;
					}
				}
				currJobStartPanel--;
				if (currJobStartPanel < 1) currJobStartPanel = numFeaturedJobs;
				
				// Re-initiate timeout
				if (!jobArrowsVisible) jobTimeout = setTimeout("moveFeaturedJobs(true)", 4000);
				
			}
		}
	}
	
// -->
