// Author: Alan Nanut, ATS, York University

// No modification to this file is necessary
// for initialization purposes


// constants
var THUMB_SRC = 0;
var THUMB_W = 1;
var THUMB_H = 2;
var THUMB_SX = 3;
var THUMB_PX = 4;
var THUMB_SY = 5;
var THUMB_PY = 6;
var THUMB_TI = 7;
var THUMB_LI = 8;

// CAPTION FLAG: 
// 0 = caption only, 
// 1 = caption and image, 
// 2 = image only, 
// 3 = caption/image coords. separate
var THUMB_CF = 9;

var THUMB_WF = 10;
var THUMB_GALL = 11;
var THUMB_CX = 12;
var THUMB_CY = 13;
var THUMB_CTAG = 14;
var THUMB_LYR = 15;
var THUMB_IMG = 16;
var THUMB_TLYR = 17;
var THUMB_TIMG = 18;
var THUMB_INCX = 19;
var THUMB_INCY = 20;

var GALL_LEFT = 0;
var GALL_TOP = 1;
var GALL_LYR = 2
var GALL_IMG = 3;
var GALL_ILYR = 4;
var GALL_IIMG = 5;
var GALL_CLYR = 6;
var GALL_CF = 7;
var GALL_L = 8;
var GALL_CX = 10;
var GALL_CY = 11;
var GALL_VIS = 12;
var GALL_W = 13;
var GALL_CL = 14;
var GALL_CR = 15;


var iThumbFields = 23;
var iGallFields = 16;


// gallery timer
var GALL_timer = null;

// thumbnail data
var iThumbIndex = 0;
var iThumbWidth = 100;
var iThumbHeight = 0;
var iThumbSize = 100;
var iThumbTics = 0;
var iThumbGap = 20;
var iThumbOpacity = 10;
var iThumbOpacityInc = 10;
var iThumbOffY = 230;
var iArrowSize;
var iCapWidth = 200;
var iMaxTics = 15;
var iThumbs;
var iThumbFade = 1;
var iGallInit = 0;
var stThumbs;
var stFrames;

// gallery data
var iGall;
var iGalls;
var stGalls;


/************************* IMAGE GALL ROUTINES */

function GALL_update_pos ()
{
  stThumbs[iThumbIndex][THUMB_PX] += stThumbs[iThumbIndex][THUMB_LI];
  stThumbs[iThumbIndex][THUMB_PY] += stThumbs[iThumbIndex][THUMB_TI];

  if (stThumbs[iThumbIndex][THUMB_WF])
  {
    if (iThumbWidth < stThumbs[iThumbIndex][THUMB_W])
    {
      iThumbWidth += stThumbs[iThumbIndex][THUMB_INCX];
      iThumbHeight += stThumbs[iThumbIndex][THUMB_INCY];
      if (iThumbWidth < stThumbs[iThumbIndex][THUMB_W])
      {
        // adjust new limits and locations for width (center image)
        stThumbs[iThumbIndex][THUMB_PX] -= stThumbs[iThumbIndex][THUMB_INCX] / 2;
        stThumbs[iThumbIndex][THUMB_PY] -= stThumbs[iThumbIndex][THUMB_INCY] / 2;
      }
      else if (iThumbWidth > stThumbs[iThumbIndex][THUMB_W])
      {
        // adjust new limits and locations for width (center image)
        stThumbs[iThumbIndex][THUMB_PX] -= stThumbs[iThumbIndex][THUMB_INCX] / 2;
        stThumbs[iThumbIndex][THUMB_PY] -= stThumbs[iThumbIndex][THUMB_INCY] / 2;
        iThumbWidth = stThumbs[iThumbIndex][THUMB_W];
      }
    }
  }

  if (use_features == 1)
  {
    if (stThumbs[iThumbIndex][THUMB_WF])
    {
      stGalls[iGall][GALL_IIMG].width = iThumbWidth;
      stGalls[iGall][GALL_IIMG].height = iThumbHeight;
    }

    stGalls[iGall][GALL_IIMG].style.left = stThumbs[iThumbIndex][THUMB_PX];
    stGalls[iGall][GALL_IIMG].style.top = stThumbs[iThumbIndex][THUMB_PY];
    if (iThumbFade && ie)
    {
      iThumbOpacity += iThumbOpacityInc;
      setOpacity (stGalls, GALL_IIMG, iThumbOpacity, iGall, iGall);
    }
  }
  else if (use_features == 2)
  {
    stGalls[iGall][GALL_ILYR].left = stThumbs[iThumbIndex][THUMB_PX];
    stGalls[iGall][GALL_ILYR].top = stThumbs[iThumbIndex][THUMB_PY];
  }

}


function GALL_showText ()
{
  if (use_features == 1)
  {
    stGalls[iGall][GALL_CLYR].innerHTML = stThumbs[iThumbIndex][THUMB_CTAG];
    stGalls[iGall][GALL_CLYR].style.visibility = set_show;
  }
  else if (use_features == 2)
  {
    stGalls[iGall][GALL_CLYR].document.open ();
    stGalls[iGall][GALL_CLYR].document.write (stThumbs[iThumbIndex][THUMB_CTAG]);
    stGalls[iGall][GALL_CLYR].document.close ();
    stGalls[iGall][GALL_CLYR].visibility = set_show;
  }
  GALL_end (0);
}



function GALL_update ()
{
  // if not caption only flag, update thumbnail frame
  if (stThumbs[iThumbIndex][THUMB_CF])
  {
    if (iThumbTics < iMaxTics)
      GALL_update_pos ();
    else if (stThumbs[iThumbIndex][THUMB_CF] == 1 || stThumbs[iThumbIndex][THUMB_CF] == 3)
      GALL_showText ();
  }
  else
    GALL_showText ();

  if (iThumbTics < iMaxTics)
    iThumbTics++;
}


function GALL_right (iGall)
{
  var iIndex;
  var iCycle;
  var iPos = 0;

  iIndex = stGalls[iGall][GALL_L];

  if (use_features == 1)
  {
    stThumbs[iIndex][THUMB_IMG].style.visibility = set_hide;
    stThumbs[iIndex][THUMB_TIMG].style.visibility = set_hide;
  }
  else if (use_features == 2)
  {
    stThumbs[iIndex][THUMB_LYR].visibility = set_hide;
    stThumbs[iIndex][THUMB_TLYR].visibility = set_hide;
  }

  for (iCycle = 0; iCycle < stGalls[iGall][GALL_VIS]; iCycle++)
  {
    iIndex = (iIndex + 1) % iThumbs;
    if (iCycle == 0)
      stGalls[iGall][GALL_L] = iIndex;

    stThumbs[iIndex][THUMB_SX] = stGalls[iGall][GALL_LEFT] + iPos;
    if (use_features == 1)
      stThumbs[iIndex][THUMB_LI] = -(stThumbs[iIndex][THUMB_SX] + iThumbSize / 2 - stGalls[iGall][GALL_CX]) / iMaxTics;
    else if (use_features == 2)
      stThumbs[iIndex][THUMB_LI] = -(stThumbs[iIndex][THUMB_SX] + stThumbs[iIndex][THUMB_W] / 2 - stGalls[iGall][GALL_CX]);

    if (use_features == 1)
    {
      stThumbs[iIndex][THUMB_IMG].style.visibility = set_show;
      stThumbs[iIndex][THUMB_TIMG].style.visibility = set_show;
      stThumbs[iIndex][THUMB_IMG].style.left = stThumbs[iIndex][THUMB_SX];
      stThumbs[iIndex][THUMB_TIMG].style.left = stThumbs[iIndex][THUMB_SX];
    }
    else if (use_features == 2)
    {
      stThumbs[iIndex][THUMB_LYR].visibility = set_show;
      stThumbs[iIndex][THUMB_TLYR].visibility = set_show;
      stThumbs[iIndex][THUMB_LYR].left = stThumbs[iIndex][THUMB_SX];
      stThumbs[iIndex][THUMB_TLYR].left = stThumbs[iIndex][THUMB_SX];
    }

    iPos += iThumbSize + iThumbGap;
  }
}




function GALL_left (iGall)
{
  var iIndex = 0;
  var iCycle;
  var iPos = 0;

  iIndex = stGalls[iGall][GALL_L] - 1;
  if (iIndex < 0)
    iIndex += iThumbs;

  for (iCycle = 0; iCycle < stGalls[iGall][GALL_VIS]; iCycle++)
  {
    if (iCycle == 0)
      stGalls[iGall][GALL_L] = iIndex;

    stThumbs[iIndex][THUMB_SX] = stGalls[iGall][GALL_LEFT] + iPos;
    if (use_features == 1)
      stThumbs[iIndex][THUMB_LI] = -(stThumbs[iIndex][THUMB_SX] + iThumbSize / 2 - stGalls[iGall][GALL_CX]) / iMaxTics;
    else if (use_features == 2)
      stThumbs[iIndex][THUMB_LI] = -(stThumbs[iIndex][THUMB_SX] + stThumbs[iIndex][THUMB_W] / 2 - stGalls[iGall][GALL_CX]);

    if (use_features == 1)
    {
      stThumbs[iIndex][THUMB_IMG].style.visibility = set_show;
      stThumbs[iIndex][THUMB_TIMG].style.visibility = set_show;
      stThumbs[iIndex][THUMB_IMG].style.left = stThumbs[iIndex][THUMB_SX];
      stThumbs[iIndex][THUMB_TIMG].style.left = stThumbs[iIndex][THUMB_SX];
    }
    else if (use_features == 2)
    {
      stThumbs[iIndex][THUMB_LYR].visibility = set_show;
      stThumbs[iIndex][THUMB_TLYR].visibility = set_show;
      stThumbs[iIndex][THUMB_LYR].left = stThumbs[iIndex][THUMB_SX];
      stThumbs[iIndex][THUMB_TLYR].left = stThumbs[iIndex][THUMB_SX];
    }

    iPos += iThumbSize + iThumbGap;
    iIndex = (iIndex + 1) % iThumbs;
  }

  if (use_features == 1)
  {
    stThumbs[iIndex][THUMB_IMG].style.visibility = set_hide;
    stThumbs[iIndex][THUMB_TIMG].style.visibility = set_hide;
  }
  else if (use_features == 2)
  {
    stThumbs[iIndex][THUMB_LYR].visibility = set_hide;
    stThumbs[iIndex][THUMB_TLYR].visibility = set_hide;
  }
}






function GALL_start (iThumb)
{
  iThumb--;

  if (!iGallInit)
    return;

  if (stThumbs[iThumb][THUMB_CF] && !stFrames[iThumb].complete && (ie || use_features == 2))
    return;

  iThumbIndex = iThumb;
  iThumbWidth = iThumbSize;
  iThumbTics = 0;
  iGall = stThumbs[iThumbIndex][THUMB_GALL];


  if (stThumbs[iThumbIndex][THUMB_CF] != 2)
  {
    if (use_features == 1)
    {
      if (stThumbs[iThumbIndex][THUMB_CF] == 3 || !stThumbs[iThumb][THUMB_CF])
      {
        stGalls[iGall][GALL_CLYR].style.left = stThumbs[iThumbIndex][THUMB_CX];
        stGalls[iGall][GALL_CLYR].style.top = stThumbs[iThumbIndex][THUMB_CY];
      }
      else
      {
        stGalls[iGall][GALL_CLYR].style.left = stThumbs[iThumbIndex][THUMB_SX] + iMaxTics * stThumbs[iThumbIndex][THUMB_LI] + (iMaxTics * -stThumbs[iThumbIndex][THUMB_INCX] / 2) - (iCapWidth / 2 - stThumbs[iThumbIndex][THUMB_W] / 2);
        stGalls[iGall][GALL_CLYR].style.top = stThumbs[iThumbIndex][THUMB_SY] +  iMaxTics * stThumbs[iThumbIndex][THUMB_TI] + (iMaxTics * -stThumbs[iThumbIndex][THUMB_INCY] / 2) + stThumbs[iThumbIndex][THUMB_H];
      }
    }
    else if (use_features == 2)
    {
      if (stThumbs[iThumb][THUMB_CF] == 3 || !stThumbs[iThumb][THUMB_CF])
      {
        stGalls[iGall][GALL_CLYR].left = stThumbs[iThumbIndex][THUMB_CX];
        stGalls[iGall][GALL_CLYR].top = stThumbs[iThumbIndex][THUMB_CY];
      }
      else
      {
        stGalls[iGall][GALL_CLYR].left = stThumbs[iThumbIndex][THUMB_SX] + stThumbs[iThumbIndex][THUMB_LI] - (iCapWidth / 2 - stThumbs[iThumbIndex][THUMB_W] / 2);
        stGalls[iGall][GALL_CLYR].top = stThumbs[iThumbIndex][THUMB_SY] + stThumbs[iThumbIndex][THUMB_TI] + stThumbs[iThumbIndex][THUMB_H] + 5;
      }
    }
  }

  // if not caption only flag, set thumbnail frame
  if (stThumbs[iThumbIndex][THUMB_CF])
  {
    if (use_features == 1)
    {
      if (stThumbs[iThumbIndex][THUMB_WF])
      {
        stGalls[iGall][GALL_IIMG].width = iThumbWidth;
        iThumbHeight = iThumbSize / stThumbs[iThumbIndex][THUMB_W] * stThumbs[iThumbIndex][THUMB_H];
        stGalls[iGall][GALL_IIMG].height = iThumbHeight;
      }
      else
      {
        stGalls[iGall][GALL_IIMG].width = stThumbs[iThumbIndex][THUMB_W];
        stGalls[iGall][GALL_IIMG].height = stThumbs[iThumbIndex][THUMB_H];
      }

      stGalls[iGall][GALL_IIMG].src = stFrames[iThumbIndex].src;
      stGalls[iGall][GALL_IIMG].style.left = stThumbs[iThumbIndex][THUMB_PX] = stThumbs[iThumbIndex][THUMB_SX];
      stGalls[iGall][GALL_IIMG].style.top = stThumbs[iThumbIndex][THUMB_PY] = stThumbs[iThumbIndex][THUMB_SY];
      stGalls[iGall][GALL_IIMG].style.visibility = set_show;

      // give netscape a longer delay
      if (ns)
        GALL_timer = setInterval ("GALL_update ()", 60);
      else
        GALL_timer = setInterval ("GALL_update ()", 30);
    }
    else if (use_features == 2)
    {
      stGalls[iGall][GALL_ILYR].resizeTo (stThumbs[iThumbIndex][THUMB_W], stThumbs[iThumbIndex][THUMB_H]);
      stGalls[iGall][GALL_ILYR].left = stThumbs[iThumbIndex][THUMB_PX] = stThumbs[iThumbIndex][THUMB_SX] + stThumbs[iThumbIndex][THUMB_LI];
      stGalls[iGall][GALL_ILYR].top = stThumbs[iThumbIndex][THUMB_PY] = stThumbs[iThumbIndex][THUMB_SY] + stThumbs[iThumbIndex][THUMB_TI];
      stGalls[iGall][GALL_ILYR].background.src = stFrames[iThumbIndex].src;
      stGalls[iGall][GALL_ILYR].visibility = set_show;

      GALL_update ();
    }
  }
  else
    GALL_update ();
}



function GALL_end (iHide)
{
  if (!iGallInit)
    return;

  iGall = stThumbs[iThumbIndex][THUMB_GALL];
  iThumbOpacity = iThumbOpacityInc;

  if (use_features == 1)
  {
    if (GALL_timer != null)
    {
      clearInterval (GALL_timer);
      GALL_timer = null;
    }
  }

  if (iHide)
  {
    if (stThumbs[iThumbIndex][THUMB_CF])
    {
      // hide thumbnail image
      if (use_features == 1)
        stGalls[iGall][GALL_IIMG].style.visibility = set_hide;
      else if (use_features == 2)
        stGalls[iGall][GALL_ILYR].visibility = set_hide;
    }

    if (use_features == 1)
    {
      if (iThumbFade && ie)
        setOpacity (stGalls, GALL_IIMG, iThumbOpacity, iGall, iGall);
    }

    // hide caption text
    if (stThumbs[iThumbIndex][THUMB_CF] != 2)
    {
      if (use_features == 1)
        stGalls[iGall][GALL_CLYR].style.visibility = set_hide;
      else if (use_features == 2)
        stGalls[iGall][GALL_CLYR].visibility = set_hide;
    }
  }
}


function GALL_toggleFade ()
{
  var iGallIndex = iGall;
  var iThumb = iThumbIndex;

  if (useFade)
  {
    GALL_end (1);
    iThumbFade = 1 - iThumbFade;

    iThumbOpacity = iThumbOpacityInc;

    if (iThumbFade)
      setOpacity (stGalls, GALL_IIMG, iThumbOpacity, iGallIndex, iGallIndex);
    if (!iThumbFade)
      setOpacity (stGalls, GALL_IIMG, 100, iGallIndex, iGallIndex);

    GALL_start (iThumb);
  }
}


function GALL_init ()
{
  var iIndex;
  var iGallIndex;
  var iThumb;
  var sThumb;
  var sLayer;
  var sName;

  setBrowser ();

  if (!use_features)
    return;

  if (iThumbFade && !useFade)
    iThumbFade = 0;

  stFrames = new Array(iThumbs);

  iThumbOpacity = iThumbOpacityInc;

  // initialize image galleries
  for (iIndex = 0; iIndex < iGalls; iIndex++)
  {
    stGalls[iIndex][GALL_W] = stGalls[iIndex][GALL_VIS] * iThumbSize + (stGalls[iIndex][GALL_VIS] - 1) * iThumbGap;
    stGalls[iIndex][GALL_CX] = stGalls[iIndex][GALL_W] / 2 + stGalls[iIndex][GALL_LEFT];
    stGalls[iIndex][GALL_CY] = iThumbSize / 2 + stGalls[iIndex][GALL_TOP];

    if (stGalls[iIndex][GALL_CF])
    {
      // initialize caption layer
      sLayer = "caption_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_CLYR] = (use_features == 1) ? document.getElementById(sLayer) : document[sLayer];

      if (use_features == 1)
      {
        stGalls[iIndex][GALL_CLYR].style.position = "absolute";
        stGalls[iIndex][GALL_CLYR].style.visibility = set_hide;
        stGalls[iIndex][GALL_CLYR].style.zIndex = 4;
      }
      else if (use_features == 2)
      {
        stGalls[iIndex][GALL_CLYR].position = "absolute";
        stGalls[iIndex][GALL_CLYR].visibility = set_hide;
      }
    }

    if (use_features == 1)
    {
      sName = "gall_img" + (iIndex + 1);
      stGalls[iIndex][GALL_IMG] = (ns) ? document[sName] : document.all[sName];
      sName = "thumb_img" + (iIndex + 1);
      stGalls[iIndex][GALL_IIMG] = (ns) ? document[sName] : document.all[sName];

      stGalls[iIndex][GALL_IMG].style.position = "absolute";    
      stGalls[iIndex][GALL_IMG].style.left = stGalls[iIndex][GALL_LEFT];
      stGalls[iIndex][GALL_IMG].style.top = stGalls[iIndex][GALL_TOP];
      stGalls[iIndex][GALL_IMG].style.zIndex = 1;
      stGalls[iIndex][GALL_IMG].style.visibility = set_show;
      stGalls[iIndex][GALL_IIMG].style.position = "absolute";
      stGalls[iIndex][GALL_IIMG].style.zIndex = 3;

      sLayer = "left_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_CL] = (use_features == 1) ? document.getElementById(sLayer) : document[sLayer];
      sLayer = "right_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_CR] = (use_features == 1) ? document.getElementById(sLayer) : document[sLayer];

      stGalls[iIndex][GALL_CL].style.position = "absolute";
      stGalls[iIndex][GALL_CL].style.visibility = set_show;
      stGalls[iIndex][GALL_CL].style.left = stGalls[iIndex][GALL_LEFT] - (iArrowSize + iThumbGap);
      stGalls[iIndex][GALL_CL].style.top = stGalls[iIndex][GALL_TOP] + iArrowSize;
      stGalls[iIndex][GALL_CR].style.position = "absolute";
      stGalls[iIndex][GALL_CR].style.visibility = set_show;
      stGalls[iIndex][GALL_CR].style.left = stGalls[iIndex][GALL_LEFT] + stGalls[iIndex][GALL_W] + iThumbGap;
      stGalls[iIndex][GALL_CR].style.top = stGalls[iIndex][GALL_TOP] + iArrowSize;

      if (!iThumbFade && useFade)
        setOpacity (stGalls, GALL_IIMG, 100, iIndex, iIndex);
    }
    else if (use_features == 2)
    {
      sLayer = "gall_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_LYR] = (ns) ? document[sLayer] : document.all[sLayer].style;
      sLayer = "thumb_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_ILYR] = (ns) ? document[sLayer] : document.all[sLayer].style;

      stGalls[iIndex][GALL_ILYR].resizeTo (stThumbs[0][THUMB_W], stThumbs[0][THUMB_H]);
      stGalls[iIndex][GALL_LYR].position = "absolute";
      stGalls[iIndex][GALL_LYR].left = stGalls[iIndex][GALL_LEFT];
      stGalls[iIndex][GALL_LYR].top = stGalls[iIndex][GALL_TOP];
      stGalls[iIndex][GALL_LYR].visibility = set_show;

      sLayer = "left_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_CL] = (ns) ? document[sLayer] : document.all[sLayer].style;
      sLayer = "right_layer" + (iIndex + 1);
      stGalls[iIndex][GALL_CR] = (ns) ? document[sLayer] : document.all[sLayer].style;

      stGalls[iIndex][GALL_CL].position = "absolute";
      stGalls[iIndex][GALL_CL].visibility = set_show;
      stGalls[iIndex][GALL_CL].left = stGalls[iIndex][GALL_LEFT] - (iArrowSize + iThumbGap);
      stGalls[iIndex][GALL_CL].top = stGalls[iIndex][GALL_TOP] + iArrowSize;
      stGalls[iIndex][GALL_CR].position = "absolute";
      stGalls[iIndex][GALL_CR].visibility = set_show;
      stGalls[iIndex][GALL_CR].left = stGalls[iIndex][GALL_LEFT] + stGalls[iIndex][GALL_W] + iThumbGap;
      stGalls[iIndex][GALL_CR].top = stGalls[iIndex][GALL_TOP] + iArrowSize;
    }
  }


  // initialize thumbnails
  iGallIndex = stThumbs[0][THUMB_GALL];
  stGalls[0][GALL_L] = 0;
  iIndex = -(iThumbSize + iThumbGap);
  for (iThumb = 0; iThumb < iThumbs; iThumb++)
  {
    // ignore further initialization for this thumbnail (text captions only)
    if (!stThumbs[iThumb][THUMB_CF])
      continue;

    iThumbHeight = iThumbSize / stThumbs[iThumb][THUMB_W] * stThumbs[iThumb][THUMB_H];
    stThumbs[iThumb][THUMB_INCX] = (stThumbs[iThumb][THUMB_W] - iThumbSize) / iMaxTics;
    stThumbs[iThumb][THUMB_INCY] = (stThumbs[iThumb][THUMB_H] - iThumbHeight) / iMaxTics;

    // initialize thumbnail image layer
    stFrames[iThumb] = new Image ();
    stFrames[iThumb].src = stThumbs[iThumb][THUMB_SRC];

    if ((use_features == 1) && stThumbs[iThumb][THUMB_WF])
      stThumbs[iThumb][THUMB_WF] = 1;
    else
      stThumbs[iThumb][THUMB_WF] = 0;

    if (iGallIndex != stThumbs[iThumb][THUMB_GALL])
    {
      iIndex = 0;
      iGallIndex = stThumbs[iThumb][THUMB_GALL];
      stGalls[iGallIndex][GALL_L] = iThumb;
    }
    else
      iIndex += iThumbSize + iThumbGap;

    stThumbs[iThumb][THUMB_SX] = iIndex + stGalls[iGallIndex][GALL_LEFT];
    stThumbs[iThumb][THUMB_SY] = stGalls[iGallIndex][GALL_TOP];

    if (stThumbs[iThumb][THUMB_WF])
    {
      stThumbs[iThumb][THUMB_LI] = -(stThumbs[iThumb][THUMB_SX] + iThumbWidth / 2 - stGalls[iGallIndex][GALL_CX]) / iMaxTics;
      stThumbs[iThumb][THUMB_TI] = -(stThumbs[iThumb][THUMB_SY] + iThumbHeight / 2 - (iThumbSize + iThumbOffY)) / iMaxTics;
    }
    else
    {
      stThumbs[iThumb][THUMB_LI] = -(stThumbs[iThumb][THUMB_SX] + stThumbs[iThumb][THUMB_W] / 2 - stGalls[iGallIndex][GALL_CX]);
      stThumbs[iThumb][THUMB_TI] = -(stThumbs[iThumb][THUMB_SY] + stThumbs[iThumb][THUMB_H] / 2 - (iThumbSize + iThumbOffY));
    }

    if (use_features == 1)
    {
      sName = "sm_img" + (iThumb + 1);
      stThumbs[iThumb][THUMB_IMG] = (ns) ? document[sName] : document.all[sName];

      stThumbs[iThumb][THUMB_IMG].style.position = "absolute";    
      stThumbs[iThumb][THUMB_IMG].style.left = 0;
      stThumbs[iThumb][THUMB_IMG].style.top = stThumbs[iThumb][THUMB_SY];
      stThumbs[iThumb][THUMB_IMG].style.zIndex = 2;
      if (iThumb < stGalls[iGallIndex][GALL_VIS] + stGalls[iGallIndex][GALL_L])
      {
        stThumbs[iThumb][THUMB_IMG].style.visibility = set_show;
        stThumbs[iThumb][THUMB_IMG].style.left = stThumbs[iThumb][THUMB_SX];
      }
      else
        stThumbs[iThumb][THUMB_IMG].style.visibility = set_hide;

      sName = "trans_img" + (iThumb + 1);
      stThumbs[iThumb][THUMB_TIMG] = (ns) ? document[sName] : document.all[sName];

      stThumbs[iThumb][THUMB_TIMG].width = 100;
      stThumbs[iThumb][THUMB_TIMG].height = 100;
      stThumbs[iThumb][THUMB_TIMG].style.position = "absolute";
      stThumbs[iThumb][THUMB_TIMG].style.left = 0;
      stThumbs[iThumb][THUMB_TIMG].style.top = stThumbs[iThumb][THUMB_SY];
      stThumbs[iThumb][THUMB_TIMG].style.zIndex = 4;
      if (iThumb < stGalls[iGallIndex][GALL_VIS] + stGalls[iGallIndex][GALL_L])
      {
        stThumbs[iThumb][THUMB_TIMG].style.visibility = set_show;
        stThumbs[iThumb][THUMB_TIMG].style.left = stThumbs[iThumb][THUMB_SX];
      }
      else
        stThumbs[iThumb][THUMB_TIMG].style.visibility = set_hide;
    }
    else if (use_features == 2)
    {
      iMaxTics = 0;

      sLayer = "sm_layer" + (iThumb + 1);
      stThumbs[iThumb][THUMB_LYR] = (ns) ? document[sLayer] : document.all[sLayer].style;

      stThumbs[iThumb][THUMB_LYR].resizeTo (stThumbs[iThumb][THUMB_W], stThumbs[iThumb][THUMB_H]);
      stThumbs[iThumb][THUMB_LYR].position = "absolute";
      stThumbs[iThumb][THUMB_LYR].left = stThumbs[iThumb][THUMB_SX];
      stThumbs[iThumb][THUMB_LYR].top = stThumbs[iThumb][THUMB_SY];
      if (iThumb < stGalls[iGallIndex][GALL_VIS] + stGalls[iGallIndex][GALL_L])
        stThumbs[iThumb][THUMB_LYR].visibility = set_show;
      else
        stThumbs[iThumb][THUMB_LYR].visibility = set_hide;

      sLayer = "trans_layer" + (iThumb + 1);
      stThumbs[iThumb][THUMB_TLYR] = (ns) ? document[sLayer] : document.all[sLayer].style;

      stThumbs[iThumb][THUMB_TLYR].resizeTo (iThumbSize, iThumbSize);
      stThumbs[iThumb][THUMB_TLYR].position = "absolute";
      stThumbs[iThumb][THUMB_TLYR].left = stThumbs[iThumb][THUMB_SX];
      stThumbs[iThumb][THUMB_TLYR].top = stThumbs[iThumb][THUMB_SY];
      if (iThumb < stGalls[iGallIndex][GALL_VIS] + stGalls[iGallIndex][GALL_L])
        stThumbs[iThumb][THUMB_TLYR].visibility = set_show;
      else
        stThumbs[iThumb][THUMB_TLYR].visibility = set_hide;
    }
  }


  iGallInit = 1;
}


