/*
 * Simple Javascript Slideshow
 *
 * Written by Nick Murphy
 * Copyright (c) 2005 Meta 13 Interactive <http://www.meta13.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

//
// NOTE: Begin customization
//

// This is the prefix for the DOM identifiers of images to be rotated within
// the document.  Remember that the id sequence is to be zero-based; i.e., the
// id of your first image must be [imageIdPrefix]0.
imageIdPrefix = 'img';

// This is the number of images that will be rotated in your document.
numImages = 3;

// The percentage of opacity by which to step per frame.
opacityDelta = 3;

// This is the delay, in milliseconds, to pause the fade effect during the
// frame that an image has faded in completely.
fullOpacityDelay = 3000;

// This is the delay, in milliseconds, between all other frames.
defaultDelay = 75;

//
// NOTE: End customization
//

userAgentName = navigator.userAgent.toLowerCase();

window.onload = function() {
    initImages();
    fadeImages(0, 0);
}

function initImages() {
    if (document.getElementById)
	for (var i = 0; i < numImages; i++) {
	    var image = document.getElementById(imageIdPrefix + i);
	    setOpacity(image, 0);
	    image.style.visibility = 'visible';
	}
}

function fadeImages(i, alpha) {
    if (document.getElementById) {
	var frameDelay;
	if (alpha >= 100) {
	    var oldImage = document.getElementById(imageIdPrefix +
						   (i % numImages));
	    setOpacity(oldImage, 0);
	    frameDelay = fullOpacityDelay;
	    alpha = 0;
	    i++;
	} else
	    frameDelay = defaultDelay;

	var image1 = document.getElementById(imageIdPrefix +
					     (i % numImages));
	var image2 = document.getElementById(imageIdPrefix +
					     ((i + 1) % numImages));

	setOpacity(image1, 100 - alpha);
	setOpacity(image2, alpha);

	alpha += opacityDelta;

	window.setTimeout("fadeImages(" + i + ", " + alpha + ")", frameDelay);
    }
}

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

    obj.style.filter = "alpha(opacity:" + opacity + ")";
    obj.style.KHTMLOpacity = opacity/100;
    obj.style.MozOpacity = opacity/100;
    obj.style.opacity = opacity/100;
}

// slideshow.js

