﻿// local vars
var isv_startpos;
var isv_scroller;
var isv_finaltop = -100;
var isv_slideby = 0;
var isv_direction = 0;
var isv_initialised = 0


function copyElement(source, target) {
  // get the source style element
  var styles = source.style;
  // iterate
  target.innerHTML = source.innerHTML;
  for (var s in styles) {
    // wathc for exceptions
    try {
      // copy the style elements
      target.style[s] = source.style[s]
    }
    catch (e) {
      // suppress
    }
  }
}

function isv_Select(sender) {
  // stop zooms
  //MagicZoom_stopZooms();
  // get the zoom images
  var bigzoom = document.getElementById('imageZoomBig');
  var smlzoom = bigzoom.firstChild;
  // set the new src and href (bad fix this !!!)
  bigzoom.href = sender.src.replace('t.jpg', 'l.jpg');
  smlzoom.src = sender.src.replace('t.jpg', 'm.jpg');
  // re-init zoom
  MagicZoom.refresh();
}

function isv_slide_up() {
  // get the top div
  var topDiv = isv_scroller.getElementsByTagName('DIV')[0];
  // set the final top pos
  isv_finaltop = topDiv.offsetHeight * -1;
  // set the direction
  isv_direction = 0;
  // set the amount to slide up by
  isv_slideby = -4;
}
function isv_slide_down() {
  // get the divs
  var divs = isv_scroller.getElementsByTagName('DIV');
  // get the bottom div
  var bottomDiv = divs[divs.length - 1];
  // create a new div
  var addDiv = document.createElement('DIV');
  // set the click hander
  addDiv.onclick = isv_slide_up;
  // copy the style
  copyElement(bottomDiv, addDiv);
  // move the scroller up
  isv_scroller.style.top = (bottomDiv.offsetHeight*-1)+'px';

  // remove the bottom div and append ready to loop
  isv_scroller.removeChild(bottomDiv);
  isv_scroller.insertBefore(addDiv, isv_scroller.firstChild);
  // set the final top pos
  isv_finaltop = 0; 
  // set the direction
  isv_direction = 1;
  // set the amount to slide up by
  isv_slideby = 4;
}
function slideUpDone() {
  // move the scroller down
  isv_scroller.style.top = '0px';
  // get the top most div
  var topDiv = isv_scroller.getElementsByTagName('DIV')[0];
  // create a new div
  var addDiv = document.createElement('DIV');
  // set the click hander
  addDiv.onclick = isv_slide_up;
  // copy the style
  copyElement(topDiv, addDiv);
  // remove and append ready to loop again
  isv_scroller.removeChild(topDiv);
  isv_scroller.appendChild(addDiv);
}

function isv_doSlide() {
  // check the slide by
  if (isv_slideby != 0) {
    // get the position of the scrolling div
    var topPos = isv_scroller.offsetTop;
    // check bounds
    if ((topPos <= isv_finaltop && isv_direction == 0) || (topPos >= 0 && isv_direction == 1)) {
      // done
      isv_slideby = 0;
    }
    // move the panel
    isv_scroller.style.top = (topPos + isv_slideby) + 'px';
    // check for slide up finishing
    if (isv_slideby == 0 && isv_direction == 0) slideUpDone();
  }
  // set the timeout call value 
  setTimeout('isv_doSlide()', 20);
}
function isv_init() {
  if (isv_initialised == 0) {
    // get the scroller
    isv_scroller = document.getElementById('isv_Scroll');
    // get the start pos of the scroller
    isv_startpos = isv_scroller.offsetTop;
    // get all of the contained divs
    var divs = isv_scroller.getElementsByTagName('DIV');
    // check if there are enough divs to scroll
    if (divs.length > 3) {
      // iterate
      for (var i = 0; i < divs.length; i++) {
        // set the onclick handler
        divs[i].onclick = isv_slide_up;
      }
      // assign event handlers
      document.getElementById('isv_UpArrow').onclick = isv_slide_up;
      document.getElementById('isv_DownArrow').onclick = isv_slide_down;
    }
    else {
      document.getElementById('isv_UpArrow').visible = false;
      document.getElementById('isv_DownArrow').visible = false;
    }
    // initialise the slide
    isv_doSlide();
    //isv_initialised = 1;
  }
}