﻿var imageToImport = "";
var curWidth = 1;
var curHeight = 1;
var curImage = "";
var curImageWidth = 0;
var curImageHeight = 0;
var counterConvert = 0;
var imageCounterText;
//Speed of gallery pix sizing
var thespeed = 20;
var destWidth = 0;
var destHeight = 0;
var curLeft = 0;
var curTop = 0;
var keepGrowingWide = false;
var keepGrowingTall = false;
var wordsleft, wordstop, boxleft, boxtop, boxdiv;
var curHeader = '';
var curDescript = '';
var scrollTo = '';
var loadImageArray = new Array();

//////////////////////////////////////////////////////////////////////////////////////
////// These arrays keep track of all of the big versions in image galleries ////////
var infoTracker = 0; //for holding onto the number of the image for cycling
var theImages = new Array(); 
var theWidths = new Array();
var theHeights = new Array(); 
var theHeaders = new Array(); 
var theDescriptions = new Array();
//////////////////////////////////////////////////////////////////////////////////////

//Loads all images in loadImageArray
function imageLoad() {
	for (i=0;i<theImages.length;i++) {
	var loadImage = new Image();
	loadImage.src = "images/" + theImages[i];
	}
}

// Gets the page size
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less than height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//Loads all images in loadImageArray
function doImageLoad() {
	for (i=0;i<loadImageArray.length;i++) {
	var loadImage = new Image();
	loadImage.src = loadImageArray[i];
	}
}

//prepares the larger version of the image to be opened
function openbigimage(zNumber){
	var arrayPageSize = getPageSize();
	var objOverlay = document.getElementById('grayoutbox');
	var photoHolder = document.getElementById('movieBox');
	infoTracker = zNumber;
	//scroll(0,0);
	curImage = theImages[infoTracker];
	destWidth = theWidths[infoTracker];
	destHeight = theHeights[infoTracker];
	curHeader = theHeaders[infoTracker] + " ... [Image " + (infoTracker + 1) + " of " + (theImages.length + 1) + "]";
	curDescript = theDescriptions[infoTracker];
	scrollTo = (window.pageYOffset - 50);
	keepGrowingWide = true;
	keepGrowingTall = true;
	zbuttons = "<div id=\"imageButtons\"><a href=\"javascript:cycleImage('back')\" class=\"backLink\" onmouseover=\"showButtons()\"></a><a href=\"javascript:cycleImage('next')\" class=\"nextLink\" onmouseover=\"showButtons()\"></a></div>";
	headerAndDescript = "<p><em class=\"hdr\">" + curHeader + "</em><br />" + curDescript + "</p>";
	zhtml = "<a href=\"javascript:closebox()\" onmouseover=\"showButtons()\" title=\"Click to close image\"><img src=\"images/" + curImage + "\" id=\"boxid\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></a>";
	photoHolder.style.visibility = "visible";
	photoHolder.innerHTML = (zbuttons + zhtml + headerAndDescript);
	photoHolder.style.top = (scrollTo + 'px');
	objOverlay.style.visibility = 'visible';
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	boxGrow();
}

///// Makes box grow
function boxGrow(){
	if(keepGrowingWide == true || keepGrowingTall == true){
		if(curWidth <= destWidth){
			document.getElementById('boxid').style.width = curWidth+"px";
			curWidth+=thespeed;
		}else{
			document.getElementById('boxid').style.width = destWidth+"px";
			keepGrowingWide = false;
		}
		if(curHeight <= destHeight){
			document.getElementById('boxid').style.height = curHeight+"px";
			curHeight+=thespeed;
		}else{
			document.getElementById('boxid').style.height = destHeight+"px";
			keepGrowingTall = false;
		}
	setTimeout('boxGrow()',1);
	}else{
		curWidth = 1;
		curHeight = 1;
		destWidth = 0;
		destHeight = 0;
		curTop = 0;
		keepGrowingWide = false;
		keepGrowingTall = false;
	}
}

//closes big image
function closebox(){
	document.getElementById('movieBox').style.visibility = "hidden";
	document.getElementById('movieBox').innerHTML = "";
	document.getElementById('grayoutbox').style.height = '50%';
	document.getElementById('grayoutbox').style.visibility = 'hidden';
	//scroll(0,scrollTo);
}

//shows buttons for enlarged images
function showButtons(){
	document.getElementById('imageButtons').style.visibility = "visible";
}

//hides buttons for enlarged images
function hideButtons(){
	document.getElementById('imageButtons').style.visibility = "hidden";
}

//voids links
function myVoid(){}

//Adjusts the infoTracker number, then runs the openbigimage function again
function cycleImage(zDirection){
picHolder = document.getElementById('movieBox');
imageBox = document.getElementById('boxid');
	for(i=0;i<theImages.length;i++){
		zz=i;
		if(theImages[zz]==curImage){
		infoTracker = zz;
		}
	}
	if(zDirection=='next'){
		infoTracker++;
	}else{
		infoTracker--;
	}
	if(infoTracker==theImages.length){
		infoTracker=0;
	}else if(infoTracker<0){
		infoTracker=theImages.length-1;
	}
openbigimage(infoTracker);
}

//closes the image
function closeImage(){
document.getElementById('main').style.visibility = 'visible';
document.getElementById('imagediv').style.visibility = 'hidden';
document.getElementById('closeWindow').style.visibility = 'hidden';
}
