﻿  
    var isf = { 'clock' : null, 'initialized' : false, 'fps' : 24.0, 'TimeSpan' : 1.2, 'Paused' : false, 'peekTime' : 20, 'slideTime' : 4500 };
    var opc;
    var btn;
    var anIndex;
    var loadCount = 0;
    var slideIndex = 0;
    var loadTimer, slideTimer;
    var slides, thumbs;
    var tbl, aDiv;
    window.onload = beginSlides;
    
    function beginSlides()
    {
//      if((showIsVisible == true) && (slideCount > 0))
//      {
//        slides = new Array();
//        
//        if(showToolbar == true) thumbs = new Array();
//        else
//        {
//          aDiv = document.getElementById("thumbRow");
//          if(aDiv != null) aDiv.innerHTML = "";
//        }
//        
//        slides[loadCount] = new Image();
//        slides[loadCount].src = imgPath + pics[loadCount][0];
//        slides[loadCount].id = "slide";
//        slides[loadCount].alt = "Slide Show";
//        slides[loadCount].width = pics[loadCount][2]
//        slides[loadCount].height = pics[loadCount][3]
//        
//        document.getElementById("slide").src = imgPath + pics[loadCount][0];
//        
//        SetCaption();
//        
//        loadTimer = setInterval("loadImage()", isf.peekTime);
//        slideTimer = setInterval("showSlide()", isf.slideTime);
//      }
//      else
//      {
//        aDiv = document.getElementById("slideShowDiv");
//        if(aDiv != null)
//        {
//          aDiv.style.visibility = "hidden";
//          aDiv.style.height = "0px";
//          aDiv.style.overflow = "hidden";
//        }
//      }
//      
      
      
      if((showIsVisible == true) && (slideCount > 0))
      {
        aDiv = document.getElementById("slideShowDiv");
        if(aDiv == null) return;
        aDiv.style.visibility = "visible";
        aDiv.style.height = "auto";
        aDiv.style.overflow = "auto";
        if(showToolbar == true)
        {
          aDiv = document.getElementById("ssToolbar");
          if(aDiv == null) return;
          aDiv.style.visibility = "visible";
          aDiv.style.height = "auto";
          aDiv.style.overflow = "auto";
          thumbs = new Array();
        }
        slides = new Array();
        slides[loadCount] = new Image();
        slides[loadCount].src = imgPath + pics[loadCount][0];
        slides[loadCount].id = "slide";
        slides[loadCount].alt = "Slide Show";
        slides[loadCount].width = pics[loadCount][2]
        slides[loadCount].height = pics[loadCount][3]
        document.getElementById("slide").src = imgPath + pics[loadCount][0];
        SetCaption();
        loadTimer = setInterval("loadImage()", isf.peekTime);
        slideTimer = setInterval("showSlide()", isf.slideTime);
      }
      
      
    }
    
    function loadImage()
    {
      if(slides[loadCount].complete)
      {
        if(showToolbar == true) AddThumb();
        loadCount++;
        if(loadCount < slideCount)
        {
          slides[loadCount] = new Image();
          slides[loadCount].id = "slide";
          slides[loadCount].alt = "Slide Show";
          slides[loadCount].width = pics[loadCount][2]
          slides[loadCount].height = pics[loadCount][3]
          slides[loadCount].src = imgPath + pics[loadCount][0];
        }
        else clearInterval(loadTimer);
      }
    }
    
    function AddThumb()
    {
      thumbs[loadCount] = new Image();
      thumbs[loadCount].src = slides[loadCount].src;
      thumbs[loadCount].alt = "";
      thumbs[loadCount].width = pics[loadCount][4];
      thumbs[loadCount].height = pics[loadCount][5];
      UpdateThumbs();
    }
    
    function showSlide()
    {
      if(!isf.Paused)
      {
        slideIndex++;
        if(slideIndex == slides.length) slideIndex = 0;
        
        if(isf.clock == null)
        {
          if(!isf.initialized) SetType();
          isf.src = slides[slideIndex].src;
          isf.caption = GetCaptionText();
		      if(isf.type != 'none')
		      {
			      isf.Step = 0;
			      isfStep();
			      isf.clock = setInterval('isfStep()', isf.frameTime);
		      }
		      else
		      {
		        isf.obj.src = isf.src;
		        if(showToolbar == true) UpdateThumbs();
		      }
        }
      }
    }
    
    function SetType()
    {
      var i, opc;
      isf.cap = document.getElementById("caption");
      isf.obj = document.getElementById("slide");
      if(typeof isf.obj.style.opacity != 'undefined') isf.type = 'w3c';
      else if(typeof isf.obj.style.MozOpacity != 'undefined') isf.type = 'moz';
      else if(typeof isf.obj.style.KhtmlOpacity != 'undefined') isf.type = 'khtml';
      else if(typeof isf.obj.filters == 'object')
        isf.type = (isf.obj.filters.length > 0 && typeof isf.obj.filters.alpha == 'object' && typeof isf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
      else isf.type = 'none';
      if(isf.type != 'none')
      {
        isf.StepCount = Math.round(isf.fps * isf.TimeSpan);
        if(isf.StepCount % 2 == 0) isf.StepCount++;
        isf.MidCount = Math.floor(isf.StepCount / 2) + 1;
        isf.Angle = Math.PI / isf.StepCount;
        isf.frameTime = Math.round(isf.TimeSpan * 1000.0 / isf.StepCount);
        isf.Opacity = new Array();
        for(i = 0; i <= isf.StepCount; i++)
        {
          opc = 1.0 - Math.sin(isf.Angle * i);
	        switch(isf.type)
	        {
		        case 'ie': isf.Opacity[i] = Math.round(opc * 100.0); break;
		        case 'khtml': isf.Opacity[i] = opc; break;
		        case 'moz' : isf.Opacity[i] = (opc == 1 ? 0.9999999 : opc); break;
		        default : isf.Opacity[i] = (opc == 1 ? 0.9999999 : opc);
	        }
        }
        if(isf.type == "ie") if(isf.Opacity[isf.StepCount - 1] != 100) isf.Opacity[isf.StepCount - 1] = 100;
      }
      isf.initialized = true;
    }
    
    function isfStep()
    {
	    switch(isf.type)
	    {
		    case 'ie' :
          isf.obj.filters.alpha.opacity = isf.Opacity[isf.Step];
          isf.cap.filters.alpha.opacity = isf.Opacity[isf.Step];
			    break;
		    case 'khtml' :
			    isf.obj.style.KhtmlOpacity = isf.Opacity[isf.Step];
			    isf.cap.style.KhtmlOpacity = isf.Opacity[isf.Step];
			    break;
		    case 'moz' : 
			    isf.obj.style.MozOpacity = isf.Opacity[isf.Step];
			    isf.cap.style.MozOpacity = isf.Opacity[isf.Step];
			    break;
		    default : 
			    isf.obj.style.opacity = isf.Opacity[isf.Step];
			    isf.cap.style.opacity = isf.Opacity[isf.Step];
	    }
      if(isf.Step == isf.MidCount)
      {
        isf.obj.src = isf.src;
        isf.cap.innerHTML = isf.caption;
        if(showToolbar == true) UpdateThumbs();
      }
	    if(isf.Step < isf.StepCount) isf.Step++;
	    else
	    {
	      clearInterval(isf.clock);
	      isf.clock = null;
	    }
    }
    
    function UpdateThumbs()
    {
      anIndex = slideIndex + 1;
      if(anIndex >= slides.length) anIndex -= thumbs.length;
      UpdateThumbnailCell("cell3", anIndex);
      UpdateThumbnailCell("cell2", slideIndex);
      anIndex = slideIndex - 1;
      if(anIndex < 0) anIndex += thumbs.length;
      UpdateThumbnailCell("cell1", anIndex);
    }
    
    function UpdateThumbnailCell(aCellID, anIndex, functionType)
    {
      var aCell = document.getElementById(aCellID);
      if(aCell != null)
      {
        if(aCell.childNodes.length > 0) aCell.removeChild(aCell.childNodes[0]);
        aCell.appendChild(thumbs[anIndex].cloneNode(true));
        switch(aCellID)
        {
          case "cell1": aCell.childNodes[0].onclick = btnPrev_Click; break;
          case "cell2": aCell.childNodes[0].onclick = PauseSlideShow; break;
          case "cell3": aCell.childNodes[0].onclick = btnNext_Click; break;
        }
      }
    }
    
    function ToggleButtonState(aButtonID)
    {
      btn = document.getElementById(aButtonID);
      if(btn != null) btn.disabled = !btn.disabled;
    }
    
    function PauseSlideShow()
    {
      if(!isf.Paused)
      {
        isf.Paused = true;
        clearInterval(slideTimer);
        ToggleButtonState("btnPause");
        ToggleButtonState("btnResume");
      }
    }
    
    function ResumeSlideShow()
    {
      ToggleButtonState("btnPause");
      ToggleButtonState("btnResume");
      isf.Paused = false;
      showSlide();
      slideTimer = setInterval("showSlide()", isf.slideTime);
    }
    
    function btnNext_Click()
    {
      if(!isf.Paused) PauseSlideShow();
      slideIndex++;
      if(slideIndex == slides.length) slideIndex = 0;
      ShowStaticSlide();
      UpdateThumbs();
    }

    function btnPrev_Click()
    {
      if(!isf.Paused) PauseSlideShow();
      slideIndex--;
      if(slideIndex < 0) slideIndex += slides.length;
      ShowStaticSlide();
      UpdateThumbs();
    }
    
    function ShowStaticSlide()
    {
      var anImage, aCaption;
      anImage = document.getElementById("slide");
      if(anImage != null) anImage.src = slides[slideIndex].src;
      SetCaption();
    }

    function SetCaption()
    {
      aCaption = document.getElementById("caption");
      if(aCaption != null) aCaption.innerHTML = GetCaptionText();
    }
    
    function GetCaptionText()
    {
      return pics[slideIndex][1] != "" ? "<h3 style=\"font-size:14px;font-weight:600;margin-bottom:0px;\" >" + pics[slideIndex][1] + "</h3>" : "&nbsp;";
    }