﻿function ZoomIn(img, spacing) {
    var w = parseInt( img.style.width.replace('px','') ) + spacing;
    var h = parseInt( img.style.height.replace('px','') ) + spacing;
    
    ////img.style.left = parseInt( img.style.left.replace('px','') ) - parseInt( spacing / 2 )+ 'px';
    ////img.style.top = (parseInt( img.style.top.replace('px','') ) - parseInt( spacing / 2 ))+ 'px';
    
    img.style.width = w + 'px';
    img.style.height = h + 'px';
}

function ZoomOut(img, spacing) {
    var w = parseInt( img.style.width.replace('px','') ) - spacing;
    var h = parseInt( img.style.height.replace('px','') ) - spacing;
    
    ////img.style.left = parseInt( img.style.left.replace('px','') ) + parseInt( spacing / 2 )+ 'px';
    ////img.style.top = (parseInt( img.style.top.replace('px','') ) + parseInt( spacing / 2 ))+ 'px';
    
    img.style.width = w + 'px';
    img.style.height = h + 'px';
}
 
  var scrolling_images = null;
  var scrolling = false;
  var running = false;
  var threshold_sum = 0;
  var index = 0;
  
  function do_scroll_Left(id, threshold, max, imageCount) {
    if (scrolling) return;
    index = imageCount;
    if (index > 0) {
        index--;
        scroll_Left(id, threshold, max, imageCount);
    }
  }
  function scroll_Left(id, threshold, max, imageCount) {
      scrolling = true;
      if (threshold_sum >= max) {
            scrolling = false;
            threshold_sum = 0;
            scroll_Stop();
            return;
      }
      
      var d = document.getElementById(id);
      d.scrollLeft = d.scrollLeft - threshold;


      scrolling_images = window.setTimeout(function() {
          if (scrolling) {
            threshold_sum += threshold; 
            scroll_Left(id, threshold, max, imageCount);
          }
      }, 10);
  }

  function do_scroll_Right(id, threshold, max, imageCount) {
    if (scrolling) return;
    index = 0;
    if (index < imageCount - 1) {
       index++;
       scroll_Right(id, threshold, max, imageCount);
    }
  }
  
  function scroll_Right(id, threshold, max, imageCount) {
      scrolling = true;

      if (threshold_sum >= max) {
            scrolling = false;
            threshold_sum = 0;
            scroll_Stop();
            return;
      } 
      var d = document.getElementById(id);
      d.scrollLeft = d.scrollLeft + threshold ;

      scrolling_images = window.setTimeout(function() {
          if (scrolling) {
            threshold_sum += threshold;             
            scroll_Right(id, threshold, max, imageCount);
          }
      }, 10);
  }

  function scroll_Stop() {
        window.clearTimeout(scrolling_images);
  }