// JavaScript Document
/////////////////////////////////////////////////////////////////////////////////
//zoom function
function getOW() {
	myImg = document.getElementById('theImg');
	origW = document.imgName.width;
	origH = document.imgName.height;
	origLoc = findPos(myImg);
	currentWidth = origW;
	currentHeight = origH;
	
	maxL = origLoc[0];
	maxR = origW + maxL;
	
	maxT = origLoc[1];
	maxB = origH + maxT;
	
	imgBottom = maxB;
	imgRight = maxR;

}
function setOW() {
	document.getElementById('theImg').style.width = origW+"px";
	document.getElementById('theImg').style.height = origH+"px";
	document.getElementById('theImg').style.top = origLoc[1]+"px";
	document.getElementById('theImg').style.left = origLoc[0]+"px";
	currentWidth = newWidth = origW;
	currentHeight = newHeight = origH;
	imgBottom = maxB;
	imgRight = maxR;
}

function imgZoom(DOMArg, bZoom) {//either got information from mouse wheel or click on "zoom in" or "zoom out"
	if (!bZoom){
		posNeg = wheel(DOMArg);
	} else {
		posNeg = bZoom
	}
	myImg = document.getElementById('theImg');
	myImgDiv = document.getElementById('theImg');
	currentLocation = findPos(myImg);
	if ((posNeg < 0) &&currentWidth == origW+700) { zoomExtents();
	}
	if ((posNeg < 0) && (currentWidth < (origW+700))) {
		newWidth = currentWidth + 100;
		newTop = currentLocation[1] - 50;
		newLeft = currentLocation[0] - 50;
		newHeight = (origH/origW)*newWidth;
		
		imgBottom = newTop + newHeight; //for use with panning functions
		imgRight = newLeft + newWidth;   //for use wtth panning functions

		if (newWidth < origW || (newHeight-5) < origH){
			setOW();
			return false;
		}

		//check top
		if (newTop <= maxT && imgBottom >= maxB) {
			myImg.style.top = newTop+"px";
		} 
		if (newTop > maxT && imgBottom >= maxB){
			newTop = maxT;
			myImg.style.top = newTop+"px";	
		}
		if (newTop <= maxT && imgBottom < maxB){
			newTop = (maxB - newHeight);
			myImg.style.top = newTop+"px";	
		}
		//check left
		if (newLeft <= maxL && imgRight >= maxR) {
			myImg.style.left = newLeft+"px";
		} 
		if (newLeft > maxL && imgRight >= maxR){
			newLeft = maxL;
			myImg.style.left = newLeft+"px";
		}
		if (newLeft <= maxL && imgRight < maxR) {
			newLeft = (maxR - newWidth);
			myImg.style.left = newLeft+"px";
		} 
		myImg.style.width = newWidth+"px";
		myImg.style.height = newHeight+"px";
		currentWidth = newWidth;
		currentHeight = newHeight;
	} 
	
	if ((posNeg > 0) && (currentWidth > origW)) {
		newWidth = currentWidth - 100;
		newTop = currentLocation[1] + 50;
		newLeft = currentLocation[0] + 50;
		newHeight = (origH/origW)*newWidth;

		imgBottom = newTop + newHeight; //for use with panning functions as well
		imgRight = newLeft + newWidth;  

		if (newWidth < origW || (newHeight-5) < origH){
			setOW();
			return false;
		}

		//check top
		if (newTop <= maxT && imgBottom >= maxB) {
			myImg.style.top = newTop+"px";
		} 
		if (newTop > maxT && imgBottom >= maxB){
			newTop = maxT;
			myImg.style.top = newTop+"px";	
		}
		if (newTop <= maxT && imgBottom < maxB){
			newTop = (maxB - newHeight);
			myImg.style.top = newTop+"px";	
		}
		//check left
		if (newLeft <= maxL && imgRight >= maxR) {
			myImg.style.left = newLeft+"px";
		} 
		if (newLeft > maxL && imgRight >= maxR){
			newLeft = maxL;
			myImg.style.left = newLeft+"px";
		}
		if (newLeft <= maxL && imgRight < maxR) {
			newLeft = (maxR - newWidth);
			myImg.style.left = newLeft+"px";
		} 
		myImg.style.width = newWidth+"px";
		myImg.style.height = newHeight+"px";
		currentWidth = newWidth;
		currentHeight = newHeight;
	}
}

function zoomExtents(toDo){
	if (!toDo) {
		document.getElementById('zoomEx').style.visibility = "visible";
		setTimeout("zoomExtents('erase')", 1800);
	}
	if (toDo == 'erase'){
		document.getElementById('zoomEx').style.visibility = "hidden";
		
	}
}
//end zoom
//////////////////////////////////////////////////////////////////////////////////////////////////////////