	ie=document.all?true:false;
	var zoomlevel = 0;
	var baseImageHeight = 0;
	var xp,yp;
	var imageAreaWidth = 590;
	var imageAreaHeight = 450;
	var tickWidth = 20;
	var originalScrollerLeft = 124;
	var currentScrollerLeft = originalScrollerLeft;
	var ficheImageLoc;
	var printLink;
	var largeLink;
	var bookmarkText;
	var bookmarkLink;
	var iOrigObjTop;
	var iOrigObjLeft;
	var iDragObjTopDiff;
	var iDragObjLeftDiff;
	var oDragObj = null;
	var innerXLock = false;
	var innerYLock = false;

document.onmouseup = drop;
window.document.onmousemove = getMouseXYPos;
		
		function mouseDown(e,sourceObject) {
			var buttonPressed;
			if(e.preventDefault)
			{
				e.preventDefault();
			}
			//Captures Which Button is pressed in IE and Mozilla
			if (e.which) 
			{
				buttonPressed = e.which;
			}
			else if (e.button) 
			{
				buttonPressed = e.button;
			}
			if ((ie && buttonPressed == 1) || (!ie && buttonPressed == 1)) 
			{			
				// Left Click
				dragPiece(sourceObject)	;
			}
			else if ((ie && buttonPressed == 2) || (!ie && buttonPressed == 3)) 
			{
				// Right Click
				if (sourceObject.id != "scroller")
				{
					centerImage(sourceObject);
				}
			}	
			else if ((ie && buttonPressed == 4) || (!ie && buttonPressed == 2)) 
			{
				//Scroll wheel Click
				zoom(0);
			}
			
		}
		
		function doZoom(inout){
			
			if ((zoomlevel < 6) && (inout > 0)) 
			{ 
				//zoom in
				zoom(zoomlevel+1);
			}
			else if ((zoomlevel > -6) && (inout < 0)) 
			{  
				//zoom out
				zoom(zoomlevel-1);
			}
			else if (inout == 0)
			{  
				//reset image
				zoom(0);
			}
		}

		function zoom(zoomin) {
			image=document.getElementById('ficheimg');
			
			if (baseImageHeight == 0) {
				baseImageWidth = image.width;
				baseImageHeight = image.height;
			}
			
			if (zoomin >= 0) 
			{ 
				//zoom in
				originalTop = parseInt(image.style.top);
				originalLeft = parseInt(image.style.left);
				oCenterLeft = ((imageAreaWidth/2)-originalLeft);
				oCenterTop = ((imageAreaHeight/2)-originalTop);
				originalWidth = image.width;
				originalHeight = image.height;
				oCenterPLeft = oCenterLeft/originalWidth;
				oCenterPTop = oCenterTop/originalHeight;			
				newHeight = Math.round(baseImageHeight*Math.pow(1.2,Math.abs(zoomin)));
				newWidth = Math.round(baseImageWidth*Math.pow(1.2,Math.abs(zoomin)));			
				image.height = newHeight;
				if (ie)
				{
					image.width = newWidth;
				}
				nCenterLeft = newWidth * oCenterPLeft;
				nCenterTop = newHeight * oCenterPTop;
				newTop = (imageAreaHeight/2) - nCenterTop;
				newLeft = (imageAreaWidth/2) - nCenterLeft;
				image.style.left = newLeft + "px";
				image.style.top = newTop + "px";
			} 
			else if (zoomin <= 0) 
			{  
				//zoom out
				originalTop = parseInt(image.style.top);
				originalLeft = parseInt(image.style.left);
				oCenterLeft = ((imageAreaWidth/2)-originalLeft);
				oCenterTop = ((imageAreaHeight/2)-originalTop);
				originalWidth = image.width;
				originalHeight = image.height;
				oCenterPLeft = oCenterLeft/originalWidth;
				oCenterPTop = oCenterTop/originalHeight;
				newHeight = Math.round(baseImageHeight*Math.pow(.8,Math.abs(zoomin)));
				newWidth = Math.round(baseImageWidth*Math.pow(.8,Math.abs(zoomin)));
				image.height = newHeight;
				if (ie)
				{
					image.width = newWidth;
				}		
				nCenterLeft = newWidth * oCenterPLeft;
				nCenterTop = newHeight * oCenterPTop;
				newTop = (imageAreaHeight/2) - nCenterTop;
				newLeft = (imageAreaWidth/2) - nCenterLeft;
				image.style.left = newLeft + "px";
				image.style.top = newTop + "px";
			}
			//Set the Scroller in the zoom bar
			setScrollerPlacement(zoomin);
		}	
		
		
		function lockCheck(image){
			
			// Sets Locks on the image position
			
			if (image.width < imageAreaWidth)
			{
				innerXLock = true;
			}
			else
			{
				innerXLock = false;
			}
			
			if (image.height < imageAreaHeight)
			{
				innerYLock = true;
			}
			else
			{
				innerYLock = false;
			}
		
		}
		
		function getMouseXYPos(e) {
			if (!e) var e = window.event;

			xp=ie?event.clientX+document.body.scrollLeft:e.pageX;
			yp=ie?event.clientY+document.body.scrollTop:e.pageY;

			// Move object, if dragging.
			if (oDragObj != null) {	
					
				topStyle = (yp - iDragObjTopDiff);
				leftStyle = (xp - iDragObjLeftDiff);
			
				if (oDragObj.id == "ficheimg")
				{
					//Moving the Main Fiche image
					if ((innerYLock) && (innerXLock) && (topStyle < 0))
					{
						topStyle = 0;
					}
					else if ((innerYLock) && (innerXLock) && ((topStyle + oDragObj.height) > imageAreaHeight))
					{
						topStyle = imageAreaHeight - oDragObj.height;
					}
					else if ((topStyle > imageAreaHeight*.5))
					{
						topStyle = imageAreaHeight*.5;
					}
					else if ((topStyle + oDragObj.height) < (imageAreaHeight*.5))
					{
						topStyle = imageAreaHeight*.5 - oDragObj.height;
					}
	
					if ((innerYLock) && (innerXLock) && (leftStyle < 0))
					{
						leftStyle = 0;
					}
					else if ((innerXLock) && (innerXLock) && ((leftStyle + oDragObj.width) > imageAreaWidth))
					{
						leftStyle = imageAreaWidth - oDragObj.width;
					}
					else if ((leftStyle > imageAreaWidth*.5))
					{
						leftStyle = imageAreaWidth*.5;
					}
					else if (((leftStyle + oDragObj.width) < imageAreaWidth*.5))
					{
						leftStyle = imageAreaWidth*.5 - oDragObj.width;
					}
									
					oDragObj.style.top = topStyle + "px";
					oDragObj.style.left = leftStyle + "px";
				}
				else if (oDragObj.id == "scroller")
				{
					//Moving the Scroll bar Scroller
					if ((leftStyle < (originalScrollerLeft + tickWidth*6 + 6)) && (leftStyle > (originalScrollerLeft - tickWidth*6)))
					{
						oDragObj.style.left = leftStyle + "px";
					}
					else if (leftStyle < (originalScrollerLeft + tickWidth*6 + 6))
					{
						oDragObj.style.left = (originalScrollerLeft - tickWidth*6 - 6) + "px";
					}
					else 
					{
						oDragObj.style.left = (originalScrollerLeft + tickWidth*6 + 6) + "px";
					}
				}
			}
			
			return true;
		}
		
		function dragPiece(sourceObject) {
			//Set the Drag Object
			
			iOrigObjTop = parseInt(sourceObject.style.top);
			iOrigObjLeft = parseInt(sourceObject.style.left);
			iDragObjTopDiff = yp - iOrigObjTop;
			iDragObjLeftDiff = xp - iOrigObjLeft;
			oDragObj = sourceObject;
			document.onselectstart = function () { return false; };
		}

		function drop(e) {
			//Drops the Current draging object is avaiable
			if (oDragObj != null)
			{
				if (oDragObj.id == "scroller")
				{
					currentScrollerLeft = parseInt(oDragObj.style.left);
					scrollerDiff = currentScrollerLeft-originalScrollerLeft;
					zoomAmount = Math.round(scrollerDiff/tickWidth);
					zoom(zoomAmount);
				}
				document.onselectstart = "";
				oDragObj = null;
			}
		}
		
		function centerImage(sourceImage) {
			//Centers the Main Fiche Image
			widthDiff = (imageAreaWidth - sourceImage.width)/2;
			heightDiff = (imageAreaHeight - sourceImage.height)/2;
			sourceImage.style.top = heightDiff + "px";
			sourceImage.style.left = widthDiff + "px";
		}

		function loadImage() {
			//Loads the Main Fiche Images on page load
			imageArea = document.getElementById('fiche_imagediv');
			loadingImage = document.getElementById('loadingImg');
			// Create the new image and set its attributes
			var i = document.createElement('img');
			i.style.position = "relative";
			i.style.left = "0px";
			i.style.top = "0px";
			i.id="ficheimg";
			i.galleryimg="no";
			i.onload = function()
			{
				i.style.position = "relative";
				i.style.left = "0px";
				i.style.top = "0px";
				i.style.cursor = "move";
				i.id="ficheimg";
				i.galleryimg="no";	
				i.onmousedown = function(e)
									{
										if (!e) var e = window.event;
										mouseDown(e,i);
									};
			
				centerImage(i);
				lockCheck(i);
				//Remove the Loading Image
				imageArea.removeChild(loadingImage);
				//Attach the Main Fiche Image
				imageArea.appendChild(i);	
			}
			i.src = ficheImageLoc;
			i.onmousedown = "mouseDown(event,this);";
		}
		
		function resetImage() {
			//Resets the image to zoom level 0 and centers it as it was when you loaded the page
			image=document.getElementById('ficheimg');
			doZoom(0);
			centerImage(image);
		}
		
		function iconMouseOver(icon,state){
			//'flips' the images for the control buttons
			if   (oDragObj == null)
			{
				if (state)
				{
					icon.src = 	icon.src.replace("_off","_on");
				}
				else 
				{	
					icon.src = 	icon.src.replace("_on","_off");
				}
			}
		}
			
		function setScrollerPlacement(sliderZoomLevel){
			//Sets the Slider to the correct position on the scroll bar
			scrollerimage=document.getElementById('scroller');
			scrollerimage.style.left = (originalScrollerLeft + (sliderZoomLevel*(tickWidth+1)));
			zoomlevel = sliderZoomLevel;
		}
		
		function scrollbarClick(){
			//Handles a click on the scroll bar to zoom
			
			if (document.getElementById('mainFicheDiv').parentNode.align != "center")
			{
				if   (oDragObj == null)
				{
					scrollbar = document.getElementById('fiche_imagemanipulatediv');
					relX = xp - (document.getElementById('xDiv').offsetLeft + parseInt(scrollbar.style.left));
					clickZoomLevel = Math.round(parseInt(relX - parseInt(scrollbar.style.width)/2)/(tickWidth+1));
					zoom(clickZoomLevel);
				}
			}
		}
		
		function addBookMark(){	
			//Bookmarks the page for the user
			if(ie)
			{
				window.external.AddFavorite(bookmarkLink,bookmarkText);
			}
			else if(window.sidebar)
			{
				window.sidebar.addPanel(bookmarkText,bookmarkLink,'');
			}
		}
		
		function largeImagePopup(){
			//Pops up the Large Image view
			window.open(largeLink,"Large_Image_Window","toolbar=0,location=0,menutbar=0,directories=0,resizable=1,scrollbars=1,height=600,width=800");
		}

		function printPopup(){
			//Pops up the print Image Window
			window.open(printLink,"Print_Window","toolbar=0,location=0,menutbar=0,directories=0,resizable=1,scrollbars=1,height=600,width=800");
		}
		
		//Load the Image when the page loads
		window.onload=function(){loadImage();};