  //
  // 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 fifthgblPhotoShufflerDivId = "photodiv5";
  var fifthgblPhotoShufflerImgId = "photoimg5";
  var fifthgblPhotoShufflerAnchorId = "photoanchor5";
  var fifthgblImg = new Array(
    "images/lambda11.jpg?v=0",
    "images/lambda12.jpg?v=0",
    "images/lambda10.jpg?v=0"
    );
  var fifthgblHref = new Array(
    "lambda-colour-prints.html",
    "lambda-colour-prints.html",
    "lambda-colour-prints.html"
    );
  var fifthgblPauseSeconds = 8;
  var fifthgblFadeSeconds = 1;
  var fifthgblRotations = 1000;

  // End Customization section
  
  var fifthgblDeckSize = fifthgblImg.length;
  var fifthgblOpacity = 100;
  var fifthgblOnDeck = 0;
  var fifthgblStartImg;
  var fifthgblStartHref;
  var fifthgblImageRotations = fifthgblDeckSize * (fifthgblRotations+1);

// window.onload = fifthphotoShufflerLaunch;
  
  function fifthphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(fifthgblPhotoShufflerImgId);
        fifthgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(fifthgblPhotoShufflerAnchorId);
        fifthgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(fifthgblPhotoShufflerDivId).style.backgroundImage='url(' + fifthgblImg[fifthgblOnDeck] + ')';
	setTimeout("fifthphotoShufflerFade()",fifthgblPauseSeconds*1000);
  }

  function fifthphotoShufflerFade()
  {
  	var theimg = document.getElementById(fifthgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade fifths
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * fifthgblFadeSeconds);

	// fade top out to reveal bottom image
	if (fifthgblOpacity < 2*fadeDelta ) 
	{
	  fifthgblOpacity = 100;
	  // stop the rotation if we're done
	  if (fifthgblImageRotations < 1) return;
	  fifthphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("fifthphotoShufflerFade()",fifthgblPauseSeconds*1000);
	}
	else
	{
	  fifthgblOpacity -= fadeDelta;
	  setOpacity(theimg,fifthgblOpacity);
	  setTimeout("fifthphotoShufflerFade()",30);  // 1/30th of a fifth
	}
  }

  function fifthphotoShufflerShuffle()
  {
	var thediv = document.getElementById(fifthgblPhotoShufflerDivId);
	var theimg = document.getElementById(fifthgblPhotoShufflerImgId);
	var theanchor = document.getElementById(fifthgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = fifthgblImg[fifthgblOnDeck];
	theanchor.href = fifthgblHref[fifthgblOnDeck];
	window.status = fifthgblHref[fifthgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	fifthgblOnDeck = ++fifthgblOnDeck % fifthgblDeckSize;
	// decrement rotation counter
	if (--fifthgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  fifthgblImg[fifthgblOnDeck] = fifthgblStartImg;
	  fifthgblHref[fifthgblOnDeck] = fifthgblStartHref;
	}

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

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


