

//
// 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 gblPhotoShufflerDivId = "photodiv";
var gblPhotoShufflerImgId = "photoimg";
var gblImg = new Array(
  "images/Darwin&Barbara_t.gif",
  "images/Darwin&Barbara2_t.gif"
    );
    
var gblPosArray = new Array(
    600,
    500,
    650,
    700,
    550
    );

var gblPosSize = gblPosArray.length;
var gblPosIndex = 0;
      
var gblPauseSeconds = 0.25;
var gblFadeSeconds = 1.85;
var gblRotations = 10;

// End Customization section

var gblDeckSize = gblImg.length;
var gblOpacity = 100;
var gblOnDeck = 0;
var gblStartImg;
var gblImageRotations = gblDeckSize * (gblRotations + 1);
var gblPicPosX = 350;

//window.onload = FaderLaunch;

function debug()
{
	/*
	var x=window.innerWidth ; //document.all.DieseDatei.offsetWidth;
  	var y=window.innerHeight ; //document.all.DieseDatei.offsetWidth;
  	var d1 = document.getElementById('debug1');
  	var d2 = document.getElementById('debug2');
  if (d1.hasChildNodes())
  {
  	d1.replaceChild(Builder.node('p',x ),d1.firstChild);
  }
  else
  {
  d1.appendChild( Builder.node('p',x ));//document.all.DieseDatei.offsetWidth));
  }


  if (d2.hasChildNodes())
  {
  	d2.replaceChild(Builder.node('p',y ),d2.firstChild);
  }
  else
  {
	  d2.appendChild( Builder.node('p',y ));//document.all.DieseDatei.offsetWidth));
  }
*/

}
function positionieren(obj_id, links, oben) {
    var obj_ref = document.getElementById(obj_id);
    
    if(obj_ref != null)
    {
    	obj_ref.style.top = oben + 'px';
    	obj_ref.style.left = links + 'px';
    }

    
}

function FaderLaunch() {
    var theimg = document.getElementById(gblPhotoShufflerImgId);
    if(theimg != null)
    {
    	gblOnDeck = ++gblOnDeck % gblDeckSize;
    	setOpacity(theimg, 0);
    	theimg.src = gblImg[gblOnDeck];
    	
    }
    setTimeout("FadeIn()", 10);
}

function FadeIn() {
    var theimg = document.getElementById(gblPhotoShufflerImgId);
    var fadeDelta = 100 / (30 * gblFadeSeconds);
	debug();

	if (gblOpacity <= 0) {
        gblPicPosX = gblPosArray[gblPosIndex];
        gblPosIndex = ++gblPosIndex % gblPosSize;
        positionieren(gblPhotoShufflerDivId, gblPicPosX, 25);
        gblOpacity = 1;
    }
	
	if(theimg != null)
	{
		gblOpacity += fadeDelta;
		setOpacity(theimg, gblOpacity);
	}
    if (gblOpacity < 100)
        setTimeout("FadeIn()", 30);  // 1/30th of a second
    else
        setTimeout("FadeOut()", 1000);  // 1/30th of a second

}

function FadeOut() {
    var theimg = document.getElementById(gblPhotoShufflerImgId);
    
	debug();
	var fadeDelta = 100 / (30 * gblFadeSeconds);
    gblOpacity -= fadeDelta;
    //++gblPicPosX;
    //positionieren(gblPhotoShufflerDivId, gblPicPosX, 5);
    if(theimg != null)
    {
    	setOpacity(theimg, gblOpacity);
    }
    if (gblOpacity > 0)
        setTimeout("FadeOut()", 30);  // 1/30th of a second
    else {
        setTimeout("FadeIn()", 1000);  // 1/30th of a second
        // Next();
        if(theimg != null)
        {
        	gblOnDeck = ++gblOnDeck % gblDeckSize;
        	theimg.src = gblImg[gblOnDeck];
        }

    }
    
}



function setOpacity(obj, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    if(obj != null)
    {
    	// 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;
    }
}




