//if (document.images) { // ensure browser can do rollovers.
//qimages = new Object();

//qimages.b1_df = new Image();
//qimages.b1_df.src = "/images/but_blue.gif";

//qimages.b1_ov = new Image();
//qimages.b1_ov.src = "/images/but_blue-ov.gif";

//qimages.b2_df = new Image();
//qimages.b2_df.src = "/images/but_red.gif";

//qimages.b2_ov = new Image();
//qimages.b2_ov.src = "/images/but_red-ov.gif";

//qimages.b3_df = new Image();
//qimages.b3_df.src = "/images/but_green.gif";

//qimages.b3_ov = new Image();
//qimages.b3_ov.src = "/images/but_green-ov.gif";

//qimages.b4_df = new Image();
//qimages.b4_df.src = "/images/but_orange.gif";

//qimages.b4_ov = new Image();
//qimages.b4_ov.src = "/images/but_orange-ov.gif";


//}

//------------------------------------------------------------------------------
// page-level holders used by photo window bit
//------------------------------------------------------------------------------

var openwins = new Array();
var openimgs = new Array();

//------------------------------------------------------------------------------
// Function: openPhotoWindow
// Purpose: Opens a sized popup window with the file: image_pop.php loaded
// Parameters: iWidth    integer width of window
//             iHeight   integer height for window
//             sImage    string photo filepath
// Authoring: 8/21/2006 Bruce Quackenbush
//------------------------------------------------------------------------------
function openPhotoWindow (iWidth, iHeight, sImage, iFig) {
  
  CleanUpWindows();
  
  //check for image already opened
  var idx = IsInArray(openimgs, sImage);
  
  if (idx == -1) { //image NOT already opened
    //open new window
    thiswin = openwins.length;
    thiswname = randomString();
    if (iFig > 0) iHeight = iHeight + 20;
    openwins[thiswin] = window.open("image_pop.php?i=" + sImage + "&f=" + iFig, thiswname, "width=" + iWidth + ",height=" + iHeight + ",scrollbars=0,toolbar=0,menubar=0,status=0,resizable=1");
    
    // save image name
    openimgs[thiswin] = sImage;
    
    openwins[thiswin].focus();
    lastwin++;
  }
  else { //image already opened, set focus
    openwins[idx].focus();
  }
  
}


//------------------------------------------------------------------------------
// Function: randomString
// Purpose: generates random string of characters
// Parameters: none
// Authoring: 8/21/2006 Bruce Quackenbush
//------------------------------------------------------------------------------
function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
	var string_length = 16;
	var randomstring = '';
	for (var i = 0; i < string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum, rnum + 1);
	}
	return randomstring;
}

//------------------------------------------------------------------------------
// Function: CleanUpWindows
// Purpose: Goes through the global windows array and
//          deletes the references if they aren't found
// Parameters: none
// Authoring: 8/21/2006 Bruce Quackenbush
//------------------------------------------------------------------------------
function CleanUpWindows () {
  //clear closed windows
  var twins = new Array();
  var timgs = new Array();
  
  //alert("openwins on start: " + openwins.length);
  
  for (i = 0; i < openwins.length; i++) {
    if (window.openwins[i] == null || openwins[i].closed) {
      //openwins.splice(i, 1);
      //openimgs.splice(i, 1);
      //lastwin--;
    }
    else {
      //alert("found opened window");
      twins.push(openwins[i]);
      timgs.push(openimgs[i]);
    }
  }
  
  openwins.splice(0);
  openimgs.splice(0);
  
  openwins = twins;
  openimgs = timgs;

}

//------------------------------------------------------------------------------
// Function: IsInArray
// Purpose: Check a given array for the existence of a given value
//          Both array and value can be anything, 
//          as long as they're the same type of things
// Parameters: aryFind    array of items to search
//             vTest      variant to find
// Authoring: 8/21/2006 Bruce Quackenbush
//------------------------------------------------------------------------------
function IsInArray (aryFind, vTest) {
  for (i = 0; i < aryFind.length; i++) {
    if (aryFind[i] == vTest) {
      return i;
    }
  }
  return -1;
}



