﻿var arrTimeouts_Masthead;
var varLastSlideIndex_Masthead;
var varSpeed_Masthead;
var varSlideTotal_Masthead;

function clearAllTimeouts_Masthead() {
    for (key in arrTimeouts_Masthead) {
        clearTimeout(arrTimeouts_Masthead[key]);
    }
}

function showSlide_Masthead(varSlideIndexIn) {

    if (varSlideIndexIn > varSlideTotal_Masthead) {
        varSlideIndexIn = 1;
    }

    arrTimeouts_Masthead["changeSlideID"] = setTimeout("showSlide_Masthead(" + (varSlideIndexIn + 1) + ")", varSpeed_Masthead * 1000);

    blendImage_Masthead("imgSlideMasthead", 500);

    //set the current image as background
    document.getElementById("divSlideMasthead").style.backgroundImage = "url(upload/images/mastheads/masthead_" + varLastSlideIndex_Masthead + ".jpg)";
    document.getElementById("imgSlideMasthead").src = "upload/images/mastheads/masthead_" + varSlideIndexIn + ".jpg";

    varLastSlideIndex_Masthead = varSlideIndexIn;
}

function blendImage_Masthead(imageid, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //make image transparent
    changeOpac_Masthead(0, imageid);

    //fade in image
    for (i = 0; i <= 100; i++) {
        arrTimeouts_Masthead["fadeSlide" + i] = setTimeout("changeOpac_Masthead(" + i + ",'" + imageid + "')", (timer * speed));
        timer++;
    }
}

//change the opacity for different browsers
function changeOpac_Masthead(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function startSlideShow_Masthead(slideTotalIn, speedIn) {
    arrTimeouts_Masthead = new Array();
    varSpeed_Masthead = speedIn;
    varSlideTotal_Masthead = slideTotalIn;
    varLastSlideIndex_Masthead = 1;
    document.getElementById("imgSlideMasthead").src = "upload/images/mastheads/masthead_1.jpg";
    showSlide_Masthead(1);
}
