
    /*

        TSG Pasing - Image Gallery, v. 2.1.
  
        Copyright (C) 2008, LIONICS Internet- und Netzwerkloesungen,
        L. Fellermayr <info@lionics.de>
  
        All rights reserved by the author. Any use without
        permission is strictly forbidden and will be persecuted.
  
    */

    var curPos; /* current position within the "allImgs" array */
    var activeThumb; /* thumb id which is currently active */

    /* **************************************************************************************************** */

    function preloadImages (arr)
    {

      document.Vorladen = new Array ();

      if (document.images)

        for (var i = 0; i < arr.length; i++)
        {

            document.Vorladen[i] = new Image ();
            document.Vorladen[i].src = arr[i];

        } // endfor

    } // preloadImages ()

    /* **************************************************************************************************** */

    function displayBig (t)
    {

      /* update curPos */

      for (i = 0; i < allImgs.length; i++)
        if (allImgs[i] == t.src.replace (/http\:\/\/www\.tsg-pasing\.de/g, ""))
          curPos = i;

      /* update big image */

      document.getElementById ('bigImage').src = t.src.replace (/thumbs\//g, "");

      /* update counter */

      document.getElementById ('gal-mid').innerHTML = parseInt (curPos + 1) + "/" + allImgs.length;

      /* adapt borders */

      for (i = 0; i < 5; i++)
      {
        tc = document.getElementById ('thumb' + i);
        if (t.id == tc.id)
        {
          tc.style.border = '2px solid white';
          activeThumb = i;
        }
        else
        {
          tc.style.border = '0px';
          tc.style.borderTop = '2px solid rgb(87,87,87)';
          tc.style.borderBottom = '2px solid rgb(87,87,87)';
        }
      }
      
      adaptButtonStates ();

    }
    
    /* **************************************************************************************************** */

    function shiftThumbs (dir)
    {

      for (i = 0; i < 5; i++)
      {
      
        /* get thumbnail object */

        here = document.getElementById ('thumb' + i);

        /* initial value to indicate whether something was found in array */

        newPosition = -1;

        /* search "allImgs" array for existing thumbnail and add the offset */
        
        for (k = 0; k < allImgs.length; k++)
          if (allImgs[k] == here.src.replace (/http\:\/\/www\.tsg-pasing\.de/g, ""))
            newPosition = k + dir;

        /* if not found in array, simply take thumbnail i */

        if (newPosition == -1)
          newPosition = i;

        /* adapt thumbnail */

        if (newPosition < allImgs.length)
        {

          here.src = allImgs[newPosition];
          here.onclick = function () { displayBig (this); }
          here.onmouseover = function () { this.style.cursor = 'pointer'; };
          here.style.display = 'inline';

        }
        
        else
          here.style.display = 'none'; /* thumbnail containers that are not needed */

      } // endfor i
    
    } // shiftThumbs ()

    /* **************************************************************************************************** */

    function adaptButtonStates ()
    {

      /* adapt button states */

      nextButton = document.getElementById ('next');
      prevButton = document.getElementById ('prev');

      if (curPos < allImgs.length - 1)
      {
        nextButton.src = '/gallery/img/next1.png';
        nextButton.onclick = function () { slide (1); };
        nextButton.onmouseover = function () { this.style.cursor = 'pointer'; this.src = '/gallery/img/next1hover.png'; };
        nextButton.onmouseout = function () { this.src = '/gallery/img/next1.png'; };
      }
      else
      {
        nextButton.src = '/gallery/img/next0.png';
        nextButton.onclick = function () {};
        nextButton.onmouseover = function () { this.style.cursor = 'auto'; };
        nextButton.onmouseout = function () {};
      }
      if (curPos > 0)
      {
        prevButton.src = '/gallery/img/prev1.png';
        prevButton.onclick = function () { slide (-1); };
        prevButton.onmouseover = function () { this.style.cursor = 'pointer'; this.src = '/gallery/img/prev1hover.png'; };
        prevButton.onmouseout = function () { this.src = '/gallery/img/prev1.png'; };
      }
      else
      {
        prevButton.src = '/gallery/img/prev0.png';
        prevButton.onclick = function () {};
        prevButton.onmouseover = function () { this.style.cursor = 'auto'; };
        prevButton.onmouseout = function () {};
      }
    
    } // adaptButtonStates ()
    
    /* **************************************************************************************************** */

    function slide (dir)
    {

      /* slide *outside* view */

      if ((dir == -1) && (activeThumb == 0) || (dir == 1) && (activeThumb == 4))
      {
        shiftThumbs (dir);
        displayBig (document.getElementById ('thumb' + parseInt (activeThumb)));
      }

      /* slide *within* view */
        
      else

        displayBig (document.getElementById ('thumb' + parseInt (activeThumb + dir)));
      
    } // slide ()

    /* **************************************************************************************************** */

    function initGallery ()
    {

      if (allImgs.length == 0)

        foo = alert ("There are no images to show.");

      else
      {

        /* preload all thumbnails */

        preloadImages (allImgs);

        /* initially allocate thumbnails */

        shiftThumbs (0);

        /* initially display big image and adapt button states*/
        
        displayBig (document.getElementById ('thumb0'));
        
      }

    } // initGallery ()

/* EOF */

