  //
  // 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 fiveteenthgblPhotoShufflerDivId = "photodiv15";
  var fiveteenthgblPhotoShufflerImgId = "photoimg15";
  var fiveteenthgblPhotoShufflerAnchorId = "photoanchor15";
  var fiveteenthgblImg = new Array(
    "images/giclee7.jpg?v=0",
    "images/giclee5.jpg?v=0",
    "images/giclee4.jpg?v=0"
    );
  var fiveteenthgblHref = new Array(
    "#nogo",
    "#nogo",
    "#nogo"
    );
  var fiveteenthgblPauseSeconds = 6;
  var fiveteenthgblFadeSeconds = 0.25;
  var fiveteenthgblRotations = 1000;

  // End Customization section
  
  var fiveteenthgblDeckSize = fiveteenthgblImg.length;
  var fiveteenthgblOpacity = 100;
  var fiveteenthgblOnDeck = 0;
  var fiveteenthgblStartImg;
  var fiveteenthgblStartHref;
  var fiveteenthgblImageRotations = fiveteenthgblDeckSize * (fiveteenthgblRotations+1);

// window.onload = fiveteenthphotoShufflerLaunch;
  
  function fiveteenthphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(fiveteenthgblPhotoShufflerImgId);
        fiveteenthgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(fiveteenthgblPhotoShufflerAnchorId);
        fiveteenthgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(fiveteenthgblPhotoShufflerDivId).style.backgroundImage='url(' + fiveteenthgblImg[fiveteenthgblOnDeck] + ')';
	setTimeout("fiveteenthphotoShufflerFade()",fiveteenthgblPauseSeconds*1000);
  }

  function fiveteenthphotoShufflerFade()
  {
  	var theimg = document.getElementById(fiveteenthgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade fiveteenths
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * fiveteenthgblFadeSeconds);

	// fade top out to reveal bottom image
	if (fiveteenthgblOpacity < 2*fadeDelta ) 
	{
	  fiveteenthgblOpacity = 100;
	  // stop the rotation if we're done
	  if (fiveteenthgblImageRotations < 1) return;
	  fiveteenthphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("fiveteenthphotoShufflerFade()",fiveteenthgblPauseSeconds*1000);
	}
	else
	{
	  fiveteenthgblOpacity -= fadeDelta;
	  setOpacity(theimg,fiveteenthgblOpacity);
	  setTimeout("fiveteenthphotoShufflerFade()",30);  // 1/30th of a fiveteenth
	}
  }

  function fiveteenthphotoShufflerShuffle()
  {
	var thediv = document.getElementById(fiveteenthgblPhotoShufflerDivId);
	var theimg = document.getElementById(fiveteenthgblPhotoShufflerImgId);
	var theanchor = document.getElementById(fiveteenthgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = fiveteenthgblImg[fiveteenthgblOnDeck];
	theanchor.href = fiveteenthgblHref[fiveteenthgblOnDeck];
	window.status = fiveteenthgblHref[fiveteenthgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	fiveteenthgblOnDeck = ++fiveteenthgblOnDeck % fiveteenthgblDeckSize;
	// decrement rotation counter
	if (--fiveteenthgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  fiveteenthgblImg[fiveteenthgblOnDeck] = fiveteenthgblStartImg;
	  fiveteenthgblHref[fiveteenthgblOnDeck] = fiveteenthgblStartHref;
	}

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

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


