  //
  // 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 thirdgblPhotoShufflerDivId = "photodiv3";
  var thirdgblPhotoShufflerImgId = "photoimg3";
  var thirdgblPhotoShufflerAnchorId = "photoanchor3";
  var thirdgblImg = new Array(
    "photography/travel-photography/thumbs/j.aparicio-004s.jpg?v=0",
	"photography/still-life-photography/thumbs/j.aparicio-001s.jpg?v=0",
    "photography/portrait-photography/thumbs/j.aparicio-002s.jpg?v=0",
    "photography/corporate-photography/thumbs/j.aparicio-005s.jpg?v=0"
    );
  var thirdgblHref = new Array(
    "photographer/travel-photography.html",
	"photographer/still-life-photography.html",
	"photographer/portrait-photography.html",
    "photographer/corporate-photography.html"
    );
  var thirdgblPauseSeconds = 6;
  var thirdgblFadeSeconds = 1;
  var thirdgblRotations = 1000;

  // End Customization section
  
  var thirdgblDeckSize = thirdgblImg.length;
  var thirdgblOpacity = 100;
  var thirdgblOnDeck = 0;
  var thirdgblStartImg;
  var thirdgblStartHref;
  var thirdgblImageRotations = thirdgblDeckSize * (thirdgblRotations+1);

// window.onload = thirdphotoShufflerLaunch;
  
  function thirdphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(thirdgblPhotoShufflerImgId);
        thirdgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(thirdgblPhotoShufflerAnchorId);
        thirdgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(thirdgblPhotoShufflerDivId).style.backgroundImage='url(' + thirdgblImg[thirdgblOnDeck] + ')';
	setTimeout("thirdphotoShufflerFade()",thirdgblPauseSeconds*1000);
  }

  function thirdphotoShufflerFade()
  {
  	var theimg = document.getElementById(thirdgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade thirds
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * thirdgblFadeSeconds);

	// fade top out to reveal bottom image
	if (thirdgblOpacity < 2*fadeDelta ) 
	{
	  thirdgblOpacity = 100;
	  // stop the rotation if we're done
	  if (thirdgblImageRotations < 1) return;
	  thirdphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("thirdphotoShufflerFade()",thirdgblPauseSeconds*1000);
	}
	else
	{
	  thirdgblOpacity -= fadeDelta;
	  setOpacity(theimg,thirdgblOpacity);
	  setTimeout("thirdphotoShufflerFade()",30);  // 1/30th of a third
	}
  }

  function thirdphotoShufflerShuffle()
  {
	var thediv = document.getElementById(thirdgblPhotoShufflerDivId);
	var theimg = document.getElementById(thirdgblPhotoShufflerImgId);
	var theanchor = document.getElementById(thirdgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = thirdgblImg[thirdgblOnDeck];
	theanchor.href = thirdgblHref[thirdgblOnDeck];
	window.status = thirdgblHref[thirdgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	thirdgblOnDeck = ++thirdgblOnDeck % thirdgblDeckSize;
	// decrement rotation counter
	if (--thirdgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  thirdgblImg[thirdgblOnDeck] = thirdgblStartImg;
	  thirdgblHref[thirdgblOnDeck] = thirdgblStartHref;
	}

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

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


