/* Javascript functions that control "rollover" between two versions of 
   thumbnail images ("unlit" and "lit") when the mouse cursor moves over
   or off the thumbnail.
   This feature only works in JavaScript 1.1 or later.
*/
/* *** CODE WRITTEN BY FRANK PETTIT, COPYRIGHT 2001 FRANK K. PETTIT. *** */

/* ** THUMBNAIL CAPTION FADE-IN AND FADE-OUT FUNCTIONS.** */
/* USER-DEFINABLE PARAMETERS. */
// This number divided by 60 equals number of seconds to fade up the caption.
var numstp_fadeup = 60;
var numstp_fadedown = 60; // This #/60 == # of sec. to fade down.
var numstp_initdelay = 22; // Delay before caption fadeup begins. Used to be 45.
var numstp_display = 128; // How long to display before auto-fadeout.

var numstp_rollover = 22; // This #/60 == # of sec. before picture "rollover".

// NOT USER DEFINABLE:
var capclasscolor = new ColorStyle();  // color of caption text
var bgcol = new ColorStyle();  // color of background behind thumbnail
var border_offcolor = new ColorStyle(); // color of hyperlink border around thumbnail
var border_oncolor = new ColorStyle(); // color of border when mouse is over it.
var captionformat = null; // object of class FadeTextFormat shared by all captions.

function showcaption( img, captionid, layerid, content, state)
{ // img is image object, captionid is id (string) of caption's enclosing
  // DIV within document. layerid is id (string) of caption's enclosing layer
  // (for NS4). content is text of caption (only has effect in NS4.)
  // state is 1 (make visible) or 0 (make invisible).
  var captionobj;  // object of class FadeTextArea.

  if (captionformat == null)
    {
      captionformat = new FadeTextFormat( numstp_initdelay, numstp_fadeup,
					  numstp_display, numstp_fadedown);

      /* Initialize BACKGROUND and CAPTION colors from STYLE SHEET. */
      // STYLE SHEET: Rule 1 is for links, Rule 4 is for class .thumbnail,
      // Rule 10 is for class .tnimgcaption
      capclasscolor.set_color_style( "tnimgcaption", 10);
      bgcol.set_background_style( "thumbnail", 4);
      border_oncolor.set_color_style( "A:link", 1);

      border_offcolor.set_color_style( "A:visited", 2);

      captionformat.set_colorstyles( capclasscolor, bgcol, "tnimgcaption",
				     "<FONT SIZE=-1><EM>", "</EM></FONT>");
    }

  if (img == null || img.captionobj == null)
    { // Normally this will only execute FIRST time showcaption is called
      captionobj = getFadeTextArea( window, captionid, layerid);

      if (captionobj == null || captionobj.initialized == null)
	{
	  captionobj = newFadeTextArea( 'window', captionid, layerid);
	  if (captionobj == null) return;  // In NS4, document not yet loaded.
	  captionobj.set_format( captionformat);
	  captionobj.set_content( content);
	}
    }
  else
    // This will execute second, third+ times function is called.
    captionobj = img.captionobj;

  // Display caption in Status Bar:
  if (state == 1)
    if (content != null && content != "")
      window.status = "Photo: " + content;
    else
      window.status = "Click to View Larger Picture";
  else
    window.status = "";  // mouseoff

  if (captionobj == null || jsversn_1p1 == false) return;

  if (img != null && img.captionobj == null)
    img.captionobj = captionobj;

  if (state == 1)
    captionobj.fadeup();
  else
    captionobj.fadedown();
}

/* IMAGE ROLLOVER FUNCTIONS */

var litimages; // These used to force browser to store images in cache.

if (jsversn_1p1 == true)
  {
    litimages = new Array();
     // This is necessary in NS4 for SGI.
    if (litimages.length == null) litimages.length = 0;
  }

function stripserver( srcname)
{ // This functions strips off the name of the server added to URL's.
  var slashpos, httppos;

  httppos = srcname.indexOf("://");
  if (httppos != -1)
    {
      slashpos = srcname.indexOf( "/", httppos+3);
      return (slashpos == -1) ? "" : srcname.substring(slashpos,srcname.length);
    }
  // do we have servername in front but not preceded by "http://"?
  slashpos = srcname.indexOf( "/", 0);
  if (srcname.substring( 0, slashpos).indexOf(".") != -1)
    return srcname.substring( slashpos, srcname.length);
  else
    return srcname;
}

function loadlitpic( img, litpicsrc)
{ // After the HTML document in loaded by the Web browser, all "unlit" pictures
  // should be displayed. Here we use javascript to PRE-LOAD "lit" picture
  // into the browser's cache memory; that way, later, when user's mouse cursor is
  // over a photo, switching from "unlit" to "lit" will be instantaneous.
  // img should be the Image object (initial state).
  // litpicsrc is URL of "lit" version.
  // If litpicsrc is null, empty string, or == img.src, then this image
  // will not "flip" between lit and unlit versions.
  if (jsversn_1p1 == false || img == null ||
      (img.loaded != null && img.loaded == true))
    return;

  img.loaded = false;

  if (img.initpicsrc == null)
    img.initpicsrc = stripserver( img.src);

  if (litpicsrc != null && litpicsrc != "" &&
      stripserver(litpicsrc) != img.initpicsrc)
    { // This picture will "flip" when mouse is over it.
      img.flipping = true;

      // Now pre-load "lit" picture into browser's cache.
      var litimg = new Image();
      litimg.src = litpicsrc;
      litimages.length += 1;
      litimages[ litimages.length-1] = litimg;
    }
  else
    img.flipping = false;  // Flipping is disabled.

  img.loaded = true;

  return;
}

function flippik( imgid, img_link, captionid, layerid, litpicsrc, captionstr)
{ // This function will "light up" thumbnail image when mouse cursor is over it,
  // (that only works in JavaScript 1.1), that is, replace thumbnail image
  // with new image whose filename is litpicsrc.
  // Argument imgid should be the name of the Image object within document.
  // img_link argument should be the Link object that wraps it.
  // If litpicsrc is null or empty string or same as img.src,
  // then image flipping is disabled, BUT in Internet Explorer / NS6 ONLY,
  // the border of the image will change color when mouse is over it.
  // captionid should be the ID of an HTML tag (<DIV> or <SPAN>) whose
  // content is the caption: it will fade from invisible to black print
  // when mouse is over image.
  // If the argument captionstr is not null or an empty string, then it will
  // be displayed in the status bar when mouse is over image (Netscape only).
  /* Make Caption Visible. */
  var img = window.document[imgid];

  showcaption( img, captionid, layerid, captionstr, 1);

  if (jsversn_1p1 == false || img == null) return true;

  if (img.initpicsrc == null)
    img.initpicsrc = stripserver( img.src);

  if (litpicsrc != null && litpicsrc != "" &&
      stripserver(litpicsrc) != img.initpicsrc)
    { // This picture will rollover when mouse is over it.
      img.flipping = true;

      if (numstp_rollover <= 0) // IMMEDIATE ROLLOVER.
	{
	  img.src = litpicsrc;
	  img.loaded = true;
	}
      else // SHORT DELAY BEFORE ROLLOVER
	{ 
	  loadlitpic( img, litpicsrc); // Use delay to START PRE-LOADING image
	  img.timeup =
	    setTimeout("document[\'"+imgid+"\'].src = \'"+litpicsrc+"\'; "+
		       "document[\'"+imgid+"\'].loaded = true; ",
		       Math.floor((numstp_rollover*1000)/onesecond));
	}
    }
  else if (document.all || document.getElementById) // IE4 or NS6
    img.style.borderColor = border_oncolor.colorstring; // from Style Sheet

  return true; // prevents browser from overwriting status bar message
}

function unflippik( imgid)
{ // When mouse pointer moves off link, this resets status bar to nothing.
  // It also "unlights" a lighted-up thumbnail image (in JS 1.1).
  // Argument imgid should be the name of the Image object within document.
  var img = document[imgid];

  showcaption( img, '', '', '', 0);

  if (jsversn_1p1 == false || img == null) return true;

  if (img.timeup != null)
    { // Mouseon started delayed rollover; mouseoff cancels it.
      clearTimeout(img.timeup);
      img.timeup = null;
    }

  if (img.flipping != null && img.flipping == true &&
      img.initpicsrc != null)
    img.src = img.initpicsrc;
  else if (document.all || document.getElementById) // IE4 or NS6
    img.style.borderColor = border_offcolor.colorstring;  // from Style Sheet

  return true; // prevents browser from overwriting status bar.
}
