// NOTES:
// We have a race condition... if two mouseovers happen roughly at the same time
// they'll both start the timers simultaneously, and the wrong one might end up
// finishing last.  to avoid this, we probably need to bring back the 'onmouseout'
// handler, and perhaps keep a set of global flags indicating if the mouse is
// currently over the desired link.

// Starting and finishing positions each moving graphic.
var topstarts   = new Array(5);
var topfinishes = new Array(5);
topstarts[0] = 250; topfinishes[0] = 250;
topstarts[1] = 250; topfinishes[1] = 250;
topstarts[2] = 330; topfinishes[2] = 270;
topstarts[3] = 380; topfinishes[3] = 290;
topstarts[4] = 330; topfinishes[4] = 270;

var leftstarts   = new Array(5);
var leftfinishes = new Array(5);
leftstarts[0] = 550; leftfinishes[0] = 520;
leftstarts[1] = 672; leftfinishes[1] = 576;
leftstarts[2] = 702; leftfinishes[2] = 576;
leftstarts[3] = 611; leftfinishes[3] = 544;
leftstarts[4] = 520; leftfinishes[4] = 520;

var widthstart  = 91;
var heightstart = 65;
var widthfinish = 224;
var heightfinish = 160;

// If we begin moving an object, store its current position; if we start moving
// something a different direction, we can go from where we left off.
var cursteps    = new Array(6);

// To avoid race conditions, we keep a running global 'operation number' for each
// graphic.  When a timer expires, we don't execute the operation unless we're
// on the most recent operation.
var currentops = new Array(6);

// Initialize tracking variables.
for (i = 0; i < 6; i++) {
   cursteps[i] = 0;
   currentops[i] = 0;
}

// This function sets the opacity of a given object to the given value (0-100).
function setObjectOpacity(objnum, curstep, opacity)
{ 
   var linkid = 'link' + objnum;
   var object = document.getElementById(linkid).style; 
   cursteps[objnum - 1] = curstep;
   
   // Different browsers use a different attribute for opacity.
   object.opacity      = (opacity / 100); // CSS3, Mozilla, Safari, Opera
   object.MozOpacity   = (opacity / 100); // Older Mozilla browsers
   object.KhtmlOpacity = (opacity / 100); // Konqueror, Safari
   object.filter       = "alpha(opacity=" + opacity + ")";  // Internet Explorer
}

// This function sets the size, position, and opacity of an object to the given
// values.  To move an object's position, we have to move its containing DIV,
// so we require both IDs.
function setObjectPosition(id, divid, top, left, width, height, zindex)
{
   var object = document.getElementById(id).style; 
   var divobject = document.getElementById(divid).style; 

   divobject.top = top + 'px';
   divobject.left = left + 'px';
   divobject.width = width + 'px';
   divobject.height = height + 'px';
   divobject.zIndex = zindex;
   object.width = width + 'px';
   object.height = height + 'px';
}

function setLinkParms(objnum, curstep, currentop, top, left, width, height, linkopacity, zindex)
{
   var id = 'graphic' + objnum;
   var divid = 'divgraphic' + objnum;
   var linkid = 'link' + objnum;

   if (currentop == currentops[objnum - 1]) {
      setObjectOpacity(objnum, curstep, linkopacity);
      setObjectPosition(id, divid, top, left, width, height, zindex);
   }
}
   
function resetObjects()
{
   setObjectOpacity(1, 0, 50);
   setObjectOpacity(2, 0, 50);
   setObjectOpacity(3, 0, 50);
   setObjectOpacity(4, 0, 50);
   setObjectOpacity(5, 0, 50);
   setObjectOpacity(6, 0, 50);

   setObjectPosition('graphic1', 'divgraphic1', topstarts[0], leftstarts[0], widthstart, heightstart, 0);
   setObjectPosition('graphic2', 'divgraphic2', topstarts[1], leftstarts[1], widthstart, heightstart, 0);
   setObjectPosition('graphic3', 'divgraphic3', topstarts[2], leftstarts[2], widthstart, heightstart, 0);
   setObjectPosition('graphic4', 'divgraphic4', topstarts[3], leftstarts[3], widthstart, heightstart, 0);
   setObjectPosition('graphic5', 'divgraphic5', topstarts[4], leftstarts[4], widthstart, heightstart, 0);

   cursteps[0] = 0; currentops[0] = 0;
   cursteps[1] = 0; currentops[1] = 0;
   cursteps[2] = 0; currentops[2] = 0;
   cursteps[3] = 0; currentops[3] = 0;
   cursteps[4] = 0; currentops[4] = 0;
   cursteps[5] = 0; currentops[5] = 0;
}
  
function fadeAndGrowObject(objnum, inout, speed)
{
   var topstart;
   var leftstart;

   var topfinish;
   var leftfinish;

   var top;
   var left;
   var width;
   var height;

   var linkopacity;
   var zindex;

   var istart;
   var ifinish;
   var iincr;

   currentops[objnum - 1] = currentops[objnum - 1] + 1;
   if (currentops[objnum - 1] > 9999) { currentops[objnum - 1] = 0; }

   topstart = topstarts[objnum - 1];
   leftstart = leftstarts[objnum - 1];

   topfinish = topfinishes[objnum - 1];
   leftfinish = leftfinishes[objnum - 1];

   var currentop = currentops[objnum - 1];
   var istart = cursteps[objnum - 1];
   if (inout == 1) {
      ifinish = 50;
      iincr   = 1;
   }
   else {
      ifinish = 0;
      iincr   = -1;
   }

   for (i = istart; (i >= 0) && (i <= 50); i += iincr) {
      var itime = i - istart;
      if (iincr == -1) { itime = istart - i; }

      top    = (topstart + Math.round(((topfinish - topstart) * i) / 50));
      left   = (leftstart + Math.round(((leftfinish - leftstart) * i) / 50));
      width  = (widthstart + Math.round(((widthfinish - widthstart) * i) / 50));
      height = (heightstart + Math.round(((heightfinish - heightstart) * i) / 50));
      linkopacity = 50 + i;
      zindex = Math.round(i / 10);
      var parms = "'" + objnum + "'," + i + "," + currentop + "," + top + "," + left + "," + 
                        width + "," + height + "," + linkopacity + "," + zindex;
      setTimeout("setLinkParms(" + parms + ")", itime * speed);
   }
}

function fadeObject(objnum, inout, speed)
{
   var linkopacity;

   var istart;
   var ifinish;
   var iincr;

   currentops[objnum - 1] = currentops[objnum - 1] + 1;
   if (currentops[objnum - 1] > 9999) { currentops[objnum - 1] = 0; }

   var currentop = currentops[objnum - 1];
   var istart = cursteps[objnum - 1];
   if (inout == 1) {
      ifinish = 50;
      iincr   = 1;
   }
   else {
      ifinish = 0;
      iincr   = -1;
   }

   for (i = istart; (i >= 0) && (i <= 50); i += iincr) {
      var itime = i - istart;
      if (iincr == -1) { itime = istart - i; }

      linkopacity = 50 + i;
      var parms = objnum + "," + i + "," + linkopacity;
      setTimeout("setObjectOpacity(" + parms + ")", itime * speed);
   }
}
