//-----------------------------------------------------------------------
// set up image cache for Online Menu images
	if (document.images) {
		var mnuImagesNormal = new Array();
		mnuImagesNormal["online"] = new Image(25, 62);
		mnuImagesNormal["online"].src = "images/online_mnu_normal.png";
		mnuImagesNormal["home"] = new Image(25, 64);
		mnuImagesNormal["home"].src = "images/home_normal.png";
		mnuImagesNormal["prize"] = new Image(25, 95);
		mnuImagesNormal["prize"].src = "images/prize2009_normal.png";
		mnuImagesNormal["results"] = new Image(25, 70);
		mnuImagesNormal["results"].src = "images/results_normal.png";
		mnuImagesNormal["introduction"] = new Image(20, 95);
		mnuImagesNormal["introduction"].src = "images/sub_introduction_normal.png";
		mnuImagesNormal["enter"] = new Image(20, 95);
		mnuImagesNormal["enter"].src = "images/sub_enter_normal.png";
		mnuImagesNormal["rules"] = new Image(20, 95);
		mnuImagesNormal["rules"].src = "images/sub_rules_normal.png";
		mnuImagesNormal["judging"] = new Image(20, 95);
		mnuImagesNormal["judging"].src = "images/sub_judging_normal.png";
	
		var mnuImagesOver = new Array();
		mnuImagesOver["online"] = new Image(25, 62);
		mnuImagesOver["online"].src = "images/online_mnu_highlighted.png";
		mnuImagesOver["home"] = new Image(25, 64);
		mnuImagesOver["home"].src = "images/home_highlighted.png";
		mnuImagesOver["prize"] = new Image(25, 95);
		mnuImagesOver["prize"].src = "images/prize2009_highlighted.png";
		mnuImagesOver["results"] = new Image(25, 70);
		mnuImagesOver["results"].src = "images/results_highlighted.png";
		mnuImagesOver["introduction"] = new Image(20, 95);
		mnuImagesOver["introduction"].src = "images/sub_introduction_highlighted.png";
		mnuImagesOver["enter"] = new Image(20, 95);
		mnuImagesOver["enter"].src = "images/sub_enter_highlighted.png";
		mnuImagesOver["rules"] = new Image(20, 95);
		mnuImagesOver["rules"].src = "images/sub_rules_highlighted.png";
		mnuImagesOver["judging"] = new Image(20, 95);
		mnuImagesOver["judging"].src = "images/sub_judging_highlighted.png";

	}
// function to swap images - used anywhere in the page			
	function setImage(imgName, type) {
		if (document.images) {	
			if (type == "Over") {
				document.images[imgName].src = mnuImagesOver[imgName].src;
				return true;
			}else if (type == "Normal") {
				document.images[imgName].src = mnuImagesNormal[imgName].src;
				return true;
			}
		}
		return false;
	}


//------------------------------------------------------------------------
// Set up Array to hold the 'href' links for each of the menu options
var menuLinks = new Array;
menuLinks[menuLinks.length] = {item:"Home", linkTo:"index.html"};
menuLinks[menuLinks.length] = {item:"Events", linkTo:"events.html"};
menuLinks[menuLinks.length] = {item:"Tips", linkTo:"tips.html"};
menuLinks[menuLinks.length] = {item:"Contact Us", linkTo:"http://www.writing-competition.co.uk/online/contactus.php"};
menuLinks[menuLinks.length] = {item:"About Us", linkTo:"aboutus.html"};
menuLinks[menuLinks.length] = {item:"Links", linkTo:"links.html"};

menuLinks[menuLinks.length] = {item:"Intro", linkTo:"introduction.html"};
menuLinks[menuLinks.length] = {item:"Entry", linkTo:"entryform.html"};
menuLinks[menuLinks.length] = {item:"Rules", linkTo:"http://www.writing-competition.co.uk/rules.html"};
menuLinks[menuLinks.length] = {item:"Judges", linkTo:"judges.html"};

menuLinks[menuLinks.length] = {item:"Int", linkTo:"playintroduction.html"};
menuLinks[menuLinks.length] = {item:"Form", linkTo:"playentryform.html"};
menuLinks[menuLinks.length] = {item:"PlayRules", linkTo:"playrules.html"};
menuLinks[menuLinks.length] = {item:"PlayJudge", linkTo:"playjudges.html"};

menuLinks[menuLinks.length] = {item:"P2005", linkTo:"p2005results.html"};
menuLinks[menuLinks.length] = {item:"P2006", linkTo:"p2006results.html"};
menuLinks[menuLinks.length] = {item:"Play2006", linkTo:"play2006results.html"};

menuLinks[menuLinks.length] = {item:"mgsite", linkTo:"http://www.margaret-graham.com"};


// set up Hash table to link menuLinks[item] to menuLinks[index]

for (var i = 0; i < menuLinks.length; i++){
	menuLinks[menuLinks[i].item] = menuLinks[i];
}
//------------------------------------------------------------------------
var pageLinks = new Array;
pageLinks[pageLinks.length] = {item:"rules", linkTo:"rules.html"};
pageLinks[pageLinks.length] = {item:"contact", linkTo:"./online/contactus.php"};
pageLinks[pageLinks.length] = {item:"help", linkTo:"help.html"};
pageLinks[pageLinks.length] = {item:"online", linkTo:"online_info.html"};
pageLinks[pageLinks.length] = {item:"courses", linkTo:"courses_info.html"};
pageLinks[pageLinks.length] = {item:"links", linkTo:"links.html"};
pageLinks[pageLinks.length] = {item:"local_prize", linkTo:"local_prize.html"};

// set up Hash table to link pageLinks[item] to pageLinks[index]

for (var i = 0; i < pageLinks.length; i++){
	pageLinks[pageLinks[i].item] = pageLinks[i];
}
//------------------------------------------------------------------------

// Set up array to hold 'href' links to the Results pages
// will be used by the resultsPage() function
var resultsAddress = new Array;
resultsAddress[resultsAddress.length] = {item:"Novel", linkTo:"2005novel.html"};
resultsAddress[resultsAddress.length] = {item:"Genre", linkTo:"2005genre.html"};
resultsAddress[resultsAddress.length] = {item:"NonGenre", linkTo:"2005nongenre.html"};
resultsAddress[resultsAddress.length] = {item:"06Novel", linkTo:"2006novel.html"};
resultsAddress[resultsAddress.length] = {item:"06ShortStory", linkTo:"2006short.html"};
resultsAddress[resultsAddress.length] = {item:"06Poetry", linkTo:"2006poetry.html"};
resultsAddress[resultsAddress.length] = {item:"06StagePlay", linkTo:"play2006details.html"};
resultsAddress[resultsAddress.length] = {item:"06PlayDetails", linkTo:"play2006performancedetail.html"};
resultsAddress[resultsAddress.length] = {item:"07MannBooker", linkTo:"2007MannBooker.html"};
resultsAddress[resultsAddress.length] = {item:"07SophieGrigson", linkTo:"2007FoodFestival.html"};
resultsAddress[resultsAddress.length] = {item:"07Ramsey", linkTo:"2007Ramsey.html"};
resultsAddress[resultsAddress.length] = {item:"07WiddecombeLunch", linkTo:"2007WiddecombeLunch.html"};
resultsAddress[resultsAddress.length] = {item:"07EntryForm", linkTo:"printable_entryform.html"};
resultsAddress[resultsAddress.length] = {item:"07pdf", linkTo:"webentryform2007.pdf"};
resultsAddress[resultsAddress.length] = {item:"previousTips", linkTo:"previousTips.html"};
resultsAddress[resultsAddress.length] = {item:"playreview", linkTo:"play2006review.html"};
resultsAddress[resultsAddress.length] = {item:"bookerreview", linkTo:"2007MannBookerReview.html"};

// set up Hash table to link resultsAddress[item] to resultsAddress[index]

for (var i = 0; i < resultsAddress.length; i++){
	resultsAddress[resultsAddress[i].item] = resultsAddress[i];
}


//------------------------------------------------------------------------
function menuItemOn(elem_id) {
	var item = document.getElementById(elem_id);
	if (elem_id != 'online'){
		item.style.color ="#4040FF";
	}else{
		item.style.color ="#aa0000";
	}
	item.style.textDecoration = "underline";
	item.style.backgroundColor = "#FFFFFF";
}
function menuItemOff(elem_id) {
	var item = document.getElementById(elem_id);
	if (elem_id != 'online'){
		item.style.color ="#FFFFFF";
	}else{
		item.style.color ="#ffe14d";
	}
	item.style.backgroundColor = "#9999ff";
	item.style.textDecoration = "none";
}

function submenuItemOn(elem_id) {
	var item = document.getElementById(elem_id);
	item.style.backgroundColor="#a3b3ed";
	item.style.color ="#FFFFFF";
	item.style.textDecoration = "underline";
	item.style.borderTop = "solid #525eaa 1px";
	item.style.borderLeft = "solid #525eaa 1px";
	item.style.borderBottom = "solid #D8D9F6 1px";
	item.style.borderRight = "solid #D8D9F6 1px";
}
function submenuItemOff(elem_id) {
	var item = document.getElementById(elem_id);
	item.style.backgroundColor="#ffffd0";
	item.style.color ="#0000C0";
	item.style.textDecoration = "none";
	item.style.borderTop = "solid #FFFFd6 1px";
	item.style.borderLeft = "solid #FFFFd6 1px";
	item.style.borderBottom = "solid #bdbb00 1px";
	item.style.borderRight = "solid #bdbb00 1px";
}
function eventMenuOn(elem_id){
	var item = document.getElementById(elem_id);
	item.style.backgroundColor="#C0FFC0";
	item.style.color ="#000080";
	item.style.borderTop = "solid #C0C0C0 1px";
	item.style.borderLeft = "solid #C0C0C0 1px";
	item.style.borderBottom = "solid #D8D9F6 1px";
	item.style.borderRight = "solid #D8D9F6 1px";
}
function eventMenuOff(elem_id){
	var item = document.getElementById(elem_id);
	item.style.backgroundColor="#EBECFF";
	item.style.color ="#6466A4";
	item.style.borderTop = "solid #FFFFFF 1px";
	item.style.borderLeft = "solid #FFFFFF 1px";
	item.style.borderBottom = "solid #C0C0C0 1px";
	item.style.borderRight = "solid #C0C0C0 1px";
}
function setMenu(elem_id) {
	var item = document.getElementById(elem_id);
	item.style.color ="#4040FF";
	item.style.backgroundColor = "#ffffff";
	item.style.textDecoration = "underline";
	
}
function clearMenu(elem_id){
	var item = document.getElementById(elem_id);
	item.style.color ="#FFFFFF";
	item.style.backgroundColor = "#9999ff";
	item.style.textDecoration = "none";
}
function show_menu(menu_id) {
	var mnu = "";
	if(menu_id == "pop1"){
		mnu = "Prize";
	}else if(menu_id == "pop3"){
		mnu = "Results";
	}
	// get position of the calling element
	var calling_mnu = document.getElementById(mnu);
	var mnuLeft = 0;
	var mnuTop = 0;
	var mnuHeight = calling_mnu.offsetHeight;
	while(calling_mnu){
		mnuLeft += calling_mnu.offsetLeft;
		mnuTop += calling_mnu.offsetTop;
		calling_mnu = calling_mnu.offsetParent;
	}
	var subLeft = mnuLeft + 10;
	var subTop = mnuTop + mnuHeight - 2;
	var sub = document.getElementById(menu_id);
	sub.style.left = subLeft;
	sub.style.top = subTop;
	sub.style.visibility="visible";
}
function hide_menu(menu_id) {
	document.getElementById(menu_id).style.visibility="hidden";
}
//--------------------------------------------------------------

// function to manage the links to other pages
function linkTo(id){
	location.href = menuLinks[id].linkTo;
}


//function to open a new window for the 'results' pages
var resultWindow;
function resultsPage(address, width, height){
	var ref = resultsAddress[address].linkTo;
	var title = resultsAddress[address].item; 
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var winFeatures = "width=" + width + ",height=" + height + ",status,scrollbars,resizable,left=" + 
					left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
	resultWindow = window.open(ref, title, winFeatures);
}
//function to open a new window for the printer friendly Entry Form page
var formWindow;
function entryForm(address, width, height){
	var ref = resultsAddress[address].linkTo;
	var title = resultsAddress[address].item; 
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var winFeatures = "width=" + width + ",height=" + height + ",menubar,toolbar,status,scrollbars,resizable,left=" + 
					left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
	formWindow = window.open(ref, title, winFeatures);
}
//function to open a new window for various pages
var pageWindow;
function showPage(addr, width, height){
	var ref = pageLinks[addr].linkTo;
	var title = pageLinks[addr].item; 
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2) - 50);
	var winFeatures = "width=" + width + ",height=" + height + ",menubar,toolbar,status,scrollbars,resizable,left=" + 
					left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
	pageWindow = window.open(ref, title, winFeatures);
}
function entryMenuOn(elem_id){
	var item = document.getElementById(elem_id);
	item.style.backgroundColor="#C0FFC0";
	item.style.color ="#000080";
	item.style.borderTop = "solid #C0C0C0 1px";
	item.style.borderLeft = "solid #C0C0C0 1px";
	item.style.borderBottom = "solid #D8D9F6 1px";
	item.style.borderRight = "solid #D8D9F6 1px";
}
function entryMenuOff(elem_id){
	var item = document.getElementById(elem_id);
	item.style.backgroundColor="#EBECFF";
	item.style.color ="#000099";
	item.style.borderTop = "solid #FFFFFF 1px";
	item.style.borderLeft = "solid #FFFFFF 1px";
	item.style.borderBottom = "solid #C0C0C0 1px";
	item.style.borderRight = "solid #C0C0C0 1px";
}

function showImageDiv(elem_id){
	var item = document.getElementById(elem_id);
	item.style.visibility = "visible";
}
function hideImageDiv(elem_id){
	var item = document.getElementById(elem_id);
	item.style.visibility = "hidden";
}

//--------------------------------------------------------------

//--------------------------------------------------------------

/* Functions below used to manage positioning of elements	*/
//--------------------------------------------------------------

// Convert object name string or object reference into a valid element object reference
function getRawObject(obj){
	var theObj;
	if (typeof obj == "string"){
		if (isW3C){
			theObj = document.getElementById(obj);
		} else if (isIE4){
			theObj = document.all(obj);
		} else if (isNN4){
			theObj = seekLayer(document, obj);
		}
	} else {
		// pass through element object reference
		theObj = obj;
	}
	return theObj;
}
//------------------------------------------------------------
// Retrieve the x coordinate of a positionable Object
function getObjectLeft(obj){
	var elem = getRawObject(obj);
	var result = 0;
	if (document.defaultView){
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(elem, "");
		result = cssDec1.getPropertyValue("left");
	}else if (elem.currentStyle){
		result = elem.currentStyle.left;
	}else if (elem.style){
		result = elem.style.left;
	}else if (isNN4){
		result = elem.left;
	}
	return parseInt(result);
}
//-----------------------------------------------------------
//Retrieve the y coordinate of a positionable Object
function getObjectTop(obj){
	var elem = getRawObject(obj);
	var result = 0;
	if (document.defaultView){
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(elem, "");
		result = cssDec1.getPropertyValue("top");
	}else if (elem.currentStyle){
		result = elem.currentStyle.top;
	}else if (elem.style){
		result = elem.style.top;
	}else if (isNN4){
		result = elem.top;
	}
	return parseInt(result);
}
//---------------------------------------------------------------
// Return the available content width space in the browser window
function getInsideWindowWidth(){
	if (window.innerWidth){
		return window.innerWidth;
	}else if (isIE6CSS){
		//measure the html element's clientWidth
		return document.body.parentElement.clientWidth;
	}else if (document.body && document.body.clientWidth){
		return document.body.clientWidth;
	}
	return 0;
}
//----------------------------------------------------------------
// Return the available content height space in the browser window
function getInsideWindowHeight(){
	if (window.innerHeight){
		return window.innerHeight;
	}else if (isIE6CSS){
		//measure the html element's clientHeight
		return document.body.parentElement.clientHeight;
	}else if (document.body && document.body.clientHeight){
		return document.body.clientHeight;
	}
	return 0;
}
//---------------------------------------------------------------
// Set flags for browser compatibility
function setFlags() {
	if(document.images){
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isNN4 = (document.layers) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	}
}

//-----------------------------------------------------------------------
// get the available space for the element passed and adjust top position
// to position it in the window

function showDiv(elem,divTgt,divHt){
	//------------------------------------------------------------------
	var buttonHt = 25;

	// call setFlags to create correct instance of flags
	setFlags();
	var e = document.getElementById(divTgt);
	var availHeight = getInsideWindowHeight();
	var offY;
	if (isIE6CSS){
		offY = document.body.parentNode.scrollTop;
	}else{
		offY = document.body.scrollTop;
	}
	var elemTop = getObjectTop(elem) + buttonHt;		//elem is the 'calling' element
	var winHead = elemTop - offY;
	var divSpace = availHeight - winHead;
	var divTop = elemTop;
	var gap = divSpace - divHt;
	if (gap < 0){
		divTop += gap;
	}else{
		divTop = elemTop;
	}
	//--------------------------------------------------------------------
	var myDiv = getRawObject(divTgt);
	if (document.defaultView){
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(myDiv, "");
		cssDec1.getPropertyValue("top") = divTop;
	}else if (myDiv.currentStyle){
		myDiv.style.top = divTop;
	}else if (myDiv.style){
		myDiv.style.top = divTop;
	}else if (isNN4){
		myDiv.top = divTop;
	}
	e.style.visibility = "visible";
}

function hideDiv(elem){
	var e = document.getElementById(elem);
	e.style.visibility = "hidden";
}


//-----------------------------------------------------------------------