  //
  // CSS Photo Shuffler v1.0 by
  //   Carl Camera
  //   http://iamacamera.org 
  //
  // SetOpacity Function and inpiration from Photo Fade by
  //   Richard Rutter
  //   http://clagnut.com
  //
  // License: Creative Commons Attribution 2.5  License
  //   http://creativecommons.org/licenses/by/2.5/
  //
  
  // Customize your photo shuffle settings
  // 
  // * Surround the target <img /> with a <div>. specify id= in both
  // * The first and final photo displayed is in the html <img> tag
  // * The array contains paths to photos you want in the rotation. 
  //   If you want the first photo in the rotation, then it's best to
  //   put it as the final array image.  All photos must be same dimension
  // * The rotations variable specifies how many times to repeat array.
  //   images. zero is a valid rotation value.

  var gblPhotoShufflerDivId4 = "shufflediv4";
  var gblPhotoShufflerImgId4 = "photoshuffle4"; 
  var gblImg4 = new Array(
      "/images/shell/photos/img4_2.jpg",
      "/images/shell/photos/img4_3.jpg",
      "/images/shell/photos/img4_4.jpg",
	  "/images/shell/photos/img4_5.jpg",
	  "/images/shell/photos/img4_6.jpg",
	  "/images/shell/photos/img4_1.jpg");
  var gblPauseSeconds4 = 16;
  var gblFadeSeconds4 = .85;
  var gblRotations4 = 50;

  // End Customization section
  
  var gblDeckSize4 = gblImg4.length;
  var gblOpacity4 = 100;
  var gblOnDeck4 = 0;
  var gblStartImg4;
  var gblImageRotations4 = gblDeckSize4 * (gblRotations4+1);

  window.onload = function() {
	  photoShufflerLaunch();
	  window.setTimeout(photoShufflerLaunch2, 4000);
	  window.setTimeout(photoShufflerLaunch3, 8000);
	  window.setTimeout(photoShufflerLaunch4, 12000);
  };
  
  function photoShufflerLaunch4()
  {
  	var theimg4 = document.getElementById(gblPhotoShufflerImgId4);
        gblStartImg4 = theimg4.src; // save away to show as final image

	document.getElementById(gblPhotoShufflerDivId4).style.backgroundImage='url(' + gblImg4[gblOnDeck4] + ')';
	setTimeout("photoShufflerFade4()",gblPauseSeconds4*1000);
  }

  function photoShufflerFade4()
  {
  	var theimg4 = document.getElementById(gblPhotoShufflerImgId4);
	
  	// determine delta based on number of fade seconds
	// the slower the fade the more increments needed
        var fadeDelta4 = 100 / (30 * gblFadeSeconds4);

	// fade top out to reveal bottom image
	if (gblOpacity4 < 2*fadeDelta4 ) 
	{
	  gblOpacity4 = 100;
	  // stop the rotation if we're done
	  if (gblImageRotations4 < 1) return;
	  photoShufflerShuffle4();
	  // pause before next fade
          setTimeout("photoShufflerFade4()",gblPauseSeconds4*1000);
	}
	else
	{
	  gblOpacity4 -= fadeDelta4;
	  setOpacity4(theimg4,gblOpacity4);
	  setTimeout("photoShufflerFade4()",30);  // 1/30th of a second
	}
  }

  function photoShufflerShuffle4()
  {
	var thediv4 = document.getElementById(gblPhotoShufflerDivId4);
	var theimg4 = document.getElementById(gblPhotoShufflerImgId4);
	
	// copy div background-image to img.src
	theimg4.src = gblImg4[gblOnDeck4];
	// set img opacity to 100
	setOpacity4(theimg4,100);

        // shuffle the deck
	gblOnDeck4 = ++gblOnDeck4 % gblDeckSize4;
	// decrement rotation counter
	if (--gblImageRotations4 < 1)
	{
	  // insert start/final image if we're done
	  gblImg4[gblOnDeck4] = gblStartImg4;
	}

	// slide next image underneath
	thediv4.style.backgroundImage='url(' + gblImg4[gblOnDeck4] + ')';
  }

function setOpacity4(obj4, opacity4) {
  opacity4 = (opacity4 == 100)?99.999:opacity4;
  
  // IE/Win
  obj4.style.filter = "alpha(opacity:"+opacity4+")";
  
  // Safari<1.2, Konqueror
  obj4.style.KHTMLOpacity = opacity4/100;
  
  // Older Mozilla and Firefox
  obj4.style.MozOpacity = opacity4/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj4.style.opacity = opacity4/100;
}


