
  //
  // 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/
  //
  
  // Edited 17/7/08 by Fred Riley

  // 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 gblPhotoShufflerDivId = "photodiv";
  var gblPhotoShufflerImgId = "photoimg";
  var gblPhotoShufflerAnchorId = "photoanchor";
  // added by FR
  var gblPhotoShufflerCaptionId = "photocaption";
/*  var gblImg = new Array(
    "http://static.flickr.com/44/110860008_3086e0bce5.jpg?v=0",
    "http://static.flickr.com/53/149069166_3311afe82d.jpg?v=0",
    "http://static.flickr.com/44/149069119_1080dfd3ef.jpg?v=0"
    );
*/

  // initialise array of screenshot image refs
  // relative reference to position of rlos/index.php where the shuffler appears
  var gblImg = new Array(
		"shuffler/screenshots/acids01.jpg",
		"shuffler/screenshots/aminoscreen01.jpg",
		"shuffler/screenshots/antt1.jpg",
		"shuffler/screenshots/bacteria_viruses1.jpg",
		"shuffler/screenshots/dyslexia_workplace_learning1.jpg",
		"shuffler/screenshots/glove_use1.jpg",
		"shuffler/screenshots/hand_hygiene1.jpg",
		"shuffler/screenshots/ventilation1.jpg",
		"shuffler/screenshots/hydrogen_bonding1.jpg",
		"shuffler/screenshots/inflam_ill01.jpg",
		"shuffler/screenshots/solutions_electrolytes1.jpg",
		"shuffler/screenshots/trialresults_section5.jpg"
	)
  
  // initialise array of RLO URLs, in same order as screenshots
  var gblHref = new Array(
    "http://www.nottingham.ac.uk/nursing/sonet/rlos/science/acid_base_intro/",
    "http://www.nottingham.ac.uk/nursing/sonet/rlos/bioproc/aminoglycosides/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/placs/antt/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/bioproc/bacteria/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/placs/dyslexia2/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/placs/gloves/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/placs/handwashing/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/bioproc/ventilation/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/science/hydrogen_bonding/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/bioproc/inflam/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/science/solutions/",
	"http://www.nottingham.ac.uk/nursing/sonet/rlos/ebp/trial_results/"
	
    );
  
  //  initialise array of image captions, usually RLO titles
  var gblCaption = new Array(
		"Acids, Alkalis and Bases: an Introduction", 
		"Aminoglycosides",
		"Aseptic Non-Touch Technique",
		"Bacteria and viruses compared",
		"Dyslexia and Workplace Learning",
		"Glove use",
		"Hand Hygiene",
		"Respiratory ventilation: anatomy and mechanics",
		"Hydrogen Bonding",
		"The Inflammatory response",
		"Solutions and Electrolytes",
		"Determining the Clinical Importance of Trial Results"
		)
  
  var gblPauseSeconds = 3.25;
  var gblFadeSeconds = .85;
  // set number of 'shows' to 100, meaning that it'll be continuous for the average user
  var gblRotations = 100;

  // 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()
  {
	  	// get handle of the <img> tag
  	var theimg = document.getElementById(gblPhotoShufflerImgId);
        gblStartImg = theimg.src; // save away to show as final image
		// get handle of the <a> enclosing the <img>
  	var theanchor = document.getElementById(gblPhotoShufflerAnchorId);
        gblStartHref = theimg.href; // save away to show as final image
	// added by FR	
	// get handle of the <div> holding the caption
	var thecaption = document.getElementById(gblPhotoShufflerCaptionId);

	document.getElementById(gblPhotoShufflerDivId).style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
	setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
  }

  function photoShufflerFade()
  {
  	var theimg = document.getElementById(gblPhotoShufflerImgId);
	// added by FR
	//var thediv = document.getElementById(gblPhotoShufflerDivId);

	
  	// determine delta based on number of fade seconds
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * gblFadeSeconds);

	// fade top out to reveal bottom image
	if (gblOpacity < 2*fadeDelta ) 
	{
	  gblOpacity = 100;
	  // stop the rotation if we're done
	  if (gblImageRotations < 1) return;
	  photoShufflerShuffle();
	  // pause before next fade
          setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
	}
	else
	{
	  gblOpacity -= fadeDelta;
	  setOpacity(theimg,gblOpacity);
	  // added by FR
	  //setOpacity(thediv,100-gblOpacity);
	  setTimeout("photoShufflerFade()",30);  // 1/30th of a second
	}
  }

  function photoShufflerShuffle()
  {
	// get handle of the <div> holding the <img>
	var thediv = document.getElementById(gblPhotoShufflerDivId);
	var theimg = document.getElementById(gblPhotoShufflerImgId);
	var theanchor = document.getElementById(gblPhotoShufflerAnchorId);
	// added by FR
	var thecaption = document.getElementById(gblPhotoShufflerCaptionId);
	
	// copy div background-image to img.src
	theimg.src = gblImg[gblOnDeck];
	theanchor.href = gblHref[gblOnDeck];
	// added by FR
	var captiontext = "<a href=\"" + theanchor + "\">" + gblCaption[gblOnDeck] + "</a>";
	//thecaption.innerHTML = gblCaption[gblOnDeck];
	thecaption.innerHTML = captiontext;
	
	window.status = gblHref[gblOnDeck]; // updates status bar (optional)
	// set img opacity to 100
	setOpacity(theimg,100);

// shuffle the deck
	gblOnDeck = ++gblOnDeck % gblDeckSize;
	// decrement rotation counter
	if (--gblImageRotations < 1)
	{
	  // insert start/final image if we're done
	  gblImg[gblOnDeck] = gblStartImg;
	  gblHref[gblOnDeck] = gblStartHref;
	}

	// slide next image underneath
	thediv.style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
	// added by FR
	//setOpacity(thediv,100);
  }

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



