  //
  // 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 twelvthgblPhotoShufflerDivId = "photodiv12";
  var twelvthgblPhotoShufflerImgId = "photoimg12";
  var twelvthgblPhotoShufflerAnchorId = "photoanchor12";
  var twelvthgblImg = new Array(
    "images/podium2.jpg?v=0",
    "images/podium3.jpg?v=0",
    "images/podium4.jpg?v=0",
    "images/podium5.jpg?v=0",
	"images/podium6.jpg?v=0",
	"images/podium7.jpg?v=0",
	"images/podium7.jpg?v=0",
    "images/podium1.jpg?v=0"
    );
  var twelvthgblHref = new Array(
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo",
    "#nogo"
    );
  var twelvthgblPauseSeconds = 2;
  var twelvthgblFadeSeconds = 0.25;
  var twelvthgblRotations = 1000;

  // End Customization section
  
  var twelvthgblDeckSize = twelvthgblImg.length;
  var twelvthgblOpacity = 100;
  var twelvthgblOnDeck = 0;
  var twelvthgblStartImg;
  var twelvthgblStartHref;
  var twelvthgblImageRotations = twelvthgblDeckSize * (twelvthgblRotations+1);

// window.onload = twelvthphotoShufflerLaunch;
  
  function twelvthphotoShufflerLaunch()
  {
  	var theimg = document.getElementById(twelvthgblPhotoShufflerImgId);
        twelvthgblStartImg = theimg.src; // save away to show as final image
  	var theanchor = document.getElementById(twelvthgblPhotoShufflerAnchorId);
        twelvthgblStartHref = theimg.href; // save away to show as final image

	document.getElementById(twelvthgblPhotoShufflerDivId).style.backgroundImage='url(' + twelvthgblImg[twelvthgblOnDeck] + ')';
	setTimeout("twelvthphotoShufflerFade()",twelvthgblPauseSeconds*1000);
  }

  function twelvthphotoShufflerFade()
  {
  	var theimg = document.getElementById(twelvthgblPhotoShufflerImgId);
	
  	// determine delta based on number of fade twelvths
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * twelvthgblFadeSeconds);

	// fade top out to reveal bottom image
	if (twelvthgblOpacity < 2*fadeDelta ) 
	{
	  twelvthgblOpacity = 100;
	  // stop the rotation if we're done
	  if (twelvthgblImageRotations < 1) return;
	  twelvthphotoShufflerShuffle();
	  // pause before next fade
          setTimeout("twelvthphotoShufflerFade()",twelvthgblPauseSeconds*1000);
	}
	else
	{
	  twelvthgblOpacity -= fadeDelta;
	  setOpacity(theimg,twelvthgblOpacity);
	  setTimeout("twelvthphotoShufflerFade()",30);  // 1/30th of a twelvth
	}
  }

  function twelvthphotoShufflerShuffle()
  {
	var thediv = document.getElementById(twelvthgblPhotoShufflerDivId);
	var theimg = document.getElementById(twelvthgblPhotoShufflerImgId);
	var theanchor = document.getElementById(twelvthgblPhotoShufflerAnchorId);
	
	// copy div background-image to img.src
	theimg.src = twelvthgblImg[twelvthgblOnDeck];
	theanchor.href = twelvthgblHref[twelvthgblOnDeck];
	window.status = twelvthgblHref[twelvthgblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

        // shuffle the deck
	twelvthgblOnDeck = ++twelvthgblOnDeck % twelvthgblDeckSize;
	// decrement rotation counter
	if (--twelvthgblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  twelvthgblImg[twelvthgblOnDeck] = twelvthgblStartImg;
	  twelvthgblHref[twelvthgblOnDeck] = twelvthgblStartHref;
	}

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

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


