/*
Functions for controlling "on/off" state of tool icons
*/

//Create array of nav bar "off" images
var maxLod = 10; // the number of levels of detail (cached zoom levels) in the base map

if (document.images) {

	Collapse = new Image();
	Collapse.src = "images/collapse.gif";
	Expand = new Image();
	Expand.src = "images/expand.gif";
	ZoomIn = new Image();
	ZoomIn.src="images/symb_plus_up.png";
	ZoomOut = new Image();
	ZoomOut.src="images/symb_minus_up.png";
	for (var i=0; i<maxLod; i++) {
		this["ZoomScale" + i] =  new Image();
		this["ZoomScale" + i].src = "images/symb_zoom_up_h.png";
		this["ZoomScale" + i + "Hover"] =  new Image();
		this["ZoomScale" + i + "Hover"].src = "images/symb_zoom_down_h.png";
		this["ZoomScale" + i + "On"] =  new Image();
		this["ZoomScale" + i + "On"].src = "images/symb_zoom_down_h.png";
	}
	/*Print = new Image(); 
	Print.src="images/symb_print_up.png";*/
	
	PanNESW = new Image();
	PanNESW.src ="images/PanNESW.png";

}

//Create array of nav bar "hover" images

if (document.images) {
	/*SitemapHover = new Image();
	SitemapHover.src = "images/sitemapOn.jpg";
	ContactHover = new Image();
	ContactHover.src = "images/contactOn.jpg";
	HomeHover = new Image();
	HomeHover.src = "images/homeOn.jpg";
	IdentifyHover = new Image();
	IdentifyHover.src = "images/symb_info_down.png";
	HelpHover = new Image();
	HelpHover.src = "images/symb_help_down.png";
	CenterHover = new Image();
	CenterHover.src = "images/symb_center_down.png";
	ZoomBoxHover = new Image();
	ZoomBoxHover.src="images/zoomBoxOn.png";
	ZoomExtentHover = new Image();
	ZoomExtentHover.src="images/symb_extents_down.png";*/
	ZoomInHover = new Image();
	ZoomInHover.src="images/symb_plus_down.png";
	ZoomOutHover = new Image();
	ZoomOutHover.src="images/symb_minus_down.png";
	ZoomPlusHover = new Image();
	ZoomPlusHover.src="images/symb_plus_down.png";
	ZoomMinusHover = new Image();
	ZoomMinusHover.src="images/symb_minus_down.png";
	/*PrintHover = new Image();
	PrintHover.src="images/symb_print_down.png";*/
	PanNorthHover = new Image();
	PanNorthHover.src ="images/PanNhover.png";
	PanSouthHover = new Image();
	PanSouthHover.src ="images/PanShover.png";
	PanEastHover = new Image();
	PanEastHover.src ="images/PanEhover.png";
	PanWestHover = new Image();
	PanWestHover.src ="images/PanWhover.png";
}

//Create array of nav bar "on" (selected) images
if (document.images) {
	HelpOn = new Image();
	//HelpOn.src = "images/symb_help_down.png";
	ZoomInOn = new Image();
	ZoomInOn.src="images/symb_plus_down.png";
	ZoomOutOn = new Image();
	ZoomOutOn.src="images/symb_minus_down.png";
	ZoomPlusOn = new Image();
	ZoomPlusOn.src="images/symb_plus_down.png";
	ZoomMinusOn = new Image();
	ZoomMinusOn.src="images/symb_minus_down.png";
	//PrintOn = new Image();
	//PrintOn.src="images/symb_print_down.png";
}

//function to activate images

function imgOn(imgName) {	
	if (document.images) {
		document[imgName].src = eval(imgName + "On.src");	
	}
}

//function to deactivate images
function imgHover(imgName) {
	//alert('starting hover: ' + imgName);
	if (document.images) {	
		document[imgName].src = eval(imgName + "Hover.src");
	}
}

function imgOff(imgName) {

	if (document.images) {
			document[imgName].src = eval(imgName + '.src');
			}		
}
function zoomOff(level) {
	// turn off the zoom image unless it is the current zoom 
	var currZoom = map.getLevel();
	//alert('level=' + level + ', currZoom = ' + currZoom);
	if (currZoom != level){
		imgOff('ZoomScale' + level);	
	}
}

function imgHover(imgName) {
	//alert('starting hover: ' + imgName);
	if (document.images) {	
		document[imgName].src = eval(imgName + "Hover.src");
	}
}

function zoomScale(level,alsoZoom) {
	/*Zoom to a particular level. Zoom levels are function of starting zoom level and zoom factor 
	as defined in accessmap.cfm */
	// Reset the zoom scale buttons
	if (alsoZoom) {
		map.setLevel(level);
	}
	for (var i = 0; i < maxLod; i++){
		if (i == level) {
			//alert('turning on ' + i);
			imgOn('ZoomScale' + i);
		}
		else {
			//alert('turning off ' + i);
			imgOff('ZoomScale' + i);
		}		
	}	
}

function zoomOneLevel(direction){
	// increment or decrement the zoom level unless max or min zoom has already been reached
	var zoomLvl = map.getLevel();
	if (direction == 'plus' && zoomLvl < maxLod) {zoomLvl++}
	else if (direction == 'minus' && zoomLvl > maxLod){zoomLvl--}
	else return;
	zoomScale(zoomLvl,true);
}

function printMap(){
	mapimg = dojo.byId('mapimg');
	path = encodeURI(mapimg.src);
	window.open('access_Print.cfm?src=' + path, 'MapPrint', 'width=860,height=500,alwaysRaised,menubar,toolbar,location,resizable,scrollbars');
}





