// Gallery 5.1 Template Javascript
// photogallery.js
//
// $Source: /cvs/root/host/wppd/webapps/g-i/web/i/js/photogallery.js,v $
// $Date: 2006/08/03 18:51:25 $
// $Author: ttrail $
// $Revision: 1.9 $

var slideshow_timer;
var blurTimeout;

function blurFunc() {
  if (!isLowBrowser && isPlaying) {
      blurTimeout = window.setTimeout("stopShow()", 1500);
  } 
}

function init() {
  if (isPlaying) {
        if (curImg == galleryPhotoNum) {
            curImg = 0;
        }
        curImg = curImg + 1;
        document['stop_n_start' ].src =  galleryImgPath + "stop_375.gif";
        speedSlideBar(animationSpeed);
        slideshow_timer = window.setTimeout("changeSlide()", animationSpeed);
  }
}
function stopStart(SLIDE) {
  window.clearTimeout(blurTimeout);
  if (isPlaying) {
      // Stop show
      stopShow();
  } else {
      // Start show
      startShow(SLIDE);
  }
}
function startShow(SLIDE) {
  isPlaying = true;
  if (SLIDE == galleryPhotoNum) {
    SLIDE = 0;
  }
  curImg = SLIDE + 1;
  document['stop_n_start' ].src = galleryImgPath + "stop_375.gif";
  changeSlide();
}
function stopShow() {
  isPlaying = false;
  window.clearTimeout(slideshow_timer);
  document['stop_n_start' ].src = galleryImgPath + "play_375.gif";
}
function setSpeed(speedUpOrDown, setUseAbsolute) {
  window.clearTimeout(blurTimeout);
  if (setUseAbsolute == 1) {
    animationSpeed = speedUpOrDown;
  } else {
    if (speedUpOrDown == 0) {
        animationSpeed = (animationSpeed + 2000);
        if(animationSpeed == 14000) {
            animationSpeed = 12000;
        }
    } else {
        if (animationSpeed > 2000) {
            animationSpeed = (animationSpeed - 2000);
        }
    }
  }
  speedSlideBar(animationSpeed);
  if ((!isPlaying) && (animationSpeed >= 2000)) {
    isPlaying = true;
    startShow(curImg);
  }
}
function speedSlideBar(animSpeed) {
    var tmpObj;
    var startPos = animSpeed;
    for (var i=0; i < 6; i++) {
        tmpObj = eval('document.speed' + i);
        if (12000 - (i * 2000) >=  animSpeed ) {
            tmpObj.src =  galleryImgPath + "on_box.gif";
        } else {
            tmpObj.src =  galleryImgPath + "off_box.gif";
        }
        startPos = (startPos - 2000);
    }
}


function changeSlide() {
  window.location =  galleryPageName + "?floc=" + galleryFlocPrefix + galleryName +  curImg + "-slideshow&" + paramName + "=" + galleryName + "&pl=" + isPlaying + "&spd=" + animationSpeed + "&pi=" + (curImg - 1) + "&xad=" + noAd + "&grurl=" + galleryExitURL + "&photo=" + curImg;
}
