﻿// SLIDESHOW ROTATION FUNCTION

var displayNUM;
var IMGrotation;
var imageDiv;
var timer;
var digit;
var displayNumPrev;
var imgArray;
var fadeOUTcompleted;

timer = 2000;
displayNUM = 0;
  
function rotateSet(id) { 
    imageDiv = document.getElementById(id);
    imgArray = imageDiv.getElementsByTagName('img');
    
    if (imgArray != false) {
        for(img = 0; img < imgArray.length; img++) {
            var imgElem = imgArray[img];
            var imgElemID = imgElem.getAttribute('id'); 
            imgElem.src ="/Newsletter/"+ imgElemID +".jpg"
        }
    }
    rotateSetTimer(id);
}
      
function rotateSetTimer(id) {
    IMGrotation = setInterval('rotateFunc("'+id+'");',timer);
}

function rotateFunc(id) {
    imageDiv.style.backgroundImage = 'none';

    for(img = 0; img < imgArray.length; img++) {
      imgArray[img].style.display = 'none';
    }
    if (displayNumPrev != null) {
        imgArray[displayNumPrev].style.display = 'block';
        fadeInitOUT(imgArray[displayNumPrev]);
    } else {
        fadeOUTcompleted = true;
    }
    imgArray[displayNUM].style.display = 'block';
    if (fadeOUTcompleted) {
        fadeInitIN(imgArray[displayNUM]);
    }

    if (displayNUM >= (imgArray.length - 1)) {
        displayNumPrev = displayNUM;
        displayNUM = 0;
    } else {
        displayNumPrev = displayNUM;
        displayNUM++;
    }
}
// ------------------------------------------------
// FADE IN SCRIPT

/*
Better(?) Image fader (C)2004 Patrick H. Lauke aka redux
Inspired by Richard Rutter / Clagnut http://www.clagnut.com/blog/1299/ 
Original concept and code adapted from Couloir http://www.couloir.org/ 
preInit "Scheduler" idea by Cameron Adams aka The Man in Blue
http://www.themaninblue.com/writing/perspective/2004/09/29/ 
*/

/* redux by ali malik oct 2 2008 */

/* general variables */

// var fadeTargetId = 'photo'; /* change this to the ID of the fadeable object */
var fadeINTarget;
var fadeOutTarget;
var preInitTimer;

/* functions */


function fadeInitIN(imgTag) {
	if (document.getElementById) {
	   fadeINTarget = imgTag;
		if (fadeINTarget.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			fadeINTarget.style.MozOpacity = 0;
		} else if (fadeINTarget.style.opacity!=null) {
			/* CSS3 compatible */
			fadeINTarget.style.opacity = 0;
		} else if (fadeINTarget.style.filter!=null) {
			/* IE's proprietary filter */
			fadeINTarget.style.filter = "alpha(opacity=0)";
		}
		/* make the object visible again */
		window.setTimeout("fadeIn(0)", 250);
	}
}

function fadeIn(opacity) {
	if (fadeINTarget) {
		if (opacity <= 100) {
			if (fadeINTarget.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				fadeINTarget.style.MozOpacity = (opacity/100)-.001;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (fadeINTarget.style.opacity!=null) {
				/* CSS3 compatible */
				fadeINTarget.style.opacity = (opacity/100)-.001;
			} else if (fadeINTarget.style.filter!=null) {
				/* IE's proprietary filter */
				fadeINTarget.style.filter = "alpha(opacity="+opacity+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}
			opacity += 10;
			window.setTimeout("fadeIn("+opacity+")", 25);
		}
	}
}

function fadeInitOUT(imgTag) {
	if (document.getElementById) {
	   fadeOutTarget = imgTag;
		if (fadeOutTarget.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			fadeOutTarget.style.MozOpacity = 1.0;
		} else if (fadeOutTarget.style.opacity!=null) {
			/* CSS3 compatible */
			fadeOutTarget.style.opacity = 1.0;
		} else if (fadeOutTarget.style.filter!=null) {
			/* IE's proprietary filter */
			fadeOutTarget.style.filter = "alpha(opacity=100)";
		}
		/* make the object visible again */
		window.setTimeout("fadeOut(100)", 1);
	}
}

function fadeOut(opacity) {
	if (fadeOutTarget) {
		if (opacity >= 0) {
			if (fadeOutTarget.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				fadeOutTarget.style.MozOpacity = (opacity/100);
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (fadeOutTarget.style.opacity!=null) {
				/* CSS3 compatible */
				fadeOutTarget.style.opacity = (opacity/100);
			} else if (fadeOutTarget.style.filter!=null) {
				/* IE's proprietary filter */
				fadeOutTarget.style.filter = "alpha(opacity="+opacity+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}
			opacity -= 10;
			window.setTimeout("fadeOut("+opacity+")", 25);
		}
	}
    fadeOUTcompleted = true;
}
