  //
  // 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 eigthgblPhotoShufflerDivId = "photodiv8";
  var eigthgblPhotoShufflerImgId = "photoimg8";
  var eigthgblPhotoShufflerAnchorId = "photoanchor8";
  var eigthgblImg = new Array(
    "images/rollerstand2.jpg?v=0",
    "images/rollerstand3.jpg?v=0",
    "images/rollerstand4.jpg?v=0",
    "images/rollerstand5.jpg?v=0",
	"images/rollerstand5.jpg?v=0",
    "images/rollerstand1.jpg?v=0"
    );
  var eigthgblHref = new Array(
    "#quickscreen",
    "#quickscreen",
    "#quickscreen",
    "#quickscreen",
    "#quickscreen",
    "#quickscreen"
    );
  var eigthgblPauseSeconds = 2;
  var eigthgblFadeSeconds = 0.25;
  var eigthgblRotations = 1000;

  // End Customization section
  
  var eigthgblDeckSize = eigthgblImg.length;
  var eigthgblOpacity = 100;
  var eigthgblOnDeck = 0;
  var eigthgblStartImg;
  var eigthgblStartHref;
  var eigthgblImageRotations = eigthgblDeckSize * (eigthgblRotations+1);

// window.onload = eigthphotoShufflerLaunch;
  
  function eigthphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(eigthgblPhotoShufflerImgId);
        eigthgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(eigthgblPhotoShufflerAnchorId);
        eigthgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(eigthgblPhotoShufflerDivId).style.backgroundImage='url(' + eigthgblImg[eigthgblOnDeck] + ')';
	setTimeout("eigthphotoShufflerFade()",eigthgblPauseSeconds*1000);
  }

  function eigthphotoShufflerFade()
  {
  	var theimg = document.getElementById(eigthgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade eigths
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * eigthgblFadeSeconds);

	// fade top out to reveal bottom image
	if (eigthgblOpacity < 2*fadeDelta ) 
	{
	  eigthgblOpacity = 100;
	  // stop the rotation if we're done
	  if (eigthgblImageRotations < 1) return;
	  eigthphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("eigthphotoShufflerFade()",eigthgblPauseSeconds*1000);
	}
	else
	{
	  eigthgblOpacity -= fadeDelta;
	  setOpacity(theimg,eigthgblOpacity);
	  setTimeout("eigthphotoShufflerFade()",30);  // 1/30th of a eigth
	}
  }

  function eigthphotoShufflerShuffle()
  {
	var thediv = document.getElementById(eigthgblPhotoShufflerDivId);
	var theimg = document.getElementById(eigthgblPhotoShufflerImgId);
	var theanchor = document.getElementById(eigthgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = eigthgblImg[eigthgblOnDeck];
	theanchor.href = eigthgblHref[eigthgblOnDeck];
	window.status = eigthgblHref[eigthgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	eigthgblOnDeck = ++eigthgblOnDeck % eigthgblDeckSize;
	// decrement rotation counter
	if (--eigthgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  eigthgblImg[eigthgblOnDeck] = eigthgblStartImg;
	  eigthgblHref[eigthgblOnDeck] = eigthgblStartHref;
	}

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

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


