

  //
  // 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
  // * set background-repeat:no-repeat in CSS for the div
  // * 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 gblPhotoShufflerDivId1 = "hImage";
  var gblPhotoShufflerImgId1 = "hImageImg";
  var gblImg1 = new Array(
    "./img/prague-apartment-rentals/hungerwall1.jpg",
    "./img/prague-apartment-rentals/hungerwall2.jpg",
    "./img/prague-apartment-rentals/hungerwall3.jpg",
    "./img/prague-apartment-rentals/hungerwall4.jpg",
    "./img/prague-apartment-rentals/hungerwall5.jpg",
    "./img/prague-apartment-rentals/hungerwall6.jpg"
  );
  
  var gblPhotoShufflerDivId2 = "aImage";
  var gblPhotoShufflerImgId2 = "aImageImg";
  var gblImg2 = new Array(
    "./img/prague-apartment-rentals/apartments1.jpg",
    "./img/prague-apartment-rentals/apartments6.jpg",
    "./img/prague-apartment-rentals/apartments2.jpg",
    "./img/prague-apartment-rentals/apartments3.jpg",
    "./img/prague-apartment-rentals/apartments4.jpg",
    "./img/prague-apartment-rentals/apartments5.jpg"
  );
  
  var gblPauseSeconds = 3;
  var gblFadeSeconds = .85;
  var gblRotations = 10000;

  // End Customization section
  
  var gblDeckSize1 = gblImg1.length;
  var gblDeckSize2 = gblImg2.length;
  var gblOpacity = 100;
  var gblOnDeck1 = 1;
  var gblOnDeck2 = 1;
  var gblStartImg1;
  var gblStartImg2;
  var gblImageRotations1 = gblDeckSize1 * (gblRotations+1);
  var gblImageRotations2 = gblDeckSize2 * (gblRotations+1);

  window.onload = photoShufflerLaunch;
  
  function photoShufflerLaunch()
  {
    // save away to show as final image
    gblStartImg1 = document.getElementById(gblPhotoShufflerImgId1).src;
	gblStartImg2 = document.getElementById(gblPhotoShufflerImgId2).src;

	document.getElementById(gblPhotoShufflerDivId1).style.backgroundImage='url(' + gblImg1[gblOnDeck1] + ')';
	document.getElementById(gblPhotoShufflerDivId2).style.backgroundImage='url(' + gblImg2[gblOnDeck2] + ')';
	setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
  }

  function photoShufflerFade()
  {
  	var theimg1 = document.getElementById(gblPhotoShufflerImgId1);
  	var theimg2 = document.getElementById(gblPhotoShufflerImgId2);
	
  	// 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 (Math.max(gblImageRotations1, gblImageRotations2) < 1) return;
	  photoShufflerShuffle();
	  // pause before next fade
          setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
	}
	else
	{
	  gblOpacity -= fadeDelta;
	  setOpacity(theimg1,gblOpacity);
	  setOpacity(theimg2,gblOpacity);
	  setTimeout("photoShufflerFade()",30);  // 1/30th of a second
	}
  }

  function photoShufflerShuffle()
  {
	var thediv1 = document.getElementById(gblPhotoShufflerDivId1);
	var theimg1 = document.getElementById(gblPhotoShufflerImgId1);
	var thediv2 = document.getElementById(gblPhotoShufflerDivId2);
	var theimg2 = document.getElementById(gblPhotoShufflerImgId2);
	
	// copy div background-image to img.src
	theimg1.src = gblImg1[gblOnDeck1];
	theimg2.src = gblImg2[gblOnDeck2];
	// set img opacity to 100
	setOpacity(theimg1,100);
	setOpacity(theimg2,100);

    // shuffle the deck
	gblOnDeck1 = ++gblOnDeck1 % gblDeckSize1;
	gblOnDeck2 = ++gblOnDeck2 % gblDeckSize2;

	// decrement rotation counter
	if (--gblImageRotations1 < 1)
	{
	  // insert start/final image if we're done
	  gblImg1[gblOnDeck1] = gblStartImg1;
	}
	
	if (--gblImageRotations2 < 1)
	{
	  // insert start/final image if we're done
	  gblImg2[gblOnDeck2] = gblStartImg2;
	}

	// slide next image underneath
	thediv1.style.backgroundImage='url(' + gblImg1[gblOnDeck1] + ')';
	thediv2.style.backgroundImage='url(' + gblImg2[gblOnDeck2] + ')';
  }

  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;
  }




