// Some features require Javascript 1.2 or higher so the include script function should specify
// language="JavaScript1.2" type="text/javascript" as well as src="epopop.js

// Browser check function to write warnings into the web page when placed within a <script type="text/javascript"> tag

function browser_caution() {
var browser = navigator.appName;
var version = navigator.appVersion;
// Check JavaScript supports resizing of windows - version 1.2 or higher
if (!window.resizeTo) { document.write('<font color="#FF0000">Unfortunately you are running  a browser identifying itself as ' + browser + ' version ' + version + ' which does not seem to support the JavaScript which would provide the Popup images when you click on the thumbnails on this page.</font>') }
if (navigator.cookieEnabled == false) { 
document.write('<font color="#FF0000">Unfortunately you seem to have disabled Cookies in your browser and this means you will not be able to change the size of the popups used for pictures.</font>') 
 }
// if ( (navigator.userAgent.indexOf("MSIE") != -1) && (navigator.userAgent.indexOf("Mac") != -1) ) {document.write('<font size="+1" color="#FF0000"><b>Caution: Apple Users<\/b> - Please do not close Popup Windows containing the larger images you get by clicking on icons, they will be closed automatically when you leave this page. If you close them you may need to refresh the page.<\/font><p>') }
}

// Identification of specific browsers

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
// var is_epiphany = navigator.userAgent.toLowerCase().indexOf('epiphany') > -1;
// var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

// Routine for popup windows with title, size and background colour parameter (5 parameters)

var newwindow;
var wheight = 0, wwidth = 0;

function popitup5(url, title, iwidth, iheight, colour) {
var pwidth, pheight;

if ( !newwindow || newwindow.closed ) {
	pwidth=iwidth+30;
	pheight=iheight+30;
	newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=yes,top=50,left=10,status=no,location=no');
	wheight=iheight;
	wwidth=iwidth;
}

if (wheight!=iheight || wwidth!=iwidth ) {
	pwidth=iwidth+30;
	pheight=iheight+70;
//	The resizeTo needs Javascript 1.2 or higher so the include for this javascript file should specify language="JavaScript1.2" 
	if (window.resizeTo) newwindow.resizeTo(pwidth, pheight);
wheight=iheight;
wwidth=iwidth;
}

newwindow.document.clear();
newwindow.document.writeln('<html> <head> <title>' + title + ' <\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
newwindow.document.writeln('<img src=' + url + '  title=\"' + title + '\"   alt=\"' + title + '\" >');
newwindow.document.writeln('<\/center> <\/body> <\/html>');
newwindow.document.close();

if (is_chrome) {newwindow.parent.blur();}

newwindow.focus();
}

//Routines used specifically for popup feedback form windows

var fbwindow
function fbpopitup(url) {
if (fbwindow && !fbwindow.closed) 
	{ fbwindow.location.href = url; fbwindow.focus(); } 
else 
	{ fbwindow=window.open(url,'fhtmlname','width=520,height=420,resizable=1,scrollbars=1,top=50,left=10'); }
}

//Routines to tidy up popup windows when page is left

function tidy() {tidy5() }
function tidy5() {
tidyh();
fbtidy();
}

function tidyh() {
if (newwindow && !newwindow.closed) { newwindow.close(); }
}

function fbtidy(){
if (fbwindow && !fbwindow.closed) {fbwindow.close(); } }	

//routines to simulate functions used on older pages. 

function popitup(url) { popitup5(url , 'Digital Image 384x288 &copy; P Curtis', 384, 288, 'white') }
function ppopitup(url) { popitup5(url , 'Photographic Image 400x267 &copy; P Curtis',400, 267, 'white') }

function vpopitup(url) { popitup5(url , 'Digital Image 288x384 &copy; P Curtis', 288,384, 'white') }
function pvpopitup(url) { popitup5(url , 'Photographic Image 267x400 &copy; P Curtis', 267, 400, 'white') }


//Routines for cookies used to remember if user has broadband

/* Call function as setCookie("cookiename" , cookievalue, lifetime, cookiepath)
with the lifetime required in days, -1 to delete a cookie or zero
for a temporary cookie. The Cookie Path is optional.*/

function setCookie(cookie_name, cookie_value, cookie_life, cookie_path) {
  var today = new Date()
  var expiry = new Date(today.getTime() + cookie_life * 24*60*60*1000)
  if (cookie_value != null && cookie_value != ""){
    var cookie_string =cookie_name + "=" + escape(cookie_value)
    if(cookie_life){ cookie_string += "; expires=" + expiry.toGMTString()}
    if(cookie_path){ cookie_string += "; path=" + cookie_path}
	document.cookie = cookie_string
  }
} // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->

/* Call function as getCookie("cookiename") It returns the value of a cookie
if set or null. Beware of potential ambiguities in names of cookies -
getCookie is simple and will match the end of a string so xyname 
will also be matched by yname and ame. */
 
function getCookie(name) {
  var index = document.cookie.indexOf(name + "=")
  if (index == -1) { return "undefined"}
  index = document.cookie.indexOf("=", index) + 1
  var end_string = document.cookie.indexOf(";", index)
  if (end_string == -1) { end_string = document.cookie.length }
  return unescape(document.cookie.substring(index, end_string))
} // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->

// Set broadband true provided the screen resolution is sufficient for the larger popups 

var default_broadband = "true"
if (screen.height < 720 || screen.width < 720 ) {default_broadband = "false"}
var cookie_time=0

// Functions to set and clear broadband

function set_broadband(){
setCookie('broadband',"true",cookie_time,"/")
}

function clear_broadband(){
setCookie('broadband',"false",cookie_time,"/")
}

// Function to toggle flag for broadband users

function toggle(){
if (getCookie('broadband') == "undefined") { setCookie('broadband',default_broadband,cookie_time,"/"); }
if (getCookie('broadband') != "true") {
setCookie('broadband',"true",cookie_time,"/");
}
else {
setCookie('broadband',"false",cookie_time,"/");
}
}

// Functions called for vertical and horizontal popups of two different sizes (image files end in i.jpg for icon, w.jpg for small image (400*300) and b.jpg for large images (600x450)

function popitup2v(url,title) {
if (getCookie('broadband') == "undefined") { setCookie('broadband',default_broadband,cookie_time,"/"); }
if ( getCookie('broadband') == "true") {url=url+'b.jpg';popitup5(url , title, 450, 600, 'white') }
else {url=url+'w.jpg'; popitup5( url , title, 300, 400, 'white') } }

function popitup2h(url,title) {
if (getCookie('broadband') == "undefined") { setCookie('broadband',default_broadband,cookie_time,"/"); }
if ( getCookie('broadband') == "true") {url=url+'b.jpg';popitup5(url , title, 600, 450, 'white') }
else { url=url+'w.jpg'; popitup5( url, title, 400, 300, 'white')
}}
/*
Functions to put in the HTML to provide simplified calls for vertical and horizontal popups with a doubleClick event handler calling toggle() so that large popups can be displayed if user has broadband

<IMG src= "imagei.jpg" alt="title"  title="title"  width = "160" height = "120" border = "0" align="left" hspace = 10 vspace = 10 onDblClick="toggle()"  onClick="popitup2h('image' , 'title')" </IMG>

*/

	function hpop(image, title, alignment) {
		document.write('<IMG src= \"' +image + 'i.jpg\" alt=\"' + title + '\"  title=\"' + title + '\"    width = 160 height = 120 border = 0 align=\"' + alignment + '\" hspace = 10 vspace = 10 onDblClick=\"toggle()\"  onClick=\"popitup2h(\' '+ image+'\' ,\' ' + title+ '  \' )\" <\/IMG>') }



	function vpop(image, title, alignment) {
		document.write('<IMG src= \"' +image + 'i.jpg\" alt=\"' + title + '\"  title=\"' + title + '\"     width = 120 height = 160 border = 0 align=\"' + alignment + '\" hspace = 10 vspace = 10 onDblClick=\"toggle()\"  onClick=\"popitup2v(\''+ image+ '\' ,\' ' + title+ '  \' )\" <\/IMG>') }
		

/* The following code can be used to calculate the connection speed by measuring the time to load one of the images on the site. The image tag is replace by a Script call to writeImageTag{}. Based on code at http://phaster.com/golden_hill_free_web/ghfw_connection_speed.shtml but new use of cookie set in onload event in body.
*/

bandwidth = 30; // Connection Speed

function writeImageTag( imageURL, fileSize, imgTagProperties ) {
// Writes the image tag which is used to calculate the bandwidth on the fly. Needs filesize input in bytes.
	start = (new Date()).getTime();
	loc = imageURL + '?t=' + escape(start); // Append start time to ensure the image is not cached.
	document.write('<img src="' + loc + '" ' + imgTagProperties + ' onload="bandwidth=computebandwidth(' + start + ',' + fileSize + ');  ">');
	return;
}

function computebandwidth( start, fileSize ) {
	// Called by writeImageTag to calculate approximate connection speed	
	end = (new Date()).getTime();
	connectSpeed = (fileSize * 8) / (end - start);
	if (connectSpeed > 40  && screen.width > 800 ) { setCookie('broadband',"true",0,"/"); };
	if (connectSpeed < 10 ) { setCookie('broadband',"false",0,"/"); };
	return connectSpeed;
}

function showSpeed() {
 // For testing puposes
    alert('The Connection Speed during the download of the test image was: ' + Math.floor(bandwidth) + ' kbps.');
	return;
}

//function setBroadband() {
//  Put onload="setBroadband()" in Body tag
//  Checks bandwidth and screen width before setting broadband cookie
//	if (bandwidth > 40  && screen.width > 799 ) { setCookie('broadband',"true",0,"/"); };
//	if (bandwidth < 10 ) { setCookie('broadband',"false",0,"/"); };
//	return; 
//  }		

/* The following is loosely based on some code found at the Webdeveloper.com by Ultimater */


function ExpandOn(topicID){
var expand=document.getElementById(topicID);
if(!expand)return true;
if(expand.style.display=="none"){
expand.style.display="block"
} 
return true;
}

function ExpandOff(topicID){
var expand=document.getElementById(topicID);
if(!expand)return true;
if(expand.style.display=="block"){
expand.style.display="none"
}
return true;
} 

function ExpandToggle(topicID){
var expand=document.getElementById(topicID);
if(!expand)return true;
if(expand.style.display=="none"){
expand.style.display="block"
} else {
expand.style.display="none"
}
return true;
}





//Last Updated 16th September 2011  

