  //
  // 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 seventhgblPhotoShufflerDivId = "photodiv7";
  var seventhgblPhotoShufflerImgId = "photoimg7";
  var seventhgblPhotoShufflerAnchorId = "photoanchor7";
  var seventhgblImg = new Array(
    "images/after.jpg?v=0",
    "images/before.jpg?v=0"
    );
  var seventhgblHref = new Array(
    "photographic-image-retouching.html",
    "photographic-image-retouching.html"
    );
  var seventhgblPauseSeconds = 5;
  var seventhgblFadeSeconds = 1;
  var seventhgblRotations = 1000;

  // End Customization section
  
  var seventhgblDeckSize = seventhgblImg.length;
  var seventhgblOpacity = 100;
  var seventhgblOnDeck = 0;
  var seventhgblStartImg;
  var seventhgblStartHref;
  var seventhgblImageRotations = seventhgblDeckSize * (seventhgblRotations+1);

// window.onload = seventhphotoShufflerLaunch;
  
  function seventhphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(seventhgblPhotoShufflerImgId);
        seventhgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(seventhgblPhotoShufflerAnchorId);
        seventhgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(seventhgblPhotoShufflerDivId).style.backgroundImage='url(' + seventhgblImg[seventhgblOnDeck] + ')';
	setTimeout("seventhphotoShufflerFade()",seventhgblPauseSeconds*1000);
  }

  function seventhphotoShufflerFade()
  {
  	var theimg = document.getElementById(seventhgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade sevenths
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * seventhgblFadeSeconds);

	// fade top out to reveal bottom image
	if (seventhgblOpacity < 2*fadeDelta ) 
	{
	  seventhgblOpacity = 100;
	  // stop the rotation if we're done
	  if (seventhgblImageRotations < 1) return;
	  seventhphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("seventhphotoShufflerFade()",seventhgblPauseSeconds*1000);
	}
	else
	{
	  seventhgblOpacity -= fadeDelta;
	  setOpacity(theimg,seventhgblOpacity);
	  setTimeout("seventhphotoShufflerFade()",30);  // 1/30th of a seventh
	}
  }

  function seventhphotoShufflerShuffle()
  {
	var thediv = document.getElementById(seventhgblPhotoShufflerDivId);
	var theimg = document.getElementById(seventhgblPhotoShufflerImgId);
	var theanchor = document.getElementById(seventhgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = seventhgblImg[seventhgblOnDeck];
	theanchor.href = seventhgblHref[seventhgblOnDeck];
	window.status = seventhgblHref[seventhgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	seventhgblOnDeck = ++seventhgblOnDeck % seventhgblDeckSize;
	// decrement rotation counter
	if (--seventhgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  seventhgblImg[seventhgblOnDeck] = seventhgblStartImg;
	  seventhgblHref[seventhgblOnDeck] = seventhgblStartHref;
	}

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

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


