// This routine traps any keystrokes, and tests for whether the navigation keys have been used.
// The left, right arrows go back, forwards.
function checkKeycode(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	// alert("keycode: " + keycode);
	current_id = parseFloat(url.substring(a+5,b))
	if (keycode == "37") 
	{
		window.location = "index" + current_id + "-" + prev_page + ".html?" + res + timeout
	}
	else if ((keycode == "39") || (keycode == "32")) 
	{
		window.location = "index" + current_id + "-" + next_page + ".html?" + res + timeout
	}
	else if (keycode == "80") 
	{
		window.location = "fullsize" + current_id + "-" + firstfullpage + ".html?" + res + timeout
	}
}
document.onkeydown = checkKeycode


// cross-browser code for getting the ID of the DIV containing the image, this is to ensure
// that the dhtml is as cross-browser as possible, even if the styles aren't.  This is used
// in the init function for locating the image.
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}


// This convoluted routine is merely to get the start/stop slideshow text to blink
// because IE does not support the blink property
blinke = ""
function blinking()
{
	if (blinke == "")
	{
		blinke = "colour"
		for (var li_item=0;li_item<document.getElementsByTagName("SPAN").length;li_item++)
		{
			if (document.getElementsByTagName("SPAN")[li_item].id=="start1")
			{
				document.getElementsByTagName("SPAN")[li_item].className="full_start"
			}
			else if (document.getElementsByTagName("SPAN")[li_item].id=="start2")
			{
				document.getElementsByTagName("SPAN")[li_item].className="full_start"
			}
//			else if (document.getElementsByTagName("SPAN")[li_item].id=="pause1")
//			{
//				document.getElementsByTagName("SPAN")[li_item].className="full_stop"
//			}
//			else if (document.getElementsByTagName("SPAN")[li_item].id=="pause2")
//			{
//				document.getElementsByTagName("SPAN")[li_item].className="full_stop"
//			}
		}
	}
	else	
	{
		blinke = ""
		for (var li_item=0;li_item<document.getElementsByTagName("SPAN").length;li_item++)
		{
			if (document.getElementsByTagName("SPAN")[li_item].id=="start1")
			{
				document.getElementsByTagName("SPAN")[li_item].className="full_whyte"
			}
			else if (document.getElementsByTagName("SPAN")[li_item].id=="start2")
			{
				document.getElementsByTagName("SPAN")[li_item].className="full_whyte"
			}
//			else if (document.getElementsByTagName("SPAN")[li_item].id=="pause1")
//			{
//				document.getElementsByTagName("SPAN")[li_item].className="full_whyte"
//			}
//			else if (document.getElementsByTagName("SPAN")[li_item].id=="pause2")
//			{
//				document.getElementsByTagName("SPAN")[li_item].className="full_whyte"
//			}
		}
	}
}
window.setInterval("blinking()", 900)

//  This function is intended to vertically size the thin vertical margin that runs along the 
//  right hand edge of the left hand menu bar.
function resize_window() 
{
	document.getElementById('nav_frame').style.height = totalheight - 80 - 170 - 5 + 'px'
	document.getElementById('index_left_margin').style.height = totalheight - 80 - 5 + 'px'
	document.getElementById('index_banner').style.width = windowwidth - scroll_width_fudge - 20 + 'px'
	document.getElementById('index_content_holder').style.width = windowwidth - left_margin - scroll_width_fudge - 10 + 'px'
	document.getElementById('index_content').style.width = windowwidth - scroll_width_fudge - left_margin - 10 + 'px'

	// Size the thumbnail boxes so that as may as possible fit across the page and are evenly spaced
	// Contentwidth is used later as the width for the overall container for all the thumbnails
	contentwidth = windowwidth - scroll_width_fudge - left_margin - 15
	// Work out how many thumbs can fit in the alloted space, but max of 5
	numberofthumbs = Math.floor(contentwidth / 160)
	if (numberofthumbs > 5)
	{
		numberofthumbs = 5
	}
	// Work out how much space to give to each thumb so that they are more or less evenly spaced
	thumbwidth = Math.floor((contentwidth - 2) / numberofthumbs)
 
	var thumlis=document.getElementsByTagName? document.getElementsByTagName('div') : document.all.tags('div')
	for (var i_tem = 0; i_tem < thumlis.length; i_tem++)
		if (thumlis[i_tem].className=='index_thmholder')
		{
			thumlis[i_tem].style.width=thumbwidth + 'px'
		}

	setTimeout("resize_window()", 10);
}


//Optional persistence feature from dynamicdrive.com
function get_cookie(Name) {
	//Get cookie routine by Shelley Powers 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) 
		{
			offset += search.length
    		// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}
function set_cookie(cookieName,cookieValue,nDays) {
	if (cookieName==="fp_scroll") cookieValue = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=0;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	if (nDays == 0)
	{
		document.cookie = cookieName+"="+escape(cookieValue)+";path=/;";
	}
	else
	{
		document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString()+";path=/;";
	}
}


// This function is called from the "body tag onload action" to do a range of things 
// that need to be done last
function init()
{
	//set_dimensions()
	//resize_window()

	//preload next image, previously defined
	if ((loadNext.length > 0) && (loadNext.indexOf('<#') == -1))
	{
	  nextimage.src = loadNexxt;
	}
	
}

// This function simply pops up the instructions window
function instruct()
{
	instructions=window.open('instructions.html','instructions','width=600,height=450,location=no,menubar=no,scrollbars=yes,resizable=yes,status=no,toolbar=no')
}

