// 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=2242',
                          '/image.php?id=2243',
                          '/image.php?id=2244',
                          '/image.php?id=2245',
                          '/image.php?id=2553',
                          '/image.php?id=2555',
                          '/image.php?id=2246',
                          '/image.php?id=2247',
                          '/image.php?id=2248',
                          '/image.php?id=2249',
                          '/image.php?id=2250',
                          '/image.php?id=2252',
                          '/image.php?id=2253',
                          '/image.php?id=2254',
                          '/image.php?id=2255',
                          '/image.php?id=2500',
                          '/image.php?id=2499',
                          '/image.php?id=2587',
                          '/image.php?id=2259',
                          '/image.php?id=2251',
                          '/image.php?id=2260');

//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 + ')';
}