﻿var ImageScroller = function(_imageScrollerParentDivID, _imageScrollerChildDivID) {
   _imageScrollerParentDivID = getElem(_imageScrollerParentDivID); 
   _imageScrollerChildDivID = getElem(_imageScrollerChildDivID);
   _imageScrollerParentDivID.style.width = "566px"; //width of scrolling div
var prImagePaths = new Array(); 
var prImageAltText = new Array(); 
var prImageClicks = new Array(); 
var iNumOfImages; 
var bAutoScroll = 1; //0=false, 1=true
var iAutoScrollDelay = 1000; 
var bAutoReverse = 1; //0=false, 1=true
var objCounterDiv = ""; 
var objDescriptionDiv = ""; 
var iSmoothSlideInterval = 50;
var iSmoothSlideAmount = 7;
var moveTimer;
   var CURRENT_THUMB_INDEX = 1;
   var NEW_REVERSE_OFFSET = 0;
   var MAX_REVERSE_OFFSET = 0;
   var NEW_FORWARD_OFFSET = 0;
   var IS_SCROLLING = false;
   this.setNumOfImageToScroll = function(_NumOfImagesToScroll) {
        iImageScrollAmount = parseInt(_NumOfImagesToScroll);
      };
   this.setClickOpenType = function(_openType) {
      if (_openType == 0 || _openType == 1) {
         bClickOpenType = _openType; }
      };
   this.enableThumbBorder = function(_boolean) {
      bEnableThumbBorder = _boolean; 
      }; 
   this.setThumbsShown = function(_newNumOfThumbsShown) {
      iNumOfThumbsShown = parseInt(_newNumOfThumbsShown); 
      };
   this.addThumbnail = function(_thumbnailURL, _fullClickURL, _thumbnailAlt) {
      prImagePaths[prImagePaths.length] = _thumbnailURL;
      prImageClicks[prImageClicks.length] = _fullClickURL;
      prImageAltText[prImageAltText.length] = _thumbnailAlt;
      };	  
   this.setThumbnailHeight = function(_newThumbHeight) {
      this.THUMB_HEIGHT = _newThumbHeight;
      };
   this.setThumbnailWidth = function(_newThumbWidth) {
      this.THUMB_WIDTH = _newThumbWidth;
      };
   this.setThumbnailPadding = function(_newThumbPadding) {
      this.THUMB_PADDING = _newThumbPadding;
      };
   this.renderScroller = function() {
      iNumOfImages = prImagePaths.length; 
      if (iNumOfThumbsShown > iNumOfImages) {
         iNumOfThumbsShown = iNumOfImages; 
         }
      MAX_REVERSE_OFFSET = 0 - (iNumOfImages - iNumOfThumbsShown) * this.THUMB_WIDTH; 
      if (this.THUMB_PADDING > 0) {
         MAX_REVERSE_OFFSET = MAX_REVERSE_OFFSET - (iNumOfImages * this.THUMB_PADDING); 
         }
      if (bEnableThumbBorder == 1) {
         MAX_REVERSE_OFFSET = MAX_REVERSE_OFFSET - (iNumOfImages * 4); 
         }
         if (bEnableThumbBorder == 1) {
            _imageScrollerParentDivID.style.width = (parseInt(_imageScrollerParentDivID.style.width) + (iNumOfThumbsShown * 4)) + "px"; 
            }
         _imageScrollerParentDivID.style.height = this.THUMB_HEIGHT + (this.THUMB_PADDING * 2) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerParentDivID.style.height = (parseInt(_imageScrollerParentDivID.style.height) + 4) + "px"; 
            }
         _imageScrollerChildDivID.style.width = (this.THUMB_WIDTH * iNumOfImages) + (iNumOfImages * (this.THUMB_PADDING * 2)) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerChildDivID.style.width = (parseInt(_imageScrollerChildDivID.style.width) + (iNumOfImages * 4)) + "px"; 
            }
      var oHref;
      var oImage;
        oHref = document.createElement("a");
        oImage = document.createElement("img");
      for (i = 0; i < iNumOfImages; i++) {
        oHref = document.createElement("a");
        oHref.href = prImageClicks[i];
        oHref.title = prImageAltText[i];
        if (bClickOpenType == 1) {
            oHref.target = "_blank";
        }
            oImage = document.createElement("img");
            oImage.src = prImagePaths[i];
            oImage.alt = prImageAltText[i];
            oImage.border = 0;
            oImage.width = this.THUMB_WIDTH;
            oImage.height = this.THUMB_HEIGHT;
            oImage.style.padding = this.THUMB_PADDING;
            oHref.appendChild(oImage);
            _imageScrollerChildDivID.appendChild(oHref);
        }
      };
   function getElem(_elemID) {
      return document.getElementById(_elemID); 
      };
   };