// JavaScript Document
/**
 * Script Author: Wolfgang.Marx@wolfgangmarx.net
 **/
//time to start in secconds.
var startAfter = 3000;
//speed to fade.
var blendSpeed = 50;
//How long should Image stop befor next one Fades.
var showTime = 5000;
//should files loop after last image was showen. true || false
var loopImages = true;

var firstElementToFade = 'ImageEffect1';
var secondElementToFade = 'ImageEffect2';

//List of images to include
var arrImages = new Array(
                          '/image.php?id=2589',
                          '/image.php?id=2457',
                          '/image.php?id=2436',
                          '/image.php?id=2439',
                          '/image.php?id=2441',
                          '/image.php?id=2443',
'/image.php?id=2558',
'/image.php?id=2557',
                          '/image.php?id=2445',
                          '/image.php?id=2447',
                          '/image.php?id=2449',
                          '/image.php?id=2451',
                          '/image.php?id=2453',
                          '/image.php?id=2455',
                          '/image.php?id=2459',
                          '/image.php?id=2461',
			  '/image.php?id=2463',
                          '/image.php?id=2465',
                          '/image.php?id=2467',
                          '/image.php?id=2469',
'/image.php?id=2472',
                          '/image.php?id=2470');

//This function starts the fade.
window.onload = init;

function init() {
  var objElement1 = getElement(firstElementToFade);
  var objElement2 = getElement(secondElementToFade);
  if(navigator.appName == 'Microsoft Internet Explorer') {
    objElement2.style.top = '-323px';
  } else {
    objElement2.style.top = '-320px';
  }
  setTimeout(function() { fadeImage(objElement1, objElement2, 100, 0, 0) }, startAfter);
}

function fadeImage(objElement1, objElement2, opacityOut, opacityIn, curImage) {
	if (opacityOut > 0) {
		setOpacity(objElement1, opacityOut - 3);
		setOpacity(objElement2, opacityIn + 3);
		opacityOut = opacityOut - 3;
		opacityIn = opacityIn + 3;
		setTimeout(function() {fadeImage(objElement1, objElement2, opacityOut, opacityIn, curImage)}, blendSpeed);
  } else {
    if(curImage < arrImages.length-1) {
      objElement1.src = arrImages[curImage + 1];
      setTimeout(function() { fadeImage(objElement2, objElement1, 100, 0, curImage+1) }, showTime);
    } else {
      if (loopImages) {
        objElement1.src = arrImages[0];
        setTimeout(function() { fadeImage(objElement2, objElement1, 100, 0, 0) }, showTime);
      }
    }
  }
}

function getElement(elementId) {
    try {
        if(document.getElementById) {
            return document.getElementById(elementId);
        } else {
            return document.all[elementId];
        }
    } catch(e) { }
}

function setOpacity(obj, o) {
    obj.style.opacity = (o / 100);
    obj.style.MozOpacity = (o / 100);
    obj.style.KhtmlOpacity = (o / 100);
    obj.style.filter = 'alpha(opacity=' + o + ')';
}