var DELAY = 5000;
var TIMEOUT = null;
var SLIDES = Array();
var RUNNING = false;
var TOGGLE = null;
var STATIC_ROOT = "//cstatic.fiu.edu";
var ANIM = null;
var next = null;
var active = null;
var opacity = 0;
var engine = null;
function load() {
    if (window.navigator.appName == "Microsoft Internet Explorer") {
        if (document.documentMode) {
            engine = document.documentMode;
        }
        else {
            engine = 5;
            if (document.compatMode) {
                if (document.compatMode == "CSS1Compat") {
                    engine = 7;
                }
            }
        }
    }
    else
        engine = 9001;

    // Add media stylesheet
    var head = document.getElementsByTagName('head')[0];
    var style = document.createElement('style');
    head.appendChild(style);
    style.media = 'screen';
    style.type = 'text/css';
    style.appendChild(document.createTextNode('#slide_holder > p {position:absolute;top:0;left:0;display:block;}'));

    var pane = document.getElementById('slide_holder');
    pane.parentNode.style.overflow = 'hidden';
    SLIDES = document.getElementById('slide_holder').childNodes;
    if (SLIDES.length < 2)
        return;
    var temp = SLIDES[0].getElementsByTagName('img')[0];
    var index = temp.src.indexOf('/', 9);
    var ctrl = document.createElement('div');
    ctrl.setAttribute('id', 'slide_nav');
    pane.parentNode.appendChild(ctrl);
    for (var i = 0; i < SLIDES.length; i++) {
        if (engine < 9)
            SLIDES[i].style.zIndex = '10';
        if (i > 0 && engine < 9) {
            SLIDES[i].style.display = 'none';
            var a = null;
            var img = SLIDES[i].firstChild;
            if (SLIDES[i].firstChild.tagName == 'A') {
                a = img;
                img = a.firstChild;
            }
            if (engine < 8) {
                img.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
                img.style.zIndex = '9';
                if (a != null)
                    a.style.zIndex = '9';
            }
            else
                img.setAttribute('style', 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);z-index:9;');
        }
        a = document.createElement('a');
        a.setAttribute('href', '#');
        a.setAttribute('title', 'Jump to this slide');
        if (engine < 9)
            a.attachEvent('onclick', slideSwitch);
        else
            a.addEventListener('click', slideSwitch, false);
        a.setAttribute('onclick', 'return false;');
        a.appendChild(document.createTextNode(i + 1));
        ctrl.appendChild(a);
    }
    a = document.createElement('a');
    a.id = 'gallery-toggle';
    a.setAttribute('href', '#');
    if (engine < 9)
        a.attachEvent('onclick', slideToggle);
    else
        a.addEventListener('click', slideToggle, false);
    ctrl.appendChild(a);
    TOGGLE = document.createElement('img');
    TOGGLE.setAttribute('id', 'gallery-control');
    TOGGLE.setAttribute('alt', '||');
    TOGGLE.setAttribute('title', 'Pause slideshow');
    TOGGLE.setAttribute('width', '10px');
    TOGGLE.setAttribute('height', '10px');
    TOGGLE.src = STATIC_ROOT + '/pause';
    a.appendChild(TOGGLE);
    if (engine < 9) {
        SLIDES[0].setAttribute('class', 'active');
        SLIDES[0].className = 'active';
        var simg = SLIDES[0].getElementsByTagName('IMG')[0];
        simg.style.position = 'relative';
        simg.style.zIndex = "10";
        simg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
    }
    else
        SLIDES[0].setAttribute('class', 'active');
    slideGo();
}
function slideSwitch() {
    if (engine < 9) {
        if (event)
            var e1 = event.srcElement;
        else
            e1 = window;
    }
    else
        var e1 = this;
    if (ANIM != null)
        clearInterval(ANIM);
    active = getActive();
    if (active === null)
        active = SLIDES[0];
    if (e1 != window && e1.id != 'gallery-toggle' && e1.id != 'gallery-control') {
        if(e1.textContent)
            id = parseInt(e1.textContent) - 1;
        else if(e1.innerText)
            id = parseInt(e1.innerText) - 1;
        next = SLIDES[id];
        if (RUNNING)
            slideToggle();
    }
    else if (active.nextSibling)
        next = active.nextSibling;
    else
        next = SLIDES[0];
    if (engine < 9) {
        opacity = 1;
        active.className = 'last-active';
        next.className = 'active';
        active.setAttribute('class', 'last-active');
        next.setAttribute('class', 'active');
        next.style.opacity = '' + opacity + '';
        next.style.display = 'block';
        active.style.display = 'block';
        var aa = null;
        var aimg = active.firstChild;
        var na = null;
        var nimg = next.firstChild;
        if (aimg.tagName == 'A') {
            aa = aimg;
            aimg = aa.firstChild;
        }
        if (nimg.tagName == 'A') {
            na = nimg;
            nimg = na.firstChild;
        }
        if (engine < 8) {
            aimg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
            aimg.style.zIndex = '9';
            if (aa != null)
                aa.style.zIndex = '9';
            active.style.zIndex = '9';
            nimg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+opacity+')';
            nimg.style.zIndex = '10';
            if (na != null)
                na.style.zIndex = '10';
            next.style.zIndex = '10';
        }
        else {
            aimg.setAttribute('style', 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);z-index:9;');
            nimg.setAttribute('style', 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity='+opacity+');z-index:10;');
        }
    }
    else {
        active.setAttribute('class', 'last-active');
        next.style.opacity = '0';
        next.setAttribute('class', 'active');
    }
    ANIM = setInterval(animate, 10);
    if (RUNNING)
        slideGo();
    return false;
}
function animate() {
    if (engine < 9) {
        var aimg = active.firstChild;
        var nimg = next.firstChild;
        if (aimg.tagName == 'A')
            aimg = aimg.firstChild;
        if (nimg.tagName == 'A')
            nimg = nimg.firstChild;
        opacity += 2;
        if (engine < 8) {
            nimg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+opacity+')';
        }
        else {
            nimg.setAttribute('style', 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity='+opacity+');z-index:10;');
        }
    }
    else
        next.style.opacity = Number(next.style.opacity) + 0.015;
    if (engine < 9) {
        if (Number(opacity) >= 100) {
            clearInterval(ANIM);
            if (engine < 8) {
                nimg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
                aimg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
            }
            else {
                nimg.setAttribute('style', 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);z-index:10;display:block;');
                aimg.setAttribute('style', 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);z-index:10;display:none;');
            }
            active.style.display = 'none';
            next.style.display = 'block';
            active.className = 'slide';
            active.removeAttribute('class');
            opacity = 0;
        }
    }
    else
        if (Number(next.style.opacity) >= 1.0) {
            window.clearInterval(ANIM);
            next.style.opacity = 1;
            active.removeAttribute('class');
            if (active.style.removeProperty)
                active.style.removeProperty('opacity');
            else
                active.style.opacity = '';
        }
}
function slideGo() {
    RUNNING = true;
    TIMEOUT = window.setTimeout(slideSwitch, DELAY);
}
function slidePause(cont) {
    if (cont) {
        RUNNING = true;
        slideSwitch();
    }
    else {
        if (ANIM != null)
            clearInterval(ANIM);
        clearTimeout(TIMEOUT);
        RUNNING = false;
    }
}
function slideToggle() {
    if (RUNNING) {
        TOGGLE.src = STATIC_ROOT + "/play";
        TOGGLE.setAttribute('alt', '→');
        TOGGLE.setAttribute('title', 'Play slideshow');
    }
    else {
        TOGGLE.src = STATIC_ROOT + "/pause";
        TOGGLE.setAttribute('alt', '‖');
        TOGGLE.setAttribute('title', 'Pause slideshow');
    }
    slidePause(!RUNNING);
    return false;
}
function getActive() {
    for (var i = 0; i < SLIDES.length; i++) {
        if (engine < 9) {
            if (SLIDES[i].className == 'active')
                return SLIDES[i];
        }
        else {
            if (SLIDES[i].getAttribute('class') == 'active')
                return SLIDES[i];
        }
    }
    return null;
}
if ( window.addEventListener ) {
    window.addEventListener( "load", load, false );
}
else if ( window.attachEvent ) {
    window.attachEvent( "onload", load );
} else if ( window.onLoad ) {
    window.onload = load;
}
