  //
  // CSS Linked Photo Shuffler v1.1 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 an anchor <a> and <div>. 
  //   specify unique id= in all three
  // * The first and final photo displayed is in the html <img> tag
  // * The image 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 Href array contains the link you want associated with each image
  //   each image must have a corresponding link.
  // * The rotations variable specifies how many times to repeat array.
  //   images. zero is a valid rotation value.

  var twentyfirstgblPhotoShufflerDivId = "photodiv21";
  var twentyfirstgblPhotoShufflerImgId = "photoimg21";
  var twentyfirstgblPhotoShufflerAnchorId = "photoanchor21";
  var twentyfirstgblImg = new Array(
    "images/slideshow/LorenzoAgius.jpg?v=0",
    "images/slideshow/ZubairAnsari.jpg?v=0",
    "images/slideshow/RogerHooper.jpg?v=0",
    "images/slideshow/RichardBryant.jpg?v=0"
    );
  var twentyfirstgblHref = new Array(
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo"
    );
  var twentyfirstgblPauseSeconds = 7;
  var twentyfirstgblFadeSeconds = 1;
  var twentyfirstgblRotations = 1000;

  // End Customization section
  
  var twentyfirstgblDeckSize = twentyfirstgblImg.length;
  var twentyfirstgblOpacity = 100;
  var twentyfirstgblOnDeck = 0;
  var twentyfirstgblStartImg;
  var twentyfirstgblStartHref;
  var twentyfirstgblImageRotations = twentyfirstgblDeckSize * (twentyfirstgblRotations+1);

// window.onload = twentyfirstphotoShufflerLaunch;
  
  function twentyfirstphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(twentyfirstgblPhotoShufflerImgId);
        twentyfirstgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(twentyfirstgblPhotoShufflerAnchorId);
        twentyfirstgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(twentyfirstgblPhotoShufflerDivId).style.backgroundImage='url(' + twentyfirstgblImg[twentyfirstgblOnDeck] + ')';
	setTimeout("twentyfirstphotoShufflerFade()",twentyfirstgblPauseSeconds*1000);
  }

  function twentyfirstphotoShufflerFade()
  {
  	var theimg = document.getElementById(twentyfirstgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade twentyfirsts
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * twentyfirstgblFadeSeconds);

	// fade top out to reveal bottom image
	if (twentyfirstgblOpacity < 2*fadeDelta ) 
	{
	  twentyfirstgblOpacity = 100;
	  // stop the rotation if we're done
	  if (twentyfirstgblImageRotations < 1) return;
	  twentyfirstphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("twentyfirstphotoShufflerFade()",twentyfirstgblPauseSeconds*1000);
	}
	else
	{
	  twentyfirstgblOpacity -= fadeDelta;
	  setOpacity(theimg,twentyfirstgblOpacity);
	  setTimeout("twentyfirstphotoShufflerFade()",30);  // 1/30th of a twentyfirst
	}
  }

  function twentyfirstphotoShufflerShuffle()
  {
	var thediv = document.getElementById(twentyfirstgblPhotoShufflerDivId);
	var theimg = document.getElementById(twentyfirstgblPhotoShufflerImgId);
	var theanchor = document.getElementById(twentyfirstgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = twentyfirstgblImg[twentyfirstgblOnDeck];
	theanchor.href = twentyfirstgblHref[twentyfirstgblOnDeck];
	window.status = twentyfirstgblHref[twentyfirstgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	twentyfirstgblOnDeck = ++twentyfirstgblOnDeck % twentyfirstgblDeckSize;
	// decrement rotation counter
	if (--twentyfirstgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  twentyfirstgblImg[twentyfirstgblOnDeck] = twentyfirstgblStartImg;
	  twentyfirstgblHref[twentyfirstgblOnDeck] = twentyfirstgblStartHref;
	}

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

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;
}



