/* NOT-SO-USER-DEFINABLE PARAMETERS. */
var onesecond = 60;  // each time unit == 1/60 sec.

var jsversn_1p1 = false;
var browserName = navigator.appName.substring(0,8);
var browserVer = parseFloat(navigator.appVersion);

if ((browserName == 'Netscape' && browserVer >= 3.0) ||
    (browserName == 'Microsof' && browserVer >= 4.0))
  jsversn_1p1 = true;

/* ** FUNCTIONS OF CLASS FLIPLINKFORMAT ** */

function FlipLinkFormat_set_colorstyles( normaltextcol, normalbackgroundcol,
					 activetextcol, activebackgroundcol)
{ // All arguments are objects of class ColorStyle.
  this.ntextcol.copy( normaltextcol);
  this.nbgcol.copy( normalbackgroundcol);
  this.atextcol.copy( activetextcol);
  this.abgcol.copy( activebackgroundcol);
}

function FlipLinkFormat_set_colorstrings( normaltextcolstr, normalbackgroundcolstr,
					  activetextcolstr, activebackgroundcolstr)
{ // All arguments are strings of form "#000000".
  this.ntextcol.set_color_string( normaltextcolstr);
  this.nbgcol.set_color_string( normalbackgroundcolstr);
  this.atextcol.set_color_string( activetextcolstr);
  this.abgcol.set_color_string( activebackgroundcolstr);
}

function FlipLinkFormat( time_initdelay, time_display)
{ /* CONSTRUCTOR */
  this.time_initdelay = time_initdelay;
  this.time_display = time_display;
  this.ntextcol = new ColorStyle();
  this.nbgcol = new ColorStyle();
  this.atextcol = new ColorStyle();
  this.abgcol = new ColorStyle();
}

/* Member Functions of Class FlipLinkFormat */
FlipLinkFormat.prototype.set_colorstyles = FlipLinkFormat_set_colorstyles;
FlipLinkFormat.prototype.set_colorstrings = FlipLinkFormat_set_colorstrings;

/* ** MEMBER FUNCTIONS OF CLASS FLIPLINK ** */

function getFlipLink( win, divid, layerid)
{ // Returns a reference to relevant HTML element: ilayer (for NS4), otherwise DIV.
  // divid is id (string) of text area's enclosing DIV within document. 
  // layerid is id (string) of text area's enclosing ilayer (for NS4).
  // In NS4, this function may return NULL if document is not yet loaded.
  if (document.all && divid != null && divid != '')  /* IE4 */
    return win.document.all[divid];
  else if (document.getElementById && divid != null && divid != '')  /* NS6 */
    return win.document.getElementById(divid);
  else if (document.layers && layerid != null && layerid != '') /* NS4 */
    return win.document.layers[layerid];
  else
    return null;
}

function FlipLink_set_format( fliplinkformat)
{ this.format = fliplinkformat; }

function FlipLink_flip()
{
  var newcolstr, newbgcolstr;
  var lay1;

  if (this.colormode >= 1) // Flip on
    {
      newcolstr = this.format.atextcol.colorstring;
      newbgcolstr = this.format.abgcol.colorstring;
    }
  else if (this.colormode == 0) // Flip off
    {
      newcolstr = this.format.ntextcol.colorstring;
      newbgcolstr = this.format.nbgcol.colorstring;
    }

  if (document.all || document.getElementById)
    {
      this.style.color = newcolstr;
      this.style.backgroundColor = newbgcolstr;
    }
  else if (document.layers) /* NS4 */
    { // In NS4, we use extra layer (embedded within an ilayer.)
      lay1 = this.document.layers[0];
      lay1.bgColor= newbgcolstr;
    }
}

function newFlipLink( winname, divid, layerid)
{ // This functions like "constructor" of FlipLink object (not true constructor.)
  // divid is id (string) of caption's enclosing DIV within document. 
  // layerid is id (string) of caption's enclosing ilayer (for NS4). 
  // Winname is name of window with FlipLink in it (example: "window","parent".)
  // Returns reference to initialized object.
  var newlink, win;

  win = eval( winname);

  if (document.all && divid != null && divid != "")  /* IE4 */
    {
      newlink = win.document.all[divid];
      newlink.myhome = winname+".document.all."+divid;
    }
  else if (document.getElementById && divid != null && divid != "")
    {
      newlink = win.document.getElementById(divid);
      newlink.myhome = winname+".document.getElementById(\""+divid+"\")";
    }
  else if (document.layers && layerid != null && layerid != "") /* NS4 */
    {
      newlink = win.document.layers[layerid];
      if (newlink == null) return null; // In NS4, document not yet loaded.
      newlink.myhome = winname+".document.layers."+layerid;
    }

  newlink.mywin = win;
  newlink.colormode = 0;  // 0 is normal, 1 is active (mouseover.)
  newlink.format = null;

  // Member functions.
  newlink.set_format = FlipLink_set_format;
  newlink.flip = FlipLink_flip;

  newlink.initialized = true;

  return newlink;
}

function fliplinkon( winname, divid, layerid, format)
{ // divid is id (string) of text area's enclosing DIV within document. 
  // layerid is id (string) of text area's enclosing ilayer (for NS4).
  // winname is name of window with TextArea in it (example: "window","parent".)
  var linkobj, win;
  win = eval( winname);

  if (document.all && divid != null && divid != '')  /* IE4 */
    linkobj = win.document.all[divid];
  else if (document.getElementById && divid != null && divid != '')  /* NS6 */
    linkobj = win.document.getElementById(divid);
  else if (document.layers && layerid != null && layerid != '') /* NS4 */
    linkobj = win.document.layers[layerid];

  if (jsversn_1p1 == false) return;

  if (linkobj == null || linkobj.initialized == null)
    { // Not initialized. Initialize via pseudo-constructor.
      linkobj = newFlipLink( winname, divid, layerid);
      if (linkobj == null) return;  // In NS4, document not yet loaded.
    }

  linkobj.set_format( format);

  // Mode 0 is normal, 1 is active (mouseover.)
  if (linkobj.colormode == 0)
    {
      linkobj.colormode = 1;
      if (linkobj.format.time_initdelay > 0) // delay before start of fade up
	  linkobj.timeup =
	      setTimeout(linkobj.myhome+".flip();",
			 Math.floor((linkobj.format.time_initdelay*1000)/onesecond));
      else // go now
	  linkobj.flip();
    }
}

function fliplinkoff( winname, divid, layerid)
{ // divid is id (string) of text area's enclosing DIV within document. 
  // layerid is id (string) of text area's enclosing ilayer (for NS4).
  // Winname is name of window with TextArea in it (example: "window","parent".)
  var linkobj, win;
  win = eval( winname);

  if (document.all && divid != null && divid != '')  /* IE4 */
    linkobj = win.document.all[divid];
  else if (document.getElementById && divid != null && divid != '')  /* NS6 */
    linkobj = win.document.getElementById(divid);
  else if (document.layers && layerid != null && layerid != '') /* NS4 */
    linkobj = win.document.layers[layerid];

  if (jsversn_1p1 == false) return;

  if (linkobj == null || linkobj.initialized == null)
    { // Not initialized. Initialize via pseudo-constructor.
      linkobj = newFlipLink( winname, divid, layerid);
      if (linkobj == null) return;  // In NS4, document not yet loaded.
    }

  if (linkobj.timeup != null)
    {
      clearTimeout( linkobj.timeup);
      linkobj.timeup = null;
      if (linkobj.colormode >= 1)
	linkobj.colormode = 0; // stopped delayed flipon from starting
      else
	linkobj.colormode = 1; // prevented auto-flip-off
    }

  linkobj.colormode = 0; // Fade down
  linkobj.flip();
}

