/* function UpdateImg(img) {
	picture.src = "images/gallery/" + img;
	piclink.href = "images/gallery/" + img;

	var picNum = picture.src.substring(picture.src.indexOf("gallery")+15,picture.src.length-4);
	if (picNum == "1" || picNum == "3" || picNum == "4" || picNum == "6" || picNum == "7" || picNum == "10" || picNum == "11")
		caption.style.visibility = "visible";
	else
		caption.style.visibility = "hidden";
}

function NavRight() {
	var picNum = picture.src.substring(picture.src.indexOf("gallery")+15,picture.src.length-4);
	if (picNum == "1")
		UpdateImg("gallery2.jpg");
	else if (picNum == "2")
		UpdateImg("gallery3.jpg");
	else if (picNum == "3")
		UpdateImg("gallery4.jpg");
	else if (picNum == "4")
		UpdateImg("gallery5.jpg");
	else if (picNum == "5")
		NextSet();
	else if (picNum == "6")
		UpdateImg("gallery7.jpg");
	else if (picNum == "7")
		UpdateImg("gallery8.jpg");
	else if (picNum == "8")
		UpdateImg("gallery9.jpg");
	else if (picNum == "9")
		UpdateImg("gallery10.jpg");
	else if (picNum == "10")
		NextSet();
	else if (picNum == "11")
		UpdateImg("gallery12.jpg");
	else if (picNum == "12")
		UpdateImg("gallery13.jpg");
	else if (picNum == "13")
		NextSet();
}

function NavLeft() {
	var picNum = picture.src.substring(picture.src.indexOf("gallery")+15,picture.src.length-4);
	if (picNum == "1") {
		PrevSet();
		UpdateImg("gallery13.jpg");		
	}
	else if (picNum == "2")
		UpdateImg("gallery1.jpg");
	else if (picNum == "3")
		UpdateImg("gallery2.jpg");
	else if (picNum == "4")
		UpdateImg("gallery3.jpg");
	else if (picNum == "5")
		UpdateImg("gallery4.jpg");
	else if (picNum == "6") {
		PrevSet();
		UpdateImg("gallery5.jpg");
	}
	else if (picNum == "7")
		UpdateImg("gallery6.jpg");
	else if (picNum == "8")
		UpdateImg("gallery7.jpg");
	else if (picNum == "9")
		UpdateImg("gallery8.jpg");
	else if (picNum == "10")
		UpdateImg("gallery9.jpg");
	else if (picNum == "11") {
		PrevSet();
		UpdateImg("gallery10.jpg");
	}
	else if (picNum == "12")
		UpdateImg("gallery11.jpg");
	else if (picNum == "13")
		UpdateImg("gallery12.jpg");
}

function PrevSet() {
	var picNum = picture.src.substring(picture.src.indexOf("gallery")+15,picture.src.length-4);

	if ((picNum >= 1) && (picNum <= 5))		//first set, switch to third
		Set3();
	if ((picNum >= 6) && (picNum <= 10)) 	//second set, switch to first
		Set1();
	if ((picNum >= 11) && (picNum <= 15)) 	//third set, switch to second
		Set2();
}

function NextSet() {
	var picNum = picture.src.substring(picture.src.indexOf("gallery")+15,picture.src.length-4);

	if ((picNum >= 1) && (picNum <= 5))		//first set, switch to second
		Set2();
	if ((picNum >= 6) && (picNum <= 10)) 	//second set, switch to third
		Set3();
	if ((picNum >= 11) && (picNum <= 15)) 	//third set, switch to first
		Set1();
}

function Set1() {
		UpdateImg("gallery1.jpg");
		slot1.src = "images/gallery/thumbs/gallery1.jpg";
		link1.href = "javascript:UpdateImg('gallery1.jpg')";
		slot2.src = "images/gallery/thumbs/gallery2.jpg";
		link2.href = "javascript:UpdateImg('gallery2.jpg')";
		slot3.src = "images/gallery/thumbs/gallery3.jpg";
		link3.href = "javascript:UpdateImg('gallery3.jpg')";
		slot4.src = "images/gallery/thumbs/gallery4.jpg";
		link4.href = "javascript:UpdateImg('gallery4.jpg')";
		slot5.src = "images/gallery/thumbs/gallery5.jpg";
		link5.href = "javascript:UpdateImg('gallery5.jpg')";
}

function Set2() {
		UpdateImg("gallery6.jpg");
		slot1.src = "images/gallery/thumbs/gallery6.jpg";
		link1.href = "javascript:UpdateImg('gallery6.jpg')";
		slot2.src = "images/gallery/thumbs/gallery7.jpg";
		link2.href = "javascript:UpdateImg('gallery7.jpg')";
		slot3.src = "images/gallery/thumbs/gallery8.jpg";
		link3.href = "javascript:UpdateImg('gallery8.jpg')";
		slot4.src = "images/gallery/thumbs/gallery9.jpg";
		link4.href = "javascript:UpdateImg('gallery9.jpg')";
		slot5.src = "images/gallery/thumbs/gallery10.jpg";
		link5.href = "javascript:UpdateImg('gallery10.jpg')";		
}

function Set3() {
		UpdateImg("gallery11.jpg");
		slot1.src = "images/gallery/thumbs/gallery11.jpg";
		link1.href = "javascript:UpdateImg('gallery11.jpg')";
		slot2.src = "images/gallery/thumbs/gallery12.jpg";
		link2.href = "javascript:UpdateImg('gallery12.jpg')";
		slot3.src = "images/gallery/thumbs/gallery13.jpg";
		link3.href = "javascript:UpdateImg('gallery13.jpg')";
		slot4.src = "images/global/spacer.gif";
		slot5.src = "images/global/spacer.gif";
} */

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		index_05_over = newImage("images/index_05-over.gif");
		index_09_over = newImage("images/index_09-over.gif");
		index_11_over = newImage("images/index_11-over.gif");
		index_12_over = newImage("images/index_12-over.gif");
		index_13_over = newImage("images/index_13-over.gif");
		index_14_over = newImage("images/index_14-over.gif");
		index_15_over = newImage("images/index_15-over.gif");
		index_16_over = newImage("images/index_16-over.gif");
		index_17_over = newImage("images/index_17-over.gif");
		index_18_over = newImage("images/index_18-over.gif");
		index_20_over = newImage("images/index_20-over.gif");
		preloadFlag = true;
	}
}






function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		mainpage_05_over = newImage("images/global/mainpage_05-over.gif");
		mainpage_07_over = newImage("images/global/mainpage_07-over.gif");
		mainpage_08_over = newImage("images/global/mainpage_08-over.gif");
		mainpage_09_over = newImage("images/global/mainpage_09-over.gif");
		mainpage_10_over = newImage("images/global/mainpage_10-over.gif");
		mainpage_11_over = newImage("images/global/mainpage_11-over.gif");
		mainpage_12_over = newImage("images/global/mainpage_12-over.gif");
		mainpage_13_over = newImage("images/global/mainpage_13-over.gif");
		mainpage_14_over = newImage("images/global/mainpage_14-over.gif");
		mainpage_15_over = newImage("images/global/mainpage_15-over.gif");
		mainpage_16_over = newImage("images/global/mainpage_16-over.gif");
		mainpage_17_over = newImage("images/global/mainpage_17-over.gif");
		mainpage_18_over = newImage("images/global/mainpage_18-over.gif");
		preloadFlag = true;
	}
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

var picCount;			//variable used for line breaks in image galleries
var picsPerRow;
var vAlign = "center";	//default vertical alignment
var galName = "";		//hidden gallery name for lightbox gallery view

//begins a table-based gallery
//argument 1 (optional): the title of the gallery
//argument 2 (optional): number of pictures per row
//argument 3 (optional): vertical alignment
//argument 4 (optional): width of table
function galleryStart(title,p,va,w) {
	picCount = 0;
	if (galName == "")			//else append gallery to existing set
		galName = Math.random();	//random hidden gallery name for lightbox gallery view
	
	if (title != undefined)	
		document.write("<table width="+w+"><tr><td colspan="+picsPerRow+"><br><center><h1>"+title+"</h1></center><br></td></tr><tr valign="+vAlign+">");
	else
		document.write("<table width="+w+"><tr valign="+vAlign+">");
	
	if ((p != undefined)&&(p != ""))
		picsPerRow = p;
	else
		picsPerRow = 3;		//default
	
	if ((va != undefined)&&(va != ""))
		vAlign = va;
	if ((w != undefined)&&(w != ""))
		width = w;
	
}

//ends a table-based gallery
function galleryEnd() {
	picCount = 0;
	galName = "";
	document.write("</tr></table>");
}

//begins a non-table-based set of pictures (for use of NEXT and PREVIOUS buttons)
function setStart() {
	galName = Math.random();	//so we know the individual picture is part of a set
}

//ends a non-table-based set of pictures
function setEnd() {
	galName = "";	//resets hidden gallery name (for lightbox gallery view)
}

//display a picture in gallery format, assumed presence within a table row element and a script element
//argument 1: location of the image, base directory of /images/ is assumed
//argument 2 (optional): the caption
function galleryPic(loc,cap,disp) {
	picCount++;
	var path = loc.substring(0,loc.lastIndexOf("/")+1);
	var filename = loc.substr(loc.lastIndexOf("/")+1);
	if ((cap==undefined)||(disp=="nodisplay")) {
		var cap = "";
		var displayCap = "";
	}	
	else var displayCap = cap;	//shortened form of caption used for main gallery page

	//***************************************************************
	//PENDING: check for existence of thumbnail, create it if it doesn't exist
	//***************************************************************

	if (disp=="nolightboxcaption") cap = " ";
	else if((cap == undefined)||(cap == "")) {
		cap = " ";	//deal with missing captions
	}
	else {
		cap = escape(cap); //hack to get double quotes (lightbox can't deal with them)
		cap = cap.replace(/%22/g,"''");
		cap = unescape(cap);
	}	

	//if (cap.length > 50) displayCap = cap.substr(0,cap.indexOf(" ",50)) + "...";	//shorten long captions
	
	document.write("<td><div align=\"center\"><a href=\"images/" 
		+ loc +	"\" rel=\"lightbox["+galName+"]\" title=\"" + cap
		+ "\"><img class=\"galleryPic\" src=\"images/" + path + "thumbs/" + filename 
		+ "\"></a><div class=\"caption\">" 
		+ displayCap + "</div></div></td>");
	
	// insert a "line break"
	if ((picCount%picsPerRow)==0) {
		document.write("<\/tr><tr valign="+vAlign+">");
	}
}

//standalone picture
function picture(loc,cap,align) {
	var path = loc.substring(0,loc.lastIndexOf("/")+1);
	var filename = loc.substr(loc.lastIndexOf("/")+1);
	
	if(cap == undefined) {
		var cap = " ";
		var displayCap = " ";
	}	
	//else if (cap.length > 50) displayCap = cap.substr(0,cap.indexOf(" ",50)) + "...";	//shorten long captions
	else var displayCap = cap;	//shortened form of caption used for main gallery page
	var a = align;
	
	if (galName != "")
		document.write("<div align=\"center\"><a href=\"images/" 
			+ loc +	"\" rel=\"lightbox["+galName+"]\" title=\"" + cap
			+ "\"><img class=\"galleryPic\" align=" + a 
			+ " src=\"images/" + path + "thumbs/" + filename 
			+ "\" alt=\"" + cap + "\" hspace=\"15\" vspace=\"15\"></a><div class=\"caption\">" 
			+ displayCap + "</div></div>");
	else
		document.write("<div align=\"center\"><a href=\"images/" 
			+ loc +	"\" rel=\"lightbox\" title=\"" + cap
			+ "\"><img class=\"galleryPic\" align=" + a 
			+ " src=\"images/" + path + "thumbs/" + filename 
			+ "\" alt=\"" + cap + "\" hspace=\"15\" vspace=\"15\"></a><div class=\"caption\">" 
			+ displayCap + "</div></div>");
	cap = " ";	
}