var gblPhotoShufflerDivId = "imageSlideshow";
var gblPhotoShufflerImgId = "photoimg";
var gblPhotoShufflerAnchorId = "photoanchor";
var gblImg = new Array(
  "images/gallery/slideshow/02.jpg",
  "images/gallery/slideshow/03.jpg",
  "images/gallery/slideshow/04.jpg",
  "images/gallery/slideshow/05.jpg",
  "images/gallery/slideshow/06.jpg",
  "images/gallery/slideshow/07.jpg",
  "images/gallery/slideshow/08.jpg",
  "images/gallery/slideshow/09.jpg",
  "images/gallery/slideshow/12.jpg",
  "images/gallery/slideshow/14.jpg",
  "images/gallery/slideshow/15.jpg",
  "images/gallery/slideshow/16.jpg",
  "images/gallery/slideshow/17.jpg",
  "images/gallery/slideshow/22.jpg",
  "images/gallery/slideshow/23.jpg",
  "images/gallery/slideshow/24.jpg",
  "images/gallery/slideshow/25.jpg",
  "images/gallery/slideshow/28.jpg",
  "images/gallery/slideshow/30.jpg",
  "images/gallery/slideshow/33.jpg",
  "images/gallery/slideshow/34.jpg",
  "images/gallery/slideshow/35.jpg",
  "images/gallery/slideshow/36.jpg",
  "images/gallery/slideshow/37.jpg",
  "images/gallery/slideshow/38.jpg",
  "images/gallery/slideshow/39.jpg",
  "images/gallery/slideshow/40.jpg",
  "images/gallery/slideshow/41.jpg",
  "images/gallery/slideshow/42.jpg",
  "images/gallery/slideshow/43.jpg",
  "images/gallery/slideshow/44.jpg"
  );
var gblHref = new Array(
  "#",
  "#",
  "#"
  );
var gblPauseSeconds = 7.25;
var gblFadeSeconds = .85;
var gblRotations = 1;

var gblDeckSize = gblImg.length;
var gblOpacity = 100;
var gblOnDeck = 0;
var gblStartImg;
var gblStartHref;
var gblImageRotations = gblDeckSize * (gblRotations+1);

window.onload = photoShufflerLaunch;
  
function photoShufflerLaunch()
{
	var theimg = document.getElementById(gblPhotoShufflerImgId);
        gblStartImg = theimg.src; // save away to show as final image
  	//var theanchor = document.getElementById(gblPhotoShufflerAnchorId);
    //    gblStartHref = theimg.href; // save away to show as final image

	document.getElementById(gblPhotoShufflerDivId).style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
	setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
}

function photoShufflerShuffle()
{
  var thediv = document.getElementById(gblPhotoShufflerDivId);
  var theimg = document.getElementById(gblPhotoShufflerImgId);
  //var theanchor = document.getElementById(gblPhotoShufflerAnchorId);

  // copy div background-image to img.src
  theimg.src = gblImg[gblOnDeck];
 // theanchor.href = gblHref[gblOnDeck];
  window.status = gblHref[gblOnDeck]; // updates status bar (optional)
  // set img opacity to 100
  setOpacity(theimg,100);

  // shuffle the deck
  gblOnDeck = ++gblOnDeck % gblDeckSize;
  // decrement rotation counter
  if (--gblImageRotations < 1)
  {
    // insert start/final image if we're done
    gblImg[gblOnDeck] = gblStartImg;
    gblHref[gblOnDeck] = gblStartHref;
  }

  // slide next image underneath
  thediv.style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
}

function photoShufflerFade()
{
  var theimg = document.getElementById(gblPhotoShufflerImgId);
	
  // determine delta based on number of fade seconds
  // the slower the fade the more increments needed
  var fadeDelta = 100 / (30 * gblFadeSeconds);

  // fade top out to reveal bottom image
  if (gblOpacity < 2*fadeDelta ) 
  {
    gblOpacity = 100;
    // stop the rotation if we're done
    if (gblImageRotations < 1) return;

    photoShufflerShuffle();
    // pause before next fade
    setTimeout("photoShufflerFade()",gblPauseSeconds*1000);

  } else  {

    gblOpacity -= fadeDelta;
    setOpacity(theimg,gblOpacity);
    setTimeout("photoShufflerFade()",30);  // 1/30th of a second

  }
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
