// <<<<<<<<<<<<<<<<< GALLERY.JS >>>>>>>>>>>>>>>>>>

/*	Javascript file gallery.js - version 1.1
	Needed to run the picture gallery page(s) of TonyTurton.com
	This file (gallery.js) is located in the "gallery" directory

	Version 1.1 - Javascript simplified; links to large format pictures initiated as direct links (for <noscript>
	browsers), amended to Javascript links by this script running onLoad (function scriptLinks)
*/

// determine browser type
	var agt = navigator.userAgent.toLowerCase();
	var isOpera = ( (agt.indexOf("opera") != -1) && document.getElementById   ) ? 1 : 0;
	var isNav4 = (document.layers && !isOpera) ? 1 : 0;
	var isIE4  = (document.all && !isOpera) ? 1 : 0;
	var isMoz  = ( document.getElementById && !(isNav4 || isIE4 | isOpera) ) ? 1 : 0;
	var isNone = (isOpera+isNav4+isIE4+isMoz) ? 0 : 1;
// alert ("isOpera " + isOpera + "\nisNav4 " + isNav4 + "\nisIE4 " + isIE4 + "\nisMoz " + isMoz + "\nisNone " + isNone)

  function picwin(picNo) {
	var add_on=0;
	refNumber=picNo;
	if (picNo>999) {
		refNumber=Math.floor(picNo/1000);
		add_on=4;
		}

// build string for URL + querystring for new window
	urlstring=new String;
	urlstring="../picviewer.html?";
// first get the directory holding the picture
	var imgSrc=document.location.toString();
	var lastSlash=imgSrc.lastIndexOf("/");
	var prevSlash=imgSrc.lastIndexOf("/",lastSlash-1);
	imgSrc=imgSrc.substring(prevSlash+1, lastSlash+1);
// imgSrc now holds "dirname/" - append the picture name and file extension
	imgSrc+="pic"+picNo.toString() + ".jpg";
	urlstring+="imgSrc=" + imgSrc + "&";
// now add the picture description (alt) string
	urlstring+="picDescr=" + picdata[refNumber][3];
// finished

// build new window attribute list
	if (screen.availWidth) {
	var winw=Math.min(picdata[refNumber][0+add_on],screen.availWidth-20)
	var winh=Math.min(picdata[refNumber][1+add_on],screen.availHeight-50)
	attr_str=""
	attr_str+="width="
	attr_str+=winw.toString()
	attr_str+=",height="
	attr_str+=winh.toString()
	if (winw<bigpic[refNumber].width || winh<bigpic[refNumber].height) {
		attr_str+=",scrollbars=1,resizable=1"} else {attr_str+=",scrollbars=0"}
	} else {
	attr_str=""
	attr_str+="scrollbars=1,resizable=1"
	}
	attr_str+=",toolbar=0,location=0,directories=0,status=1,menubar=0"
	attr_str+=",screenX=0,screenY=0,top=0,left=0"
// finished

// load selected picture into memory
// message in status window
	self.status="Loading picture - please wait"
	bigpic[refNumber].src="pic"+picNo.toString()+".jpg"
	bigpic[refNumber].width=picdata[refNumber][0+add_on]
	bigpic[refNumber].height=picdata[refNumber][1+add_on]
	bigpic[refNumber].alt=picdata[refNumber][3]
// wait until picture is loaded
	var isItLoaded=isLoaded()
}

	function isLoaded() {
// force status message
	if (self.status.substring(0,4)!="Load") {self.status="Loading picture - please wait"}
	if (bigpic[refNumber].complete) {var pr = openIt()} else {timerId1=setTimeout('isLoaded()', 250)}
}

	function openIt() {
// clear status and open new window
	self.status=""
	var p=window.open(urlstring,"newwin",attr_str)
}

	function statData(n) {
	self.status=picdata[n][3]+" : "+picdata[n][0]+" x "+picdata[n][1]+" ("+picdata[n][2]+" Kb)"
	var picnamestr="pic"+n.toString()
	var picname=eval(picnamestr)
	picname.alt=picdata[n][3]
	return true
}
