//// Filmstrip scroll code for Abbeydale site ////
//
// config items...
var sScrlDiv = "filmstrip";
var nDeltaY = 2;          // scroll by 2px...
var nScrlDelay = 10;      // ...every 10ms
var bAutoScroll = true;   // auto start
var nDwellTime = 5000;    // show each pic for 5s
var sPicDir = "imgs";     // image files are in this folder
var nPicMargin = 10;      // image top margin
var nImagesPerPage = 3;   // number of images on home page
var arrPics = new Array(Array("film_restore.jpg", "http://www.restorelife.co.uk", 180),
                        Array("film_seceq.jpg", "http://www.securequity.com", 196),
                        Array("film_jdp2010.jpg", "http://www.jeanettedawson.co.uk", 168),
                        Array("film_whelan.jpg", "http://www.whelanshoes.ie", 180),
                        Array("film_artglass.jpg", "http://www.artglassuk.co.uk", 155),
                        Array("film_life.jpg", "http://www.lifesolutions.org.uk", 200),
                        Array("film_restore2.jpg", "http://www.restorelife.co.uk", 180),
                        Array("film_dales.jpg", "http://www.dalesaccountancy.co.uk", 185),
                        Array("film_greenwood.jpg", "http://www.greenwood-electrics.co.uk", 150),
                        Array("film_imp.jpg", "http://www.impinabox.co.uk", 160),
                        Array("film_nfarts.jpg", "http://www.newformarts.org.uk", 190),
                        Array("film_lemon.jpg", "http://www.lemonsnap.co.uk", 190),
                        Array("film_beaut.jpg", "http://www.permanentlybeautiful.co.uk", 200),
                        Array("film_kidstuff.jpg", "http://www.kidstuffphotography.co.uk", 185),
                        Array("film_weir.jpg", "http://www.weirstreet.co.uk", 200),
                        Array("film_brownes.jpg", "http://www.browneshair.com", 175));
var sFolioLink = "website-portfolio.php";
// internal globals...
var nCurNdx = 0;
var tmrScroll = 0;
var nY = 0;
var elScrlDiv = 0;
// Filmstrip control images... the imgsLo and imgsHi arrays
// are created in navigation.js and the functions to swap the
// images on mouseover are also there.  Include navigation.js
// before this file.
if (document.images)
  {
  imgsLo["ctrlUp"] = new Image(11, 12);
  imgsLo["ctrlUp"].src = "imgs/ctrl_up_0.gif";
  imgsLo["ctrlStop"] = new Image(11, 12);
  imgsLo["ctrlStop"].src = "imgs/ctrl_stop_0.gif";
  imgsLo["ctrlPlay"] = new Image(11, 12);
  imgsLo["ctrlPlay"].src = "imgs/ctrl_play_0.gif";
  imgsLo["ctrlDown"] = new Image(11, 12);
  imgsLo["ctrlDown"].src = "imgs/ctrl_down_0.gif";

  imgsHi["ctrlUp"] = new Image(11, 12);
  imgsHi["ctrlUp"].src = "imgs/ctrl_up_1.gif";
  imgsHi["ctrlStop"] = new Image(11, 12);
  imgsHi["ctrlStop"].src = "imgs/ctrl_stop_1.gif";
  imgsHi["ctrlPlay"] = new Image(11, 12);
  imgsHi["ctrlPlay"].src = "imgs/ctrl_play_1.gif";
  imgsHi["ctrlDown"] = new Image(11, 12);
  imgsHi["ctrlDown"].src = "imgs/ctrl_down_1.gif";
  }

// flmAutoStart() - called by body onload
// if continuous scrolling is set, start scrolling after short interval...
function flmAutoStart()
  {
  if (bAutoScroll)
    tmrDwell = setTimeout("scrlToNext()", 1500);
  return true;
  }

// flmScrollContinuous() called by Scroll Continuous button
// sets bAutoScroll flag and starts a scroll after very short intvl...
function flmScrollContinuous()
  {
  if (!bAutoScroll)
    {
    bAutoScroll = true;
    tmrDwell = setTimeout("scrlToNext()", 500);
    }
  return false;
  }

// flmScrollStop() - called by Stop btn onclick
// clears bAutoScroll flag and clears dwell timer
// but does NOT stop a scroll currently in progress...
function flmScrollStop()
  {
  bAutoScroll = false;
  clearTimeout(tmrDwell);
  return false;
  }

// flmScrollToNext() - called by Next btn onclick
function flmScrollToNext()
  {
  bAutoScroll = false;
  clearTimeout(tmrDwell);
  scrlToNext();
  return false;
  }

// flmScrollToPrev() - called by Prev btn onclick
function flmScrollToPrev()
  {
  bAutoScroll = false;
  clearTimeout(tmrDwell);
  scrlToPrev();
  return false;
  }

// helper functions

// scrlToNext() initiates a scroll upwards...
function scrlToNext()
  {
  if (!elScrlDiv)
    elScrlDiv = document.getElementById(sScrlDiv);
  // add next pic to end before scrolling...
  elScrlDiv.innerHTML += "<img src=\"" + sPicDir + "/" + arrPics[(nCurNdx + nImagesPerPage) % arrPics.length][0] + "\" />\n";
  // go do the scrolling...
  tmrScroll = setTimeout("scrlUp()", nScrlDelay);
  return false;     // prevents page refresh after onclick
  }

// scrlUp() performs a scroll upwards...
function scrlUp()
  {
  if (elScrlDiv)
    {
    if (nY + nDeltaY <= arrPics[nCurNdx][2] + nPicMargin)
      {
      nY += nDeltaY;
      elScrlDiv.style.top = -nY + "px";
      tmrScroll = setTimeout("scrlUp()", nScrlDelay);
      }
    else
      {
      // end of scroll - redraw scrolling div at next stage...
      nY = 0;
      if (++nCurNdx >= arrPics.length)
        nCurNdx = 0;
      elScrlDiv.innerHTML = "<a href=\"" + sFolioLink + "\" target=\"_top\"><img src=\"" + sPicDir + "/" + arrPics[nCurNdx][0] + "\" /></a>\n";
      elScrlDiv.style.top = "0px";
      //alert("elScrlDiv.innerHTML:"+elScrlDiv.innerHTML);
      for (var i = 1; i < arrPics.length; i++)
        {
        elScrlDiv.innerHTML += "<a href=\"" + sFolioLink + "\" target=\"_top\"><img src=\"" + sPicDir + "/" + arrPics[(nCurNdx + i) % arrPics.length][0] + "\" /></a>\n";
        }
      if (bAutoScroll)
        tmrDwell = setTimeout("scrlToNext()", nDwellTime);
      }
    }
  }

// scrlToPrev() initiates a scroll downwards...
function scrlToPrev()
  {
  if (!elScrlDiv)
    elScrlDiv = document.getElementById(sScrlDiv);
  // go do the scrolling...
  tmrScroll = setTimeout("scrlDown()", nScrlDelay);
  return false;     // prevents page refresh after onclick
  }

// scrlDown() performs a scroll downwards...
function scrlDown()
  {
  if (elScrlDiv)
    {
    if (nY == 0)
      {
      // start of scroll - redraw div in pre-scrolled posn with prev pic at top...
      if (--nCurNdx < 0)
        nCurNdx = arrPics.length - 1;
      nY = -arrPics[nCurNdx][2] - nPicMargin;
      elScrlDiv.style.top = nY + "px";
      elScrlDiv.innerHTML = "<a href=\"" + sFolioLink + "\" target=\"_top\"><img src=\"" + sPicDir + "/" + arrPics[nCurNdx][0] + "\" /></a>\n";
      //alert("elScrlDiv.innerHTML:"+elScrlDiv.innerHTML);
      for (var i = 1; i < arrPics.length; i++)
        {
        elScrlDiv.innerHTML += "<a href=\"" + sFolioLink + "\" target=\"_top\"><img src=\"" + sPicDir + "/" + arrPics[(nCurNdx + i) % arrPics.length][0] + "\" /></a>\n";
        }
      }
    if (nY + nDeltaY >= 0)
      {
      // end of scroll...
      nY = 0;
      }
    else
      {
      // carry on scrolling...
      nY += nDeltaY;
      tmrScroll = setTimeout("scrlDown()", nScrlDelay);
      }
    elScrlDiv.style.top = nY + "px";
    }
  }

