﻿/*
DHTML REPOSITION CODE
This file *should* work for all current common browsers.  It will find the relative x an y coordinates
of each layer's parent element.


Instructions for use

-Each menu is laid out in a div tag in the main body, which has an id="subnav*Layer", where * 
is a unique integer.

-Each menu must have a parent element in the main page, which has an id="subnav*".  The * 
corresponds to the div tag's id *

-Either in a CSS style sheet or a style tag in the main page, each menu must have an id
designation as follows:

	#subnav*Layer { position: absolute; z-index: **; visibility: hidden; display: block; }

	where * equals the menu's number and ** = the menu's number + 1

-Each table cell in the menu needs the following code:

	onmouseover="highlightSubnav(this); return true;" onmouseout="unlightSubnav(this); return true;"

-each table cell in the parent element must have the following code:

	onmouseover="highlightSubnav(this); showSubnav('subnav*Layer'); return true;" onmouseout="unlightSubnav(this); return true;" onclick="location.href='(your link here)';"

-Note that in the event your parent elements are arrayed vertically rather than horizontally, each parent element must be in its own table!

-Set the configuration variables, below.
-this file must be included as a src for the main file in order to work:
	<script type="text/javascript" language="JavaScript" src="/_js/dhtml.js"></script>


*/
	//alert("test1");

	//	Platform flags
	var agt=navigator.userAgent.toLowerCase();
	var use_gebi = (document.getElementById) ? true : false;
	var ie4flag = (document.all) ? true : false;
	var ns4flag = (document.layers) ? true : false;
	var ns6flag = (use_gebi && !document.all) ? true : false;
	var safariflag = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
	var windowsflag = (agt.indexOf('window')!=-1)?true:false;
	var macIEflag = ((agt.indexOf('msie 5')!=-1) && (agt.indexOf('mac')!=-1))?true:false;
	
	var subnavShowing = false;
	var subnavExit = false;
	
	var x = 0;  // These variables are reset by the Get Location functions
	var y = 0;

	//var ChildnavExit=false;	
	
//
//	CONFIGURATION VARIABLES	
//
	var enableDebug = 'no'; 	//options are 'alert', 'status', 'no'
	
	var subnav_layers = 5;		// Number of layers
	var subnav_childmax = 0;	//Number of child layers
	var subnavOffsetX = 0; 	// Offsets are the distance that the menu should offset from the 
	var subnavOffsetY = 22; 		// parent objects - usually the height/width of the parent object and a border, if any.
	
	var childnavOffsetX = 0; 	// Offsets are the distance that the menu should offset from the 
	var childnavOffsetY = 1; 		// parent objects - usually the height/width of the parent object and a border, if any.
	
	var ie4OffsetX = 145;   	// absolute location of the top-left item of the parent objects
	var ie4OffsetY = 65;		// because IE 4 doesn't recognize the DOM parent heirarchy of nested tables
	
	var ChildnavExit=true;
//	
//	END CONFIGURATION VARIABLES
//


	//debug function
	function doDebug(someOutput) {
		if (enableDebug == 'alert') {
			alert(someOutput);
		} else if (enableDebug == 'status') {
			status = someOutput;
		}
		return true;
	}
	
	
	//subnav positioning high-level mgmt
	function repositionLayers() {
		doDebug('repositionLayers()');
		for (i = 1; i <= subnav_layers; i++) {
			setLayerPosition("subnav" + i);
		}
		return true;
	}
	
	// layer positioning
	function setLayerPosition(myobjectName) {
		doDebug('setLayerPosition(' + myobjectName + ')');
		var mylayerName = myobjectName + "Layer";
		//alert(mylayerName);
		if (getPosition(myobjectName)) {
			tempx = x + subnavOffsetX;
			tempy = y + subnavOffsetY;
			
			// Logic to find position
			if (safariflag) { 
				// now set layer top and left accordingly
				document.getElementById(mylayerName).style.left = (tempx) + "px";
				document.getElementById(mylayerName).style.top = (tempy - 1) + "px";
				}
			else if (use_gebi && ns6flag) {  
				// now set layer top and left accordingly
				document.getElementById(mylayerName).style.left = (tempx) + "px";
				document.getElementById(mylayerName).style.top = (tempy - 1) + "px";
				}
			else if (use_gebi && !windowsflag) {
				//alert(mylayerName);
				// now set layer top and left accordingly
				document.all[mylayerName].style.pixelLeft = (tempx);
				document.all[mylayerName].style.pixelTop = (tempy - 1);
				}
			else if (use_gebi && windowsflag) {
				// now set layer top and left accordingly
				document.all[mylayerName].style.pixelLeft = (tempx);
				document.all[mylayerName].style.pixelTop = (tempy - 1);
				//alert (windowsflag);
				}
			else if (ie4flag) {
				// now set layer top and left accordingly
				document[mylayerName].style.pixelLeft = tempx + 1;
				document[mylayerName].style.pixelTop = tempy;
				}
			else {
				x=0; y=0; return false;
				}
//			alert(tempx + ", " + tempy);
			return true;
		}
	}
	
	// layer hiding and showing
	function showLayer(lay) {
		doDebug('showLayer(' + lay + ')');
		if (ie4flag) {document.all[lay].style.visibility = "visible";}
		if (ns4flag) {document.layers[lay].visibility = "show";}
		if (ns6flag) {document.getElementById(lay).style.visibility="visible";}
		return true;
	}
	
	function hideLayer(lay) {
		doDebug('hideLayer(' + lay + ')');
		if (ie4flag) {document.all[lay].style.visibility = "hidden";}
		if (ns4flag) {document.layers[lay].visibility = "hide";}
		if (ns6flag) {document.getElementById(lay).style.visibility="hidden";}
		return true;
	}
	
	//returns position of object in page
	function getPosition(myobjectName) {
		doDebug('getPosition(' + myobjectName + ')');
		// Logic to find position
		if (use_gebi) {
		doDebug('using gebi...');
			var o=document.getElementById(myobjectName);
			x=setLayerPositionPageOffsetLeft(o);
			y=setLayerPositionPageOffsetTop(o);
			}
		else if (ie4flag) {
		doDebug('usingie4flag...');
			x=setLayerPositionPageOffsetLeft(document.all[myobjectName]);
			y=setLayerPositionPageOffsetTop(document.all[myobjectName]);
			}
		else {
			doDebug("default");
			x=0;
			//y=0;
			return false; 
			}
		return true;
	}
	
	// Functions for IE, mozilla, safari to get position of an object
	function setLayerPositionPageOffsetLeft (el) {
		doDebug('setLayerPositionPageOffsetLeft(' + el + ')');
		if (el != "" && el != null) {
			if (ie4flag && !use_gebi) {
				if (el.offsetLeft) {
					var ol=el.offsetLeft;
					while ((el=el.offsetParent) != null) { 
						ol += el.offsetLeft; 
					}
					ol += ie4OffsetX;
				} else {
					var ol=0;
				}
			} else {
				var ol=el.offsetLeft;
				while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
			}
		} else {
			var ol=0;
		}
		if (macIEflag) {
			var macMarginLeft=parseInt(document.body.currentStyle.marginLeft);
			ol += macMarginLeft;
		}
		return ol;
	}
	
	function setLayerPositionPageOffsetTop (el) {
		doDebug('setLayerPositionPageOffsetTop(' + el + ')');
		if (el != "" && el != null) {
			if (ie4flag && !use_gebi) {
				if (el.offsetTop) {
					var ot=el.offsetTop;
					while((el=el.offsetParent) != null) { ot += el.offsetTop; }
				} else {
					var ot=0;
				}
					ot += ie4OffsetY;
			} else {
				var ot=el.offsetTop;
				while((el=el.offsetParent) != null) { ot += el.offsetTop; }
			}
		} else {
			var ot=0;
		}
		if (macIEflag) {
			var macMarginTop=parseInt(document.body.currentStyle.marginTop);
			ot += macMarginTop;
		}

		return ot;
	}
	
	//subnav hiding and showing high-level mgmt
	function showSubnav(lay) {
		doDebug('showSubnav(' + lay + ') mgmt function');
		for (i = 1; i <= subnav_layers; i++) {
			hideLayer("subnav" + i + "Layer");
		}
		showLayer(lay);
		subnavShowing = true;
		subnavExit = false;
		setTimeout("checkSubnav()",1000);
	doDebug(lay);
		return true;
	}
	
	
	//periodic check to turn off subnav if user has left menu area
	function checkSubnav() {
		doDebug('checkSubnav()');
		if ((subnavShowing) && (subnavExit)) {
			for (i = 1; i <= subnav_layers; i++) {
				hideLayer("subnav" + i + "Layer");
			}
			subnavExit = false;
		} else if (subnavShowing) {
			setTimeout("checkSubnav()",500);
		}
		return true;
	}


	//subnav entry highlight
	function highlightSubnav(someObject) {
		doDebug('highlightSubnav(' + someObject + ')');
		subnavExit=false;
		return true;
	}
	
	//subnav entry unlight
	function unlightSubnav(someObject) {
		doDebug('unlightSubnav(' + someObject + ')');
		subnavExit=true;
		return true;
	}








//	EVERYTHING BELOW HERE IS FOR THE SECOND-TIER (CHILD) NAV MENUS.



	//subnav hiding and showing high-level mgmt
	function showChildnav(lay) {
		doDebug('showChildnav(' + lay + ') mgmt function');
		for (i = 101; i <= subnav_childmax+100; i++) {
			hideLayer("subnav" + i + "Layer");
		}
		showLayer(lay);
		childnavShowing = true;
		ChildnavExit = false;
		setTimeout("checkChildnav()",500);
		doDebug(lay);
		return true;
	}
	
	//periodic check to turn off childnav if user has left menu area
	function checkChildnav() {
		doDebug('checkChildnav()');
		if ((childnavShowing) && (ChildnavExit)) {
			for (i = 101; i <= subnav_childmax+100; i++) {
				hideLayer("subnav" + i + "Layer");
			}
			ChildnavExit = false;
		} else if (childnavShowing) {
			setTimeout("checkChildnav()",500);
		}
		return true;
	}

	//Childnav entry highlight
	function highlightChildnav(someObject) {
		doDebug('highlightChildnav(' + someObject + ')');
		ChildnavExit=false;
		return true;
	}
	
	//Childnav entry unlight
	function unlightChildnav(someObject) {
		doDebug('unlightChildnav(' + someObject + ')');
		ChildnavExit=true;
		return true;
	}

	//Childnav positioning high-level mgmt
	function repositionChildLayers() {
		doDebug('repositionChildLayers()');
		for (i = 101; i <= subnav_childmax+100; i++) {
			setChildPosition("subnav" + i);
		}
		return true;
	}

	// layer positioning
	function setChildPosition(myobjectName) {
		doDebug('setChildPosition(' + myobjectName + ')');
		var mylayerName = myobjectName + "Layer";
		if (getPosition(myobjectName)) {
			tempx = x + childnavOffsetX;
			tempy = y + childnavOffsetY;
			
			// Logic to find position
			if (safariflag) { 
				// now set layer top and left accordingly
				document.getElementById(mylayerName).style.left = (tempx) + "px";
				document.getElementById(mylayerName).style.top = (tempy - 10) + "px";
				}
			else if (use_gebi && ns6flag) {  
				// now set layer top and left accordingly
				document.getElementById(mylayerName).style.left = (tempx) + "px";
				document.getElementById(mylayerName).style.top = (tempy - 1) + "px";
				}
			else if (use_gebi && !windowsflag) {
				// now set layer top and left accordingly
				document.all[mylayerName].style.pixelLeft = (tempx);
				document.all[mylayerName].style.pixelTop = (tempy - 1);
				}
			else if (use_gebi && windowsflag) {
				// now set layer top and left accordingly
				//alert(mylayerName);
				document.all[mylayerName].style.pixelLeft = (tempx);
				document.all[mylayerName].style.pixelTop = (tempy - 1);
				//alert (windowsflag);
				}
			else if (ie4flag) {
				// now set layer top and left accordingly
				document[mylayerName].style.pixelLeft = tempx + 1;
				document[mylayerName].style.pixelTop = tempy;
				}
			else {
				x=0; y=0; return false;
				}
			return true;
		}
	}
	
origwidth = 0;
origwidth2 = 0;
zoomposition = 0;

function getOrig(img) {
	origwidth = img.width;
}

function getOrig2(img) {
	origwidth2 = img.width;
}

function zoomIn(image,image2){
	if(zoomposition < 3) {
		zoomposition++;
		image.width = (image.width) * 1.5;
		image2.width = (image2.width) * 1.5;
	}
}

function resetIMG(image,image2){
	if (origwidth != 0) {
		image.width = origwidth;
		image2.width = origwidth2;
		image.style.left = "0px";
		image.style.top = "0px";
		image.style.right = "0px";
		image.style.bottom = "0px";
		image2.style.left = "0px";
		image2.style.top = "0px";
		image2.style.right = "0px";
		image2.style.bottom = "0px";
		zoomposition = 0;
		endDrag();
	}
}

function zoomOut(image,image2){
	if(zoomposition > 0) {
		zoomposition--;
		if(zoomposition != 0) {
			image.width = (image.width) / 1.5;
			image2.width = (image2.width) / 1.5;
		}
		else {
			resetIMG(image,image2);
		}
	}
}

function InitDrag() {
	if(zoomposition != 0) {
		Drag.init(document.getElementById("image1"));
		Drag.init(document.getElementById("image2"));
	}
}

function endDrag() {
	Drag.init(document.getElementById("image1"),null,0,0,0,0);
	Drag.init(document.getElementById("image2"),null,0,0,0,0);
}

cursormode = null;

function activatecontrol(control){
	switch(control) {
		case "zoomin":
			cursormode = control;
			document.getElementById("objectbox1").style.cursor = "crosshair";
			document.getElementById("objectbox2").style.cursor = "crosshair";
			endDrag();
			break;
		case "zoomout":
			cursormode = control;
			document.getElementById("objectbox1").style.cursor = "crosshair";
			document.getElementById("objectbox2").style.cursor = "crosshair";
			endDrag();
			break;
		case "pan":
			cursormode = control;
			document.getElementById("objectbox1").style.cursor = "move";
			document.getElementById("objectbox2").style.cursor = "move";
			InitDrag()
			break;
		default:
	}	
}

function imageclick(){
	switch(cursormode) {
		case "zoomin":
			zoomIn(document.getElementById("image1"),document.getElementById("image2"));
			break;
		case "zoomout":
			zoomOut(document.getElementById("image1"),document.getElementById("image2"));
			break;
		default:
	}	
}


/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		document.getElementById("image1").root.style[o.hmode ? "left" : "right"] = nx + "px";
		document.getElementById("image1").root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		document.getElementById("image2").root.style[o.hmode ? "left" : "right"] = nx + "px";
		document.getElementById("image2").root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

function imageAdjust(img) {

	//Variable Declaration
	img.style.marginTop = "0px";
	parentWidth 		= parseInt(img.parentNode.style.width);
	parentHeight 		= parseInt(img.parentNode.style.height);
	imgWidth 			= img.width;
	imgHeight 			= img.height;
	imgRatio 			= imgWidth/imgHeight;
	
	//Resizes Image
	if (imgRatio > 1) {
		largerdim = "w";
	}
	else {
		largerdim = "h";
	}
	
	switch(largerdim) {
	
		case 'w':
		
			if(imgWidth > parentWidth) {
			
				img.width 	= parentWidth
				imgWidth 	= parseInt(img.width);
				imgHeight 	= parseInt(imgWidth/imgRatio);
			}
			break;
			
		case 'h':
		
			if(imgHeight > parentHeight) {
			
				img.width 	= imgRatio * parentHeight;
				imgWidth 	= parseInt(img.width);
				imgHeight 	= parseInt(imgWidth/imgRatio);
			}
			break;
	}
	
	//Centers Image
	if (imgHeight < (parentHeight - 2)) {
	
		imgPad = (parentHeight - imgHeight)/2;
		imgPad = imgPad + "px";
		
		img.style.marginTop = imgPad;
		
	}
}

