/*
	geojetMiniZoom.js - handles mini zoom controls for static geojet map images

	created 12-7-2005 by Brandon Medenwald (CUR-1743)

	Note:	the mini zooming functions use the map image already displayed to calculate the zoom extents.
			In order for this to work, the image src MUST contain the "center" property.  This property
			along with width and height is used to calculate the map image's existing extent, which is used
			to determine the next extent
*/


function extentFromSrc(src) {
	if (src.match('center')) {
		// parse to find just the extent value within center
		src = src.substring(src.indexOf('center'));
		src = src.substring(0, src.indexOf('&'));
		var rects = src.split('%2C'); // split center values
		var extent = rects[2]; // extent is the third attribute
	} else {
		return 0;
	}
	return extent;
}


function drawMiniZoomControls(divID, imageID, originalExtent, callbackFunction, pleaseWaitID) {
	var s = '<div>';
	if (pleaseWaitID) s += '<span id="' + pleaseWaitID + '" style="postion:relative;float:left;padding-left:5px;"><img src="/images/blue_cube_anim.gif" border="0" /></span>';
	s += '<a href="javascript:;" onclick="miniZoom(\'zoomin\', document.getElementById(\'' + imageID + '\').src, \'' + callbackFunction + '\', \'' + pleaseWaitID + '\');"><img src="/images/zoomi_16.gif" border="0" title="Zoom In" style="margin-left:3px;margin-right:3px;" /></a>';
	s += '&nbsp;&nbsp;';
	s += '<a href="javascript:;" onclick="miniZoom(\'zoomout\', document.getElementById(\'' + imageID + '\').src, \'' + callbackFunction + '\', \'' + pleaseWaitID + '\');"><img src="/images/zoomo_16.gif" border="0" title="Zoom Out" style="margin-left:3px;margin-right:3px;" /></a>';
	s += '&nbsp;&nbsp;';
	s += '<a href="javascript:;" onclick="miniReset(' + originalExtent + ', \'' + callbackFunction + '\', \'' + pleaseWaitID + '\');"><img src="/images/ref_16.gif" border="0" title="Reset Map" style="margin-left:3px;margin-right:3px;" /></a>';

	document.getElementById(divID).innerHTML = s;
}


function miniZoom(action, imgSrc, callbackFunction, pleaseWaitID) {
	var miniZoomArray = new Array( 1650, 3300, 6600, 13200, 26400, 52800, 105600, 211200, 528000, 1056000 );
	var newExtent = 0;

	// calculate the existing extent of the map image
	var existingExtent = extentFromSrc(imgSrc);
	if (existingExtent == 0) return false;

	// determine new extent possibilities by stepping through our pre-designated array
	if (action == 'zoomin') {
		for (var x = 0; x < miniZoomArray.length; x++)
			if (existingExtent > miniZoomArray[x])
				newExtent = miniZoomArray[x];
	}
	else {
		for (var x = miniZoomArray.length - 1; x > -1; x--)
			if (existingExtent < miniZoomArray[x])
				newExtent = miniZoomArray[x];
	}

	// if newExtent is still 0, then the extent is already at the extreme of in or out, so abort
	if (newExtent == 0) return false;

	// load "Please Wait", if requested
	if (pleaseWaitID) {
		if (navigator.userAgent.indexOf( 'MSIE' ) != -1) document.getElementById(pleaseWaitID).innerHTML = '<img src="/images/blue_cube_anim.gif" border="0" />';
		document.getElementById(pleaseWaitID).style.visibility = 'visible';
	}

	// execute the callback function
	eval(callbackFunction + '(' + newExtent + ');');
}


function miniReset(originalExtent, callbackFunction, pleaseWaitID) {
	if (pleaseWaitID) document.getElementById(pleaseWaitID).style.visibility = 'visible';

	// execute the callback function
	eval(callbackFunction + '(' + originalExtent + ');');
}

