﻿/**********************************************************
Script:   JavaScript Cross-Browser SlideShow Script
          With Cross-Fade Effect between Images
          Adjustable Timing and Unlimited Images
Function: Displays images continuously in a slideshow
          presentation format, with a fade effect on
          image transitions.
Browsers: All common browsers: NS3-6, IE 4-6
          Fade effect only in IE; others degrade gracefully
Author:   etLux
***********************************************************/

//Step 1.
//Put the following script in the head of your page:

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

var slideShowSpeed = 5000;  // Set slideShowSpeed (milliseconds)
var crossFadeDuration = 9   // Duration of crossfade (seconds)

// Specify the image files
var Pic = new Array();
Pic[0] = '/content/images/homepageimages/01.jpg';
Pic[1] = '/content/images/homepageimages/02.jpg';
Pic[2] = '/content/images/homepageimages/03.jpg';
Pic[3] = '/content/images/homepageimages/04.jpg';
Pic[4] = '/content/images/homepageimages/05.jpg';
Pic[5] = '/content/images/homepageimages/06.jpg';

// =======================================
// do not edit anything below this line
// =======================================

var t;
var j = 0;
var p = Pic.length;

var preLoad = new Array();
for (i = 0; i < p; i++){
    preLoad[i] = new Image();
    preLoad[i].src = Pic[i];
}

function runSlideShow() {
    FadeInImage('SlideShow', Pic[j],'SlideshowContainer');
    j = j + 1;
    if (j > (p - 1)) { j = 0; }
    t = setTimeout('runSlideShow()', slideShowSpeed)}

function SetOpacity(object, opacityPct) {
    // IE.
    object.style.filter = 'alpha(opacity=' + opacityPct + ')';
    // Old mozilla and firefox
    object.style.MozOpacity = opacityPct / 100;
    // Everything else.
    object.style.opacity = opacityPct / 100;
}

function ChangeOpacity(id, msDuration, msStart, fromO, toO) {
    var element = document.getElementById(id);
    var opacity = element.style.opacity * 100;
    var msNow = (new Date()).getTime();
    opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
    if (opacity < 0)
        SetOpacity(element, 0)
    else if (opacity > 100)
        SetOpacity(element, 100)
    else {
        SetOpacity(element, opacity);
        element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")", 1);
    }
}

function FadeIn(id) {
    var element = document.getElementById(id);
    if (element.timer) window.clearTimeout(element.timer);
    var startMS = (new Date()).getTime();
    element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)", 1);
}

function FadeOut(id) {
    var element = document.getElementById(id);
    if (element.timer) window.clearTimeout(element.timer);
    var startMS = (new Date()).getTime();
    element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)", 1);
}

function FadeInImage(foregroundID, newImage, backgroundID) {
    var foreground = document.getElementById(foregroundID);
    if (backgroundID) {
        var background = document.getElementById(backgroundID);
        if (background) {
            background.style.backgroundImage = 'url(' + foreground.src + ')';
            background.style.backgroundRepeat = 'no-repeat';
        }
    }
    SetOpacity(foreground, 0);
    foreground.setAttribute('src', newImage);
    //foreground.src = newImage;
    if (foreground.timer) window.clearTimeout(foreground.timer);
    var startMS = (new Date()).getTime();
    foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)", 10);
}


