﻿ // CSS Photo Shuffler v1.0 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.



window.onload=function(){
photoShufflerLaunch();
photoShufflerLaunch2();
photoShufflerLaunch3();
}
  
  var gblPhotoShufflerDivId = "photodiv_active";
  var gblPhotoShufflerImgId = "img_active"; 
  var gblImg = new Array(
    "/images/homefeature/active2.jpg",
    "/images/homefeature/active3.jpg",
    "/images/homefeature/active4.jpg",
    "/images/homefeature/active5.jpg",
    "/images/homefeature/active6.jpg",
    "/images/homefeature/active7.jpg"
    );
  var gblPauseSeconds = 7;
  var gblFadeSeconds = 1;
  var gblRotations = 10;

  // End Customization section 1
  
  var gblPhotoShufflerDivId2 = "photodiv_walking";
  var gblPhotoShufflerImgId2 = "img_walking"; 
  var gblImg2 = new Array(
 	"/images/homefeature/walking2.jpg",
    "/images/homefeature/walking3.jpg",
    "/images/homefeature/walking1.jpg",
    "/images/homefeature/walking4.jpg",
    "/images/homefeature/walking5.jpg",
    "/images/homefeature/walking6.jpg"
    );
  var gblPauseSeconds2 = 6;
  var gblFadeSeconds2 = 1;
  var gblRotations2 = 10;

  // End Customization section 2   
  
   var gblPhotoShufflerDivId3 = "photodiv_courses";
  var gblPhotoShufflerImgId3 = "img_courses"; 
  var gblImg3 = new Array(
    "/images/homefeature/courses2.jpg",
    "/images/homefeature/courses3.jpg",
    "/images/homefeature/courses4.jpg",
    "/images/homefeature/courses5.jpg",
    "/images/homefeature/courses6.jpg",
    "/images/homefeature/courses7.jpg",
    "/images/homefeature/courses8.jpg"
    );
  var gblPauseSeconds3 = 5;
  var gblFadeSeconds3 = 1;
  var gblRotations3 = 10;

  // End Customization section 3
  

  
  
  
  
  var gblDeckSize = gblImg.length;
  var gblOpacity = 100;
  var gblOnDeck = 0;
  var gblStartImg;
  var gblImageRotations = gblDeckSize * (gblRotations+1);
  
  function photoShufflerLaunch()
  {
  	var theimg = document.getElementById(gblPhotoShufflerImgId);
        gblStartImg = theimg.src; // save away to show as final image

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

  function photoShufflerFade()
  {
  	var theimg = document.getElementById(gblPhotoShufflerImgId);
	
  	// 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);
	  setTimeout("photoShufflerFade()",30);  // 1/30th of a second
	}
  }

  function photoShufflerShuffle()
  {
	var thediv = document.getElementById(gblPhotoShufflerDivId);
	var theimg = document.getElementById(gblPhotoShufflerImgId);
	
	// copy div background-image to img.src
	theimg.src = gblImg[gblOnDeck];
	// 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;
	}

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

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




//set 2



  
  var gblDeckSize2 = gblImg2.length;
  var gblOpacity2 = 100;
  var gblOnDeck2 = 0;
  var gblStartImg2;
  var gblImageRotations2 = gblDeckSize2 * (gblRotations2+1);
  
  function photoShufflerLaunch2()
  {
  	var theimg2 = document.getElementById(gblPhotoShufflerImgId2);
        gblStartImg2 = theimg2.src; // save away to show as final image

	document.getElementById(gblPhotoShufflerDivId2).style.backgroundImage='url(' + gblImg2[gblOnDeck2] + ')';
	setTimeout("photoShufflerFade2()",gblPauseSeconds2*1000);
  }

  function photoShufflerFade2()
  {
  	var theimg2 = document.getElementById(gblPhotoShufflerImgId2);
	
  	// determine delta based on number of fade seconds
	// the slower the fade the more increments needed
        var fadeDelta2 = 100 / (30 * gblFadeSeconds2);

	// fade top out to reveal bottom image
	if (gblOpacity2 < 2*fadeDelta2 ) 
	{
	  gblOpacity2 = 100;
	  // stop the rotation if we're done
	  if (gblImageRotations2 < 1) return;
	  photoShufflerShuffle2();
	  // pause before next fade
          setTimeout("photoShufflerFade2()",gblPauseSeconds2*1000);
	}
	else
	{
	  gblOpacity2 -= fadeDelta2;
	  setOpacity2(theimg2,gblOpacity2);
	  setTimeout("photoShufflerFade2()",30);  // 1/30th of a second
	}
  }

  function photoShufflerShuffle2()
  {
	var thediv2 = document.getElementById(gblPhotoShufflerDivId2);
	var theimg2 = document.getElementById(gblPhotoShufflerImgId2);
	
	// copy div background-image to img.src
	theimg2.src = gblImg2[gblOnDeck2];
	// set img opacity to 100
	setOpacity2(theimg2,100);

        // shuffle the deck
	gblOnDeck2 = ++gblOnDeck2 % gblDeckSize2;
	// decrement rotation counter
	if (--gblImageRotations2 < 1)
	{
	  // insert start/final image if we're done
	  gblImg2[gblOnDeck2] = gblStartImg2;
	}

	// slide next image underneath
	thediv2.style.backgroundImage='url(' + gblImg2[gblOnDeck2] + ')';
  }

function setOpacity2(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;
}
  
  
  //set 3



  
  var gblDeckSize3 = gblImg3.length;
  var gblOpacity3 = 100;
  var gblOnDeck3 = 0;
  var gblStartImg3;
  var gblImageRotations3 = gblDeckSize3 * (gblRotations3+1);
  
  function photoShufflerLaunch3()
  {
  	var theimg3 = document.getElementById(gblPhotoShufflerImgId3);
        gblStartImg3 = theimg3.src; // save away to show as final image

	document.getElementById(gblPhotoShufflerDivId3).style.backgroundImage='url(' + gblImg3[gblOnDeck3] + ')';
	setTimeout("photoShufflerFade3()",gblPauseSeconds3*1000);
  }

  function photoShufflerFade3()
  {
  	var theimg3 = document.getElementById(gblPhotoShufflerImgId3);
	
  	// determine delta based on number of fade seconds
	// the slower the fade the more increments needed
        var fadeDelta3 = 100 / (30 * gblFadeSeconds3);

	// fade top out to reveal bottom image
	if (gblOpacity3 < 2*fadeDelta3 ) 
	{
	  gblOpacity3 = 100;
	  // stop the rotation if we're done
	  if (gblImageRotations3 < 1) return;
	  photoShufflerShuffle3();
	  // pause before next fade
          setTimeout("photoShufflerFade3()",gblPauseSeconds3*1000);
	}
	else
	{
	  gblOpacity3 -= fadeDelta3;
	  setOpacity3(theimg3,gblOpacity3);
	  setTimeout("photoShufflerFade3()",30);  // 1/30th of a second
	}
  }

  function photoShufflerShuffle3()
  {
	var thediv3 = document.getElementById(gblPhotoShufflerDivId3);
	var theimg3 = document.getElementById(gblPhotoShufflerImgId3);
	
	// copy div background-image to img.src
	theimg3.src = gblImg3[gblOnDeck3];
	// set img opacity to 100
	setOpacity3(theimg3,100);

        // shuffle the deck
	gblOnDeck3 = ++gblOnDeck3 % gblDeckSize3;
	// decrement rotation counter
	if (--gblImageRotations3 < 1)
	{
	  // insert start/final image if we're done
	  gblImg3[gblOnDeck3] = gblStartImg3;
	}

	// slide next image underneath
	thediv3.style.backgroundImage='url(' + gblImg3[gblOnDeck3] + ')';
  }

function setOpacity3(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;
}
