//this script adds automated scrolling to the scroll box

/*     *  node An element node - - read-only
          o clientHeight The height of the element inside its border, minus any scrollbar height - - read-only
          o clientWidth The width of the element inside its border, minus any scrollbar width - - read-only
          o offsetHeight The height of the element outside its border - - read-only
          o offsetLeft The distance between the left edge of the node and the left edge of the offsetParent node - - read-only
          o offsetParent The parent element that the browser has chosen to be the offsetParent - Only reliable cross-browser if all chained offsets are added together - - read-only
          o offsetTop The distance between the top edge of the node and the top edge of the offsetParent node - - read-only
          o offsetWidth The width of the element outside its border - - read-only
          o scrollHeight The height of the element's contents and padding - Only reliable if it has a horizontal scrollbar - - read-only
          o scrollLeft The horizontal distance that the element has been scrolled - - read-write
          o scrollTop The vertical distance that the element has been scrolled - - read-write
          o scrollWidth The width of the element's contents and padding - Only reliable if it has a vertical scrollbar - - read-only
*/
scrollBoxNormalLeftShift=1;
scrollBoxLeftShift=scrollBoxNormalLeftShift;
timer = null;

function changeLeftShift() {
  scrollBoxLeftScroll = scrollBox.scrollLeft+scrollBoxLeftShift;
  if (scrollBoxLeftScroll>=scrollBoxFullWidth-scrollBoxInnerWidth) {
    scrollBoxLeftShift=0-scrollBoxLeftShift;
	scrollBoxLeftScroll=scrollBoxFullWidth-scrollBoxInnerWidth;
	delayScroll();
  }
  if (scrollBoxLeftScroll<=0) {
    scrollBoxLeftShift=0-scrollBoxLeftShift;
	scrollBoxLeftScroll=0;
	delayScroll();
  }
  scrollBox.scrollLeft=scrollBoxLeftScroll;
}

function startScroll() {
  clearInterval(timer);
  //timer = setInterval(changeLeftShift,40);
  timer = setInterval(changeLeftShift,25);
}

function delayScroll() {
  clearInterval(timer);
  setTimeout(startScroll,2500);
}

function stopScroll() {
  clearInterval(timer);
}

function scrollBoxSetup() {
  if (!document.getElementById("example_bespoke_frames_scrollbox")) { return; }
  scrollBox = document.getElementById("example_bespoke_frames_scrollbox");
  scrollBoxInnerWidth = scrollBox.clientWidth;
  scrollBoxFullWidth = scrollBox.scrollWidth;
  scrollBoxLeftScroll = scrollBox.scrollLeft;
  //alert ("Found Scrollbox\nInner Width: "+scrollBoxInnerWidth+"\nFull Width: "+scrollBoxFullWidth+"\nLeft Offset: "+scrollBoxLeftScroll);
  scrollBox.onmouseover = function () { stopScroll(); }
  scrollBox.onmouseout = function () { startScroll(); }
  startScroll();
}

addLoadEvent(scrollBoxSetup);