/* globals for positioning the preview window */
var pw_width = 425;
var pw_height = 625;
var pw_h_offset = pw_width + 25;

/* code for handling image maps - include after image map */
	var countySelected=false;
	var active=null;
	var areaRadius=4;
		var active_rx=11;
		var active_ry=11;
	
	
	
	
	if (document.images) {
		activeImage = new Image();				// highlight point image
		activeImage.src = "/ny/images/centerpoints/bullseye.gif";  
		rolloverImage = new Image();			// rollover point image
		rolloverImage.src = "/ny/images/centerpoints/center_point.gif";
		
		active_rx=(Math.floor(activeImage.width/2)-areaRadius);
		active_ry=(Math.floor(activeImage.height/2)-areaRadius);
		//alert(activeImage.width + "=wid, " + activeImage.height +"=hgt " + active_rx + " " + active_ry);
		rollover_rx=(Math.floor(rolloverImage.width/2)-areaRadius);
		rollover_ry=(Math.floor(rolloverImage.height/2)-areaRadius);
	}

	function getQueryVariable(variable) {
	  var query = window.location.search.substring(1);
	  var vars = query.split("&");
	  for (var i=0;i<vars.length;i++) {
	    var pair = vars[i].split("=");
	    if (pair[0] == variable) {
	      return pair[1];
	    }
	  } 
	  return '';
	}

	if (getQueryVariable('ID') != '') {
		HiliteSpot(getQueryVariable('ID'));
		}
		
	function HiliteSpot(id) {
		var coords=new Array();
		//var active_rx=11;
		//var active_ry=11;
		var x1,y1;
		
		// loads image info using AJAX - experimental
		//aerialLoader(id);
		
		coords=document.getElementById(id).coords.split(",");
		x1=coords[0];
		y1=coords[1];
		// top,left position to place the highlight image so that the center point of the
		// selected area falls in the bullseye.
		var position_x,position_y;
		// get the element that contains the highlight image
		var bullseye=document.getElementById('frame');
			
		if (id!=active && id!=0) {
			active=id;
			position_x=x1-active_rx;
			position_y=y1-active_ry;
			bullseye.style.backgroundImage='url('+activeImage.src+')';
			bullseye.style.backgroundPosition=position_x+'px '+position_y+'px';
			bullseye.style.backgroundRepeat='no-repeat';
			countySelected=true;
			var rollover=document.getElementById('frame2');
			rollover.style.backgroundImage='';
		} else {
			bullseye.style.backgroundImage='';
			countySelected=false;
			active=null;
		}
	}
	
	function PopUpNewWindow(targetURL) {
		// extract id from the target URL.  This is the highlighted link area
		var id;
		if (targetURL=="") {
			id = 0;		
		} else {
			id = ((targetURL.split('?')[1]).split('='))[1];
		}
		HiliteSpot(id);
		
		// return;	// jgr - try w/out update
		
		// call up current file with ID argument
		if (id != 0) {
			var URL = unescape(location.href);
			var xstart = URL.lastIndexOf("/") + 1;
			var xend = URL.length;
			if (URL.lastIndexOf("?") != -1) {
				xend = URL.lastIndexOf("?");
				}
			var hereName = URL.substring(xstart,xend);
			targetURL = hereName + "?ID=" + id;
			window.location = targetURL;
			}

	}
 
 	function changeState(name,whichState) {
		var rollover=document.getElementById('frame2');
		// top,left position to place the rollover image so that the center point of the
		// selected area falls in the image.
		var position_x,position_y;
		var rollover_rx=3;
		var rollover_ry=3;
		var coords=document.getElementById(name).coords.split(",");
		var x1=coords[0];
		var y1=coords[1];

		if (whichState==true && name!=active) {
			position_x=x1-rollover_rx;
			position_y=y1-rollover_ry;
			rollover.style.backgroundImage='url('+rolloverImage.src+')';
			rollover.style.backgroundPosition=position_x+'px '+position_y+'px';
			rollover.style.backgroundRepeat='no-repeat';
		} else {
			rollover.style.backgroundImage='';
		}
	}
