/*
	ELSSlideshowKit.js
	
	Copyright (c) 2006, Errol Sayre, The University of Mississippi
	All rights reserved.
	
	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:
	•	Redistributions of source code must retain the above copyright notice,
		this list of conditions and the following disclaimer.
	•	Redistributions in binary form must reproduce the above copyright
		notice, this list of conditions and the following disclaimer in the
		documentation and/or other materials provided with the distribution.
	•	Neither the name of the <ORGANIZATION> nor the names of its
		contributors may be used to endorse or promote products derived from
		this software without specific prior written permission.
	
	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
	
	This file packages the various classes required to use ELSSlideshow ojbects.
	
	For more information regarding the use of ELSSlideshow, see the bundled
	documentation as well as the raw source file ELSSlideshow.js.
	
*/
function ELSEventManager() { var instanceSelf = this; var instanceClass = instanceSelf.constructor.prototype; var instanceIdentifier; instanceSelf.addEventListener = addEventListener; instanceSelf.removeEventListener = removeEventListener; instanceSelf.callEventListeners = callEventListeners; var eventListeners; function addEventListener(eventName, eventListener) { if (eventListeners == null) { eventListeners = new Array(); } eventName = eventName.toLowerCase(); if (eventName != "") { if (eventListeners[eventName] == null) { eventListeners[eventName] = new Array(); } var eventListenerIndex = -1; for (var listenerIndex = 0; listenerIndex < eventListeners[eventName].length; listenerIndex++) { if (eventListeners[eventName][listenerIndex] == eventListener) { eventListenerIndex = listenerIndex; listenerIndex = eventListeners[eventName].length; } } if (eventListenerIndex == -1) { eventListeners[eventName][eventListeners[eventName].length] = eventListener; } } } function removeEventListener(eventName, eventListener) { if (eventListeners != null) { eventName = eventName.toLowerCase(); if (eventName != "") { if (eventListeners[eventName] != null) { for (listenerIndex = eventListeners[eventName].length - 1; listenerIndex >= 0; listenerIndex--) { if (eventListeners[eventName][listenerIndex] == eventListener) { eventListeners[eventName].splice(listenerIndex, 1); } } } } } } function callEventListeners(eventName) { if (eventListeners != null) { eventName = eventName.toLowerCase(); if (eventListeners[eventName] != null) { for (listenerIndex = 0; listenerIndex < eventListeners[eventName].length; listenerIndex++) { try { eventListener = eventListeners[eventName][listenerIndex]; eventListener(); } catch (exception) { alert(exception); eventListeners[eventName].splice(listenerIndex, 1); listenerIndex--; } } } } } }
function ELSImageTransitioner() { var instanceSelf = this; var instanceClass = this.constructor.prototype; var instanceIdentifier; instanceSelf.start = start; instanceSelf.stop = stop; instanceSelf.pause = pause; instanceSelf.resume = resume; instanceSelf.animate = animate; instanceSelf.getElement = getElement; instanceSelf.setTransitionImage = setTransitionImage; instanceSelf.setTransitionImageAndStart = setTransitionImageAndStart; instanceSelf.setTransitionImageAndStartWithDelay = setTransitionImageAndStartWithDelay; var imageContainer; var transitionContainer; var currentImage; var transition; var transitionImage; var transitionInterval; var transitionSpeed; var startDelayTimeout; var eventManager; eventManager = new ELSEventManager(); instanceSelf.addEventListener = eventManager.addEventListener; instanceSelf.removeEventListener = eventManager.removeEventListener; transition = 'fadein'; transitionSpeed = 25; function getElement() { return imageContainer; } function setTransitionImage(theImage) { if ((typeof theImage == 'string') && (theImage != '')) { transitionImage = theImage; } else if ((theImage) && (theImage.nodeType == 1) && (theImage.src != '')) { transitionImage = theImage.src; } else { transitionImage = null; } if (window.ActiveXObject) { transitionContainer.style.filter = 'alpha(opacity=0)'; } transitionContainer.style.opacity = 0; } function setTransitionImageAndStart(theImage) { stop(); setTransitionImage(theImage); start(); } function setTransitionImageAndStartWithDelay(theImage, theDelay) { stop(); setTransitionImage(theImage); startDelayTimeout = setTimeout('window.ELSImageTransitionerInstances[' + instanceIdentifier + '].start();', theDelay); } function start() { try { clearInterval(transitionInterval); } catch (exception) { } transitionInterval = null; try { clearTimeout(startDelayTimeout); } catch (exception) { } startDelayTimeout = null; startFade(); eventManager.callEventListeners('start'); } function pause() { try { clearInterval(transitionInterval); } catch (exception) { } transitionInterval = null; try { clearTimeout(startDelayTimeout); } catch (exception) { } startDelayTimeout = null; eventManager.callEventListeners('pause'); } function resume() { transitionInterval = setInterval('window.ELSImageTransitionerInstances[' + instanceIdentifier + '].animate();', 1 * transitionSpeed); eventManager.callEventListeners('resume'); } function stop() { try { clearInterval(transitionInterval); } catch (exception) { } transitionInterval = null; try { clearTimeout(startDelayTimeout); } catch (exception) { } startDelayTimeout = null; stopFade(); eventManager.callEventListeners('stop'); } function finish() { clearInterval(transitionInterval); transitionInterval = null; stopFade(); eventManager.callEventListeners('finish'); } function animate() { animateFade(); } function startFade() { transitionContainer.style.backgroundImage = 'url(' + transitionImage + ')'; if (window.ActiveXObject) { transitionContainer.style.filter = 'alpha(opacity=0)'; } transitionContainer.style.opacity = 0; if (window.ActiveXObject) { imageContainer.style.filter = 'alpha(opacity=100)'; } imageContainer.style.opacity = 1; if (imageContainer.style.backgroundImage != transitionContainer.style.backgroundImage) { transitionInterval = setInterval('window.ELSImageTransitionerInstances[' + instanceIdentifier + '].animate();', 1 * transitionSpeed); } else { finish(); } } function animateFade() { var opacity = 0; if (transitionContainer.style.opacity > 0) { opacity = Math.ceil(transitionContainer.style.opacity * 1000); } opacity += 50; if (window.ActiveXObject) { opacity += 100; } if (opacity > 1000) { opacity = 1000; } if (window.ActiveXObject) { transitionContainer.style.filter = 'alpha(opacity=' + Math.ceil(opacity / 10) + ')'; } transitionContainer.style.opacity = (opacity / 1000); if (opacity >= 1000) { finish(); } } function stopFade() { imageContainer.style.backgroundImage = transitionContainer.style.backgroundImage; if (window.ActiveXObject) { transitionContainer.style.filter = 'alpha(opacity=0)'; } transitionContainer.style.opacity = 0; } if (!window.ELSImageTransitionerInstances) { window.ELSImageTransitionerInstances = new Array(); } instanceIdentifier = window.ELSImageTransitionerInstances.length; window.ELSImageTransitionerInstances[window.ELSImageTransitionerInstances.length] = instanceSelf; imageContainer = document.createElement('div'); imageContainer.className = 'ELSImageTransitioner BackgroundLayer'; imageContainer.style.backgroundPosition = '50% 50%'; imageContainer.style.backgroundRepeat = 'no-repeat'; imageContainer.ELSImageTransitioner = instanceSelf; transitionContainer = imageContainer.cloneNode(false); transitionContainer.className = 'ELSImageTransitioner ForegroundLayer'; imageContainer.appendChild(transitionContainer); }
function ELSSlideshow(theImageList, theSlideTime) { var instanceSelf = this; var instanceClass = this.constructor.prototype; var instanceIdentifier; instanceSelf.getElement = getElement; instanceSelf.getStatus = getStatus; instanceSelf.start = start; instanceSelf.stop = stop; instanceSelf.pause = pause; instanceSelf.resume = resume; instanceSelf.nextSlide = nextSlide; instanceSelf.goToSlide = goToSlide; var slideshowContainer; var imageTransitioner; var imageList; var imageLinkElement; var status; var currentSlide; var nextSlide; var slideTime; var slideInterval; var eventManager; eventManager = new ELSEventManager(); instanceSelf.addEventListener = eventManager.addEventListener; instanceSelf.removeEventListener = eventManager.removeEventListener; imageList = []; status = 'Unitialized'; currentSlide = 0; nextSlide = 0; slideTime = 2 * 1000; function getElement() { return slideshowContainer; } function getStatus() { return status; } function start() { nextSlide = (currentSlide + 1) % imageList.length; imageTransitioner.setTransitionImageAndStart(imageList[currentSlide]['src']); status = 'playing'; eventManager.callEventListeners('start'); } function stop() { status = 'stopped'; } function pause() { imageTransitioner.pause(); status = 'paused'; eventManager.callEventListeners('pause'); } function resume() { imageTransitioner.resume(); status = 'playing'; eventManager.callEventListeners('resume'); } function nextSlide() { if (status == 'playing') { if (imageList[currentSlide]['link'] != null) { showImageLink(); } else { hideImageLink(); } currentSlide = nextSlide; nextSlide = (currentSlide + 1) % imageList.length; imageTransitioner.setTransitionImageAndStartWithDelay(imageList[currentSlide]['src'], slideTime); } } function transitionStarted() { eventManager.callEventListeners('transitionStart'); } function goToSlide() { } function showImageLink() { if (imageTransitioner.getElement().parentNode != imageLinkElement) { imageLinkElement = document.createElement('a'); slideshowContainer.replaceChild(imageLinkElement, imageTransitioner.getElement()); imageLinkElement.appendChild(imageTransitioner.getElement()); } imageLinkElement.href = imageList[currentSlide]['link']; imageLinkElement.setAttribute('title', imageList[currentSlide]['title']); imageLinkElement.setAttribute('target', imageList[currentSlide]['target']); } function hideImageLink() { if (imageTransitioner.getElement().parentNode == imageLinkElement) { imageLinkElement.removeChild(imageTransitioner.getElement()); slideshowContainer.replaceChild(imageTransitioner.getElement(), imageLinkElement); imageLinkElement = null; } } if (!window.ELSImageTransitionerInstances) { window.ELSImageTransitionerInstances = new Array(); } instanceIdentifier = window.ELSImageTransitionerInstances.length; window.ELSImageTransitionerInstances[window.ELSImageTransitionerInstances.length] = instanceSelf; slideshowContainer = document.createElement('div'); slideshowContainer.className = 'ELSSlideshow'; slideshowContainer.ELSSlideshow = instanceSelf; imageTransitioner = new ELSImageTransitioner(); imageTransitioner.addEventListener('finish', instanceSelf.nextSlide); slideshowContainer.appendChild(imageTransitioner.getElement()); try { if (typeof(theImageList) == 'string') { alert('AJAX image lists are not supported in this version.'); } else if (typeof(theImageList) == 'object') { for (imageNumber = 0; imageNumber < theImageList.length; imageNumber++) { imageData = null; if (typeof(theImageList[imageNumber]) == 'string') { imageData = []; imageData['src'] = theImageList[imageNumber]; } else if (theImageList[imageNumber]['src']) { imageData = []; imageData['src'] = theImageList[imageNumber]['src']; imageData['title'] = theImageList[imageNumber]['title']; imageData['link'] = theImageList[imageNumber]['link']; imageData['target'] = theImageList[imageNumber]['target']; } if (imageData !== null) { imageList[imageList.length] = imageData; } } } } catch (e) {} if (theSlideTime > 300) { slideTime = theSlideTime * 1; } else if (theSlideTime > 0) { slideTime = theSlideTime * 1000; } } function locateSlideshowsAndInstantiate() { divElements = document.getElementsByTagName('div'); for (divElementIndex = 0; divElementIndex < divElements.length; divElementIndex++) { if (divElements[divElementIndex].className == 'ELSSlideshow') { var imageList = []; var slideTime = 0; if (divElements[divElementIndex].hasChildNodes()) { var currentNode = null; currentNode = divElements[divElementIndex].firstChild; while (currentNode !== null) { if (currentNode.nodeType == 1) { if (currentNode.tagName.toLowerCase() == 'img') { var imageData = []; imageData['src'] = currentNode.src; imageList[imageList.length] = imageData; } else if (currentNode.tagName.toLowerCase() == 'a') { var images = currentNode.getElementsByTagName('img'); for (var imageNumber = 0; imageNumber < images.length; imageNumber++) { var imageData = []; imageData['src'] = images[imageNumber].src; try { if (images[imageNumber].getAttribute('title') != null) { imageData['title'] = images[imageNumber].getAttribute('title'); } else if (currentNode.getAttribute('title') != null) { imageData['title'] = currentNode.getAttribute('title'); } else if (images[imageNumber].getAttribute('alt') != null) { imageData['title'] = images[imageNumber].getAttribute('alt'); } else { imageData['title'] = null; } } catch (e) { imageData['title'] = null; } try { if (currentNode.getAttribute('href') != null) { imageData['link'] = currentNode.getAttribute('href'); } else { imageData['link'] = null; } } catch (e) { imageData['link'] = null; } try { if (currentNode.getAttribute('target') != null) { imageData['target'] = currentNode.getAttribute('target'); } else { imageData['target'] = null; } } catch (e) { imageData['target'] = null; } imageList[imageList.length] = imageData; } } else if (currentNode.tagName.toLowerCase() == 'input') { try { if (currentNode.name.toLowerCase() == 'slidetime') { slideTime = currentNode.value; } } catch (e) { } } } currentNode = currentNode.nextSibling; } } if (imageList.length > 0) { slideshow = new ELSSlideshow(imageList, slideTime); divElements[divElementIndex].parentNode.replaceChild(slideshow.getElement(), divElements[divElementIndex]); slideshow.start(); } } } } try { if (window.attachEvent) { window.attachEvent('onload', locateSlideshowsAndInstantiate); } else if (window.addEventListener) { window.addEventListener('load', locateSlideshowsAndInstantiate); } } catch(e) { if (document.addEventListener) { document.addEventListener("DOMContentLoaded", locateSlideshowsAndInstantiate, false); } } 