  //
  // 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 ninthgblPhotoShufflerDivId = "photodiv9";
  var ninthgblPhotoShufflerImgId = "photoimg9";
  var ninthgblPhotoShufflerAnchorId = "photoanchor9";
  var ninthgblImg = new Array(
    "images/retouching2.jpg?v=0",
    "images/retouching3.jpg?v=0",
    "images/retouching4.jpg?v=0",
    "images/retouching1.jpg?v=0"
    );
  var ninthgblHref = new Array(
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo"
    );
  var ninthgblPauseSeconds = 3;
  var ninthgblFadeSeconds = 0.25;
  var ninthgblRotations = 1000;

  // End Customization section
  
  var ninthgblDeckSize = ninthgblImg.length;
  var ninthgblOpacity = 100;
  var ninthgblOnDeck = 0;
  var ninthgblStartImg;
  var ninthgblStartHref;
  var ninthgblImageRotations = ninthgblDeckSize * (ninthgblRotations+1);

// window.onload = ninthphotoShufflerLaunch;
  
  function ninthphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(ninthgblPhotoShufflerImgId);
        ninthgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(ninthgblPhotoShufflerAnchorId);
        ninthgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(ninthgblPhotoShufflerDivId).style.backgroundImage='url(' + ninthgblImg[ninthgblOnDeck] + ')';
	setTimeout("ninthphotoShufflerFade()",ninthgblPauseSeconds*1000);
  }

  function ninthphotoShufflerFade()
  {
  	var theimg = document.getElementById(ninthgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade ninths
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * ninthgblFadeSeconds);

	// fade top out to reveal bottom image
	if (ninthgblOpacity < 2*fadeDelta ) 
	{
	  ninthgblOpacity = 100;
	  // stop the rotation if we're done
	  if (ninthgblImageRotations < 1) return;
	  ninthphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("ninthphotoShufflerFade()",ninthgblPauseSeconds*1000);
	}
	else
	{
	  ninthgblOpacity -= fadeDelta;
	  setOpacity(theimg,ninthgblOpacity);
	  setTimeout("ninthphotoShufflerFade()",30);  // 1/30th of a ninth
	}
  }

  function ninthphotoShufflerShuffle()
  {
	var thediv = document.getElementById(ninthgblPhotoShufflerDivId);
	var theimg = document.getElementById(ninthgblPhotoShufflerImgId);
	var theanchor = document.getElementById(ninthgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = ninthgblImg[ninthgblOnDeck];
	theanchor.href = ninthgblHref[ninthgblOnDeck];
	window.status = ninthgblHref[ninthgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	ninthgblOnDeck = ++ninthgblOnDeck % ninthgblDeckSize;
	// decrement rotation counter
	if (--ninthgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  ninthgblImg[ninthgblOnDeck] = ninthgblStartImg;
	  ninthgblHref[ninthgblOnDeck] = ninthgblStartHref;
	}

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

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


