  //
  // 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 a <div>. specify id= in both
  // * The first and final photo displayed is in the html <img> tag
  // * The 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 rotations variable specifies how many times to repeat array.
  //   images. zero is a valid rotation value.

  var divID = "photodiv";
  var imgID = "photoimg";
//  var AncId = "photoanchor";
  var gblImg = new Array("images/threads-photo-1.jpg", "images/threads-photo-2.jpg", "images/threads-photo-3.jpg",
               "images/threads-photo-4.jpg", "images/threads-photo-5.jpg", "images/threads-photo-6.jpg",
	       "images/threads-photo-7.jpg", "images/threads-photo-8.jpg", "images/threads-photo-9.jpg",
	       "images/threads-photo-10.jpg", "images/threads-photo-11.jpg", "images/threads-photo-12.jpg",
	       "images/threads-photo-14.jpg", "images/threads-photo-13.jpg");
  //var gblAlt = new Array("Backwards group with bags", "Up side down group with bags", "Group with bags");
//  var gblHref = new Array();
  var gblPauseSeconds = 7.25;
  var gblFadeSeconds = .85;
  var gblRotations = 10;

  // End Customization section
  var gblDeckSize = gblImg.length;
  var gblOpacity = 100;
  var gblOnDeck = 0;
  var gblStartImg;
  var gblStartHref;
  var gblImageRotations = gblDeckSize * (gblRotations+1);
  window.onload = photoShufflerLaunch;

  function photoShufflerLaunch() {
  	var theimg = document.getElementById(imgID);
    gblStartImg = theimg.src;
//  	var theanchor = document.getElementById(AncId);
	gblStartHref = theimg.href;
	document.getElementById(divID).style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
	setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
  }

  function photoShufflerFade() {
  	var theimg = document.getElementById(imgID);
	var fadeDelta = 100 / (30 * gblFadeSeconds);
	if (gblOpacity < 2*fadeDelta ) {
		gblOpacity = 100;
//		if (gblImageRotations < 1) return;
		photoShufflerShuffle();
		setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
	} else {
	  gblOpacity -= fadeDelta;
	  setOpacity(theimg,gblOpacity);
	  setTimeout("photoShufflerFade()",30);  // 1/30th of a second
	}
  }
  function photoShufflerShuffle()
  {
	var thediv = document.getElementById(divID);
	var theimg = document.getElementById(imgID);
//	var theanchor = document.getElementById(AncId);
	theimg.src = gblImg[gblOnDeck];
//	theimg.alt = gblAlt[gblOnDeck];
//	theanchor.href = gblHref[gblOnDeck];
//	window.status = gblHref[gblOnDeck];
	setOpacity(theimg,100);
	gblOnDeck = ++gblOnDeck % gblDeckSize;
//	if (--gblImageRotations < 1)
//	{
//	  gblImg[gblOnDeck] = gblStartImg;
//	  gblHref[gblOnDeck] = gblStartHref;
//	}
	thediv.style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
  }

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  obj.style.filter = "alpha(opacity:"+opacity+")";
  obj.style.KHTMLOpacity = opacity/100;
  obj.style.MozOpacity = opacity/100;
  obj.style.opacity = opacity/100;
}
