// Copyright 2010 by damxDESIGN GbR, Sandberg 2, 29339 Wathlingen
// You may not edit or use this code without permission

var width='520px';
var height='206px';
var galleryImages = new Array('images/layout.contentpic.musikgarten2.jpg','images/layout.contentpic.musikgarten3.jpg','images/layout.contentpic.musikgarten4.jpg');

var fadeTime=1500;
var viewTime=4000;

var zIndex1=2;
var zIndex2=1;

var box1 = document.createElement('div');
var box2 = document.createElement('div');


function slideshowInit(pe){
	box1.style.backgroundImage='url("'+galleryImages[0]+'")';
	box1.style.width=width;
	box1.style.height=height;
	box1.style.position='absolute';
	box1.style.zIndex=zIndex1;
	box1.id='box1';
	box2.style.backgroundImage='url("'+galleryImages[1]+'")';
	box2.style.width=width;
	box2.style.height=height;
	box2.style.position='absolute';
	box2.style.zIndex=zIndex2;
	box2.id='box2';
	el=document.getElementById(pe);
	if (el){
		el.appendChild(box1);
		el.appendChild(box2);
		slideshowRun(0);
	}
}

function slideshowRun(j){
	if (galleryImages[j]){
		fade(j);
	} else {
		slideshowRun(0);
		return;
	}
	j++;
	setTimeout('slideshowRun('+j+')',viewTime);
}

function fade(x){
	if (box1.style.zIndex==zIndex1){
		box2.style.backgroundImage='url("'+galleryImages[x]+'")';
		box2.style.opacity=1;
		box2.style.filter='alpha(opacity=100)';
		box1.fadeTimeLeft=fadeTime;
		setTimeout('animateFade("'+new Date().getTime()+'","'+box1.id+'")',33);
	} else {
		box1.style.backgroundImage='url("'+galleryImages[x]+'")';
		box1.style.opacity=1;
		box1.style.filter='alpha(opacity=100)';
		box2.fadeTimeLeft=fadeTime;
		setTimeout('animateFade("'+new Date().getTime()+'","'+box2.id+'")',33);
	}
}

function animateFade(lastTick, eid) {
  var element=document.getElementById(eid);
  var curTick = new Date().getTime();
  var elapsedTicks = curTick-lastTick;
  if(element.fadeTimeLeft <= elapsedTicks) {
    element.style.opacity='0';
    element.style.filter='alpha(opacity=100)';
	if (element==box1){
		box2.style.zIndex=zIndex1;
		box1.style.zIndex=zIndex2;
	} else {
		box1.style.zIndex=zIndex1;
		box2.style.zIndex=zIndex2;	
	}
    return;
  }
  element.fadeTimeLeft-=elapsedTicks;
  var newOpVal=element.fadeTimeLeft/fadeTime;
  element.style.opacity=newOpVal;
  element.style.filter='alpha(opacity = '+(newOpVal*100)+')';
  setTimeout('animateFade("'+curTick+'","'+eid+'")',33);
}

