function initImages () {
    var i, current, imageName
    for (imageName in document.images) {
        if (!workImage[imageName]) {
         current = -1;
         for (i=0; i<document.images.length; ++i) {
            if (document.images[i].name == imageName)
              current = i;
          }
          if (current > -1) {
            workImage[imageName] = document.images[current];
          }
        }
    }
}

function loadInit () {
  initImages();
  STScI_windowOpen();
  document.Loaded = true;
}

function closeOut () {
  STSCI_closeMBrWindows();
  STScI_windowClose();
}

function popup (url, winName, width, height) {
  var modwidth, modheight;

  // Allow for IE's vertical scrollbar & extra space
  modwidth = width;
  modheight = height;
  if (navigator.appName == "Microsoft Internet Explorer") {
    modwidth = (modwidth * 1) + 20;
    modheight = (modheight * 1) + 10;
  }

  STSCI_openMBrWindow(url, winName, "scrollbars,resizable,width="+modwidth+",height="+modheight);
}

function answer_popup(name)
  {
    popup(name+".html", 'answer', '178', '178');
  }

// This function creates a sidebar link parameters are:
// which - What sidebar to display (it adds: ../sidebar/<which>_nf.html)
function createSidebar(which)
  {
    // If the 'which' has a '/' in it anywhere
    if (which.indexOf('/') != -1)
      {
        // Let which stand alone with the _nf ...
        var fullname = which + '_nf.html';
      }
    // ELSE we just got a 'default' name
    else
      {
        var fullname = '../sidebar/' + which + '_nf.html';
      }

    // Lets pop up a window with the sidebar data in it.
    popup(fullname, 'sidebar','450','300');
  }

// Makes a new button - Takes HTML name, URL, URL to on graphics,
// URL to down graphic, status bar text
// Assumes a graphics directory
function Button (name, imageURL, imageURLon, imageURLdown, status) {
    this.name = name;
    this.status = status;

    this.active = true;

    this.defaultImage = new Image;
    this.defaultImage.src = "graphics/" + imageURL;
    this.onImage = new Image;
    this.onImage.src = "graphics/" + imageURLon;
    this.downImage = new Image;
    this.downImage.src = "graphics/" + imageURLdown;
     
    this.on = buttonOn;
    this.down = buttonDown;
    this.def = buttonDefault;
}

function buttonOn () {
    if (this.active && document.Loaded) {
      workImage[this.name].src = this.onImage.src;
      if (this.status != "") {
        window.status = this.status;
        return true;
      }
    }
    return false;
}

function buttonDefault () {
  if (document.Loaded) {
    workImage[this.name].src = this.defaultImage.src;
    if (this.status != "") {
      window.status = "";
      return true;
    }
  }
  return false;
}

function buttonDown () {
   if (this.active && document.Loaded) {workImage[this.name].src = this.downImage.src;}
   return false;
}


// Object: TitleBar
// 
// Parameters:
// banner_src - URL to the graphic of the text banner
// defaultText - URL to the graphic to fill in the text space
// backURL - URL to go to for a previous
// backText - URL to graphic to show for this
// nextURL - URL to go to for a next
// nextText - URL to graphic to show for this
// homeURL - URL to go to for a home
// homeText - URL to graphic to show for this
function TitleBar (banner_src, defaultText, backURL, backText, nextURL,
		   nextText, homeURL, homeText)
  {
    // Create a new object to hold the URLs
    this.URL = new Object;
    this.URL["back"] = backURL;
    this.URL["next"] = nextURL;
    this.URL["home"] = homeURL;

    // Set up class methods
    this.set = setBar;
    this.go = goBar;
    this.create = createBar;

    // Set up images for text area
    this.text = new Object;
    this.text["default"] = new Image;
    this.text["default"].src = defaultText;
    this.text["back"] = new Image;
    this.text["back"].src = backText;
    this.text["home"] = new Image;
    this.text["home"].src = homeText;
    this.text["next"] = new Image;
    this.text["next"].src = nextText;

    // Set up images for buttons
    this.back = new Object;
    this.back["default"] = new Image;
    this.back["default"].src = "../graphics/button.back.default.gif";
    this.back["back"] = new Image;
    this.back["back"].src = "../graphics/button.back.on.back.gif";
    this.back["home"] = new Image;
    this.back["home"].src = "../graphics/button.back.on.home.gif";
    this.back["next"] = new Image;
    this.back["next"].src = "../graphics/button.back.default.gif";

    this.home = new Object;
    this.home["default"] = new Image;
    this.home["default"].src = "../graphics/button.home.default.gif";
    this.home["back"] = new Image;
    this.home["back"].src = "../graphics/button.home.on.back.gif";
    this.home["home"] = new Image;
    this.home["home"].src = "../graphics/button.home.on.home.gif";
    this.home["next"] = new Image;
    this.home["next"].src = "../graphics/button.home.on.next.gif";

    this.next = new Object;
    this.next["default"] = new Image;
    this.next["default"].src = "../graphics/button.next.default.gif";
    this.next["home"] = new Image;
    this.next["home"].src = "../graphics/button.next.on.home.gif";
    this.next["next"] = new Image;
    this.next["next"].src = "../graphics/button.next.on.next.gif";
    this.next["back"] = new Image;
    this.next["back"].src = "../graphics/button.next.default.gif";

    // Set up basic Images to remember
    this.banner = new Image;
    this.banner.src = banner_src;
  }

function setBar (where)
  {
    if (document.Loaded)
      {
	// Set all graphics appropriately
	document.barText.src = this.text[where].src;
	document.barBack.src = this.back[where].src;
	document.barHome.src = this.home[where].src;
	document.barNext.src = this.next[where].src;

	// Set proper status message
	if (where == "home")
	  {
	    window.status = "Return to the Module List";
	  }
	else if (where == "next")
	  {
	    window.status = "Go forward to: " + this.URL["next"];
	  }
	else if (where == "back")
	  {
	    window.status = "Go back to: " + this.URL["back"];
	  }
	else // Default & error cases
	  {
	    window.status = "";
	  }

	return true;
      }

    return false;
  }

function goBar (where)
  {
    // If we have a prev/next/back THEN
    if (where == "home" || where=="next" || where=="back")
      {
	top.location = this.URL[where];
      }
    // ELSE treat it as a URL & pop it
    else
      {
	popup (this.URL[where], where);
      }
  }

function createBar ()
{
  document.write ("<table border=0 cellpadding=0 cellspacing=0 width=700>\n");
  document.write ("<tr>\n");

  document.write ("<td>");
  document.write ("<img src=\"" + this.banner.src + "\" height=\"55\" width=\"442\" border=\"0\">");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<img name=\"barText\" src=\"" + this.text["default"].src + "\" height=\"55\" width=\"151\" border=\"0\">");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<a href=\"javascript:void navbar.go('back')\" \n");
  document.write ("   onMouseOver=\"return navbar.set('back')\"\n");
  document.write ("   onMouseOut=\"navbar.set('default')\"><img name=\"barBack\" src=\"" + this.back["default"].src + "\" height=\"55\" width=\"31\" border=0></a>");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<a href=\"javascript:void navbar.go('home')\" \n");
  document.write ("   onMouseOver=\"return navbar.set('home')\"\n");
  document.write ("   onMouseOut=\"navbar.set('default')\"><img name=\"barHome\" src=\"" + this.home["default"].src + "\" height=\"55\" width=\"38\" border=0></a>");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<a href=\"javascript:void navbar.go('next')\" \n");
  document.write ("   onMouseOver=\"return navbar.set('next')\"\n");
  document.write ("   onMouseOut=\"navbar.set('default')\"><img name=\"barNext\" src=\"" + this.next["default"].src + "\" height=\"55\" width=\"38\" border=0></a>");
  document.write ("</td>\n");

  document.write ("</tr></table>\n");
}


// Object: SubTitleBar
// 
// Parameters:
// banner_src - URL to the graphic of the text banner
// defaultText - URL to the graphic to fill in the text space
// backURL - URL to go to for a previous
// backText - URL to graphic to show for this
// homeURL - URL to go to for a home
// homeText - URL to graphic to show for this
function SubTitleBar (banner_src, defaultText, backURL, backText,
		          homeURL, homeText)
  {
    // Create a new object to hold the URLs
    this.URL = new Object;
    this.URL["back"] = backURL;
    this.URL["home"] = homeURL;

    // Set up class methods
    this.set = setSubBar;
    this.go = goSubBar;
    this.create = createSubBar;

    // Set up images for text area
    this.text = new Object;
    this.text["default"] = new Image;
    this.text["default"].src = defaultText;
    this.text["back"] = new Image;
    this.text["back"].src = backText;
    this.text["home"] = new Image;
    this.text["home"].src = homeText;

    // Set up images for buttons
    this.back = new Object;
    this.back["default"] = new Image;
    this.back["default"].src = "../graphics/button.back.default.gif";
    this.back["back"] = new Image;
    this.back["back"].src = "../graphics/button.back.on.back.gif";
    this.back["home"] = new Image;
    this.back["home"].src = "../graphics/button.back.on.home.gif";

    this.home = new Object;
    this.home["default"] = new Image;
    this.home["default"].src = "../graphics/button.home.sub.default.gif";
    this.home["back"] = new Image;
    this.home["back"].src = "../graphics/button.home.sub.on.back.gif";
    this.home["home"] = new Image;
    this.home["home"].src = "../graphics/button.home.sub.on.home.gif";

    this.next = new Object;
    this.next["default"] = new Image;
    this.next["default"].src = "../graphics/button.next.default.gif";
    this.next["home"] = new Image;
    this.next["home"].src = "../graphics/button.next.on.home.gif";
    this.next["back"] = new Image;
    this.next["back"].src = "../graphics/button.next.default.gif";

    // Set up basic Images to remember
    this.banner = new Image;
    this.banner.src = banner_src;
  }

function setSubBar (where)
  {
    if (document.Loaded)
      {
	// Set all graphics appropriately
	document.barText.src = this.text[where].src;
	document.barBack.src = this.back[where].src;
	document.barHome.src = this.home[where].src;

	// Set proper status message
	if (where == "home")
	  {
	    window.status = "Return to the Module List";
	  }
	else if (where == "back")
	  {
	    window.status = "Go back to: " + this.URL["back"];
	  }
	else // Default & error cases
	  {
	    window.status = "";
	  }

	return true;
      }

    return false;
  }

function goSubBar (where)
  {
    // If we have a prev/next/back THEN
    if (where == "home" || where=="back")
      {
	top.location = this.URL[where];
      }
    // ELSE treat it as a URL & pop it
    else
      {
	popup (this.URL[where], where);
      }
  }

function createSubBar ()
{
  document.write ("<table border=0 cellpadding=0 cellspacing=0 width=700>\n");
  document.write ("<tr>\n");

  document.write ("<td>");
  document.write ("<img src=\"" + this.banner.src + "\" height=\"55\" width=\"473\" border=\"0\">");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<img name=\"barText\" src=\"" + this.text["default"].src + "\" height=\"55\" width=\"151\" border=\"0\">");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<a href=\"javascript:void navbar.go('back')\" \n");
  document.write ("   onMouseOver=\"return navbar.set('back')\"\n");
  document.write ("   onMouseOut=\"navbar.set('default')\"><img name=\"barBack\" src=\"" + this.back["default"].src + "\" height=\"55\" width=\"31\" border=0></a>");
  document.write ("</td>\n");

  document.write ("<td>");
  document.write ("<a href=\"javascript:void navbar.go('home')\" \n");
  document.write ("   onMouseOver=\"return navbar.set('home')\"\n");
  document.write ("   onMouseOut=\"navbar.set('default')\"><img name=\"barHome\" src=\"" + this.home["default"].src + "\" height=\"55\" width=\"45\" border=0></a>");
  document.write ("</td>\n");

  document.write ("</tr></table>\n");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// setDefaultSrc: Set the default src for an image that uses MM_swapImage/Restore.
function setDefaultSrc() { //v3.0
  var i,j=0,x,a=setDefaultSrc.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; x.oSrc=a[i+2];x.src=x.oSrc;x.isSwapped=false;}
}

// Yet another popup window library.

// Used by the parent window to create a child.
function STSCI_openMBrWindow(theURL,winName,features) {
  if (document.STScI_popupsState[winName]) {
    if (document.STScI_popupsState[winName] == "open") {
	  if (document.STScI_popups[winName].close)
        document.STScI_popups[winName].close();
	}
  }
  document.STScI_popups[winName] = window.open(theURL,winName,features);
  document.MM_returnValue = false;
}

// Used by the parent window to close all children.
// Typically found in the body.onUnload attribute.
function STSCI_closeMBrWindows() {
  for (var i in document.STScI_popups) {
    if (document.STScI_popupsState[i] == "open") {
      document.STScI_popups[i].close();
	}
  }
  document.MM_returnValue = false;
}

// Used by the child to let the parent know it is closing.
// Typically found in the body.onUnload attribute.
function STScI_windowClose() {
  if (window.opener)
    if (window.opener.setClose)
      window.opener.setClose(window.name);
}

// Used by the child to let the parent know it has actually opened.
// Typically found in the body.onLoad attribute.
function STScI_windowOpen() {
  if (window.opener)
    if (window.opener.setOpen)
	  window.opener.setOpen(window.name);
}

// Auxillary function called by the child in the parent.
function setOpen(winName) {
  document.STScI_popupsState[winName] = "open";
}

// Auxillary function called by the child in the parent.
function setClose(winName) {
  document.STScI_popupsState[winName] = "close";
}

// Global initialization.
document.STScI_popups = new Array;
document.STScI_popupsState = new Array;

var workImage = new Object;
var popUps = new Object;
workImage.IsLoaded = false;
