/* Craigrowan JS */

//alert ("Window Scripts Found");

/*  Global variables  */
var newWindow = null;
var newht = null;
var wd = 800;
var ht = 600;
var desc, descr, capht;
var imgsrc;
var j, k, s;

//------------------------------------------------

function addLoadEvent(func) {
//	alert ("AddLoadEvent");
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
//------------------------------------------------

function closeWindow() {
	if (newWindow != null) {
		newWindow.close();
		newWindow = null;
	}
	return null;
}
//------------------------------------------------

function getLinks() {
//	alert ("Starting getLinks");
	if (!document.getElementsByTagName) return false;
//	var wd, ht;
	var inner = document.getElementById("inner");
	var lnks = inner.getElementsByTagName("a");
	for (var i=0; i<lnks.length; i++) {
		lnks[i].onclick = function() {
//			if (this.className == "ls" || this.className == "pt") {
//				alert (this.className);
				if (this.firstChild.nodeName.toLowerCase() == "img") {
					descr = this.firstChild.getAttribute("alt");
				} else {
					descr = this.getAttribute("title");  // no valid 'alt' attribute for links
				}
				if (descr != null) {
//					alert ("Descr = " + descr);
					popUp(this.getAttribute("href"),this.className,descr);
					return false;
				}
//			}
		}
	}
	return null;
}

//------------------------------------------------

// function for ImageGallery and maps on main pages
function popUp(imgname,clname,descr) {
//	alert ("fn popUp starting");
	closeWindow();
	var loc = document.URL;
	var lastChar = loc.slice(loc.length -1);
	var popTgt = "../inc/popUp.htm";  //  path to popUp for folders
	if (loc.indexOf("index.html") != -1 || lastChar == "/") {
		popTgt = "inc/popUp.htm";  //..path to popUp from root
		if (imgname.indexOf("http://") == -1) {
			imgname = "../" + imgname;  //  path to image from popUp (only applied if path is relative)
			}
	}
	imgsrc = imgname;
	desc = descr;
	var windowName = "gallery";
	if (clname == "pt") {
		wd = 531;
		ht = 800;
	} else if (clname == "lge") {
		wd = 800;
		ht = 600;
	} else {
		wd = 800;
		ht = 531;
	}
	var widthHeight = "width="+wd + ",height="+ht;
	newWindow = window.open(popTgt, windowName, widthHeight);
	newWindow.focus();
}
//------------------------------------------------

function makeCaptions() {
//	alert ("Make Captions called");
	if (!document.getElementById) return false;
	var imgdiv = document.getElementById("imgdiv");
	var popimg = document.createElement("img");
	popimg.setAttribute("id","imgx");
	popimg.setAttribute("src",opener.imgsrc);
//	alert ("Opener Src is " + opener.imgsrc);
	popimg.setAttribute("alt",opener.desc);
	popimg.setAttribute("title","");
	var para = document.createElement("p");
	para.setAttribute("id","desc");
	para.style.top = opener.capht + "px";
	var txt = document.createTextNode(opener.desc);
	para.appendChild(txt);
	imgdiv.appendChild(popimg);
	imgdiv.appendChild(para);
	var img = document.getElementById('imgx');
//	window.setTimeout('resizeWindow()',5000);
	return null;
}
//------------------------------------------------

function resizeWindow() {
	var img = document.getElementById('imgx');
//	wd = img.getAttribute("width");
//	ht = img.getAttribute("height") + 50;
	var wd = img.width;
	var ht = img.height + 50;
//	alert ("Width is " + wd + "\nHeight is " + ht);
	window.resizeTo(wd,ht)
	return null;
}



