// FILE: scripts.js
// (c)2004-2007 property of and all rights by Jan Hollmann, licensed to Timo Grubing.
// version 1.1

// globalvars.js must be called first for working pGFS


  function MainframePosition() {
    MainframeXPosition = ( window.innerWidth - 800) / 2;
    MainframeYPosition = ( window.innerHeight - 600 ) / 2;
    if (MainframeXPosition <= 0) {
      MainframeXPosition = 0;
    }
    if (MainframeYPosition <= 0) {
      MainframeYPosition = 0;
    }
    //alert('X ' + MainframeXPosition + ' Y ' + MainframeYPosition);
    //document.getElementsByName("mainframe")[0].style.left = MainframeXPosition;
    //document.getElementsByName("mainframe")[0].style.top = MainframeYPosition;
    //nicht mehr nötig:
    //document.getElementsByName("mainframe")[0].style.visibility = "visible";
  }





  function SetPictureMap(mapnumber) {
    //alert('mapnumber: ' + mapnumber);
    document.showbox.outerHTML='<IMG id="showbox" name="showbox" src="gal/pic' + mapnumber + '.gif" usemap="#pic' + mapnumber + '" />';
    //                          <img id="showbox" name="showbox" src="gal/pic       0        .gif" usemap="#pic       00        " />
    document.textbubble.outerHTML='<img id="textbubble" name="textbubble" src="gal/pic' + mapnumber + '-text.gif" usemap="#pic' + mapnumber + '-text" />';
    //                             <img id="textbubble" name="textbubble" src="gal/pic       0        -text.gif" usemap="#pic       00        -text" />
    //alert(document.textbubble.outerHTML);
  }

  function ShowPictures(picnumber) {
    //alert("picnumber: " + picnumber + "  pictureOffset: " + pictureOffset);
    picnumber = picnumber + pictureOffset;
    //alert("picnumber: " + picnumber);

    document.showbox.src = 'gal/pic' + picnumber + '.gif';
    document.textbubble.src = 'gal/pic' + picnumber + '-text.gif';
    //
    var delayMapChangeCall = "\"SetPictureMap("+picnumber+")\"";
    //alert(delayMapChangeCall);
    //alert(picnumber);
    setTimeout(delayMapChangeCall,500);
  }

  function MenuIn(menupoint) {
    document.getElementsByName(menupoint)[0].src = '../menu/' + menupoint + '-over.gif';
  }
  function MenuOut(menupoint) {
    document.getElementsByName(menupoint)[0].src = '../menu/' + menupoint + '.gif';
  }

  function SubMenuIn(submenupoint) {
    document.getElementsByName(submenupoint)[0].src = submenupoint + '-over.gif';
  }
  function SubMenuOut(submenupoint) {
    document.getElementsByName(submenupoint)[0].src = submenupoint + '.gif';
  }

//####################################
// pGFS - phees' Gallery Function Set
//####################################
// hide all the gallery-tumbs with width "size" and
// in matching cases the galleryForward/Backward/Indicator-elements
  function pGalleryElementsHide(imgName, targetName, size, startCounter, endCounter) {
    for (var counter = startCounter; counter <= endCounter; counter++) {
      if (document.getElementsByName(imgName)[counter].width == size) {
        document.getElementsByName(targetName)[counter].style.visibility = 'hidden';
      } else {}
    }
    if (activeGalleryNumber == 1) {
      //hide backward-arrow
      document.getElementsByName('galleryBackward')[0].style.visibility = 'hidden';
    } else {
      document.getElementsByName('galleryBackward')[0].style.visibility = 'visible';
    }
    if (activeGalleryNumber == galleryCount) {
      //hide forward-arrow
      document.getElementsByName('galleryForward')[0].style.visibility = 'hidden';
    } else {
      document.getElementsByName('galleryForward')[0].style.visibility = 'visible';
    }
    if (galleryCount > 1) {
      //hide gallery-position-display
      document.getElementsByName('galleryIndicator')[0].style.visibility = 'visible';
    }
  }


// ##### pGalleryMaxCheck is not implemented yet
  function pGalleryMaxCheck() {
  }
// ##### used for gallery page-switching
// three methods are available: ('backward',0), ('forward',0) and ('jumpto',destination)
// pGallerySwitch checks, if it's at the beginning/end of the gallery and if "destination"
// is an existing gallery subpage.
// GLOBAL VARIABLE "galleryCount" must be set!
  function pGallerySwitch(method,destination) {
    if (debug == true) { alert("method: " + method + " destination: " + destination);
      alert("activeGalleryNumber: " + activeGalleryNumber + " galleryCount: " + galleryCount); }
    // decide how to handle function call (backward, forward, jumpto)
    if (method == "backward") {
      if (activeGalleryNumber > 1) {
        activeGalleryNumber = activeGalleryNumber - 1;
      }
    }
    if (method == "forward") {
      if (activeGalleryNumber < galleryCount) {
        activeGalleryNumber = activeGalleryNumber + 1;
      }
    }
    if (method == "jumpto") {
      if (0 < destination && destination <= galleryCount) {
        activeGalleryNumber = destination;
      }
    }

    // calculate new picture offset
    pictureOffset = (activeGalleryNumber - 1) * picturesPerGallery;

    //DEBUG
    //alert("activeGalleryNumber:" + activeGalleryNumber + " galleryCount:" + galleryCount)

    // set base pictures of new gallery-page
    document.showbox.src = 'gal/pic-gal' + activeGalleryNumber + '.gif';
    document.textbubble.src = 'gal/pic-gal' + activeGalleryNumber + '-text.gif';
    document.getElementsByName('galleryIndicator')[0].src = '../pic/icon_gal' + activeGalleryNumber + '_indicator.gif';

    // replace link-map for the new main gallery picture
    // var delayMapChangeCall = "\"SetPictureMap(\'-gal" + activeGalleryNumber + "\')\"";
    // alert(delayMapChangeCall);
    // alert(picnumber);
    // setTimeout(delayMapChangeCall,500);

    // replace gallery thumbs
    for (var counter = 0; counter < picturesPerGallery; counter++) {
      var replacePictureNumber = counter + pictureOffset + 1;
      document.getElementsByName('galleryThumb')[counter].src = 'gal/pic' + replacePictureNumber + '-th.gif';
      document.getElementsByName('galleryThumbLink')[counter].style.visibility = 'visible';
    }
    // refresh hidden status of gallery thumbs
    setTimeout("pGalleryElementsHide('galleryThumb', 'galleryThumbLink', '5', '0', '14')",1000);
  }
