//Global current image number
var iThumb = 1;

//Timer function for changing pictures
function timerDoBanner() {
    opacityChangeBanner("topBanner" + iThumb, 100, 0, 500);
    imageTimer = setTimeout("timerDoBanner()", 6500);
}

//Add images to the desired div
function addContentBanner() {
    sContent = '<img id="topBanner1" style="border: none; display: none; opacity:0; filter: alpha(opacity=0);" src="' + THEME_URL + 'images/banners/top-banner-1.jpg" width="450" height="333" alt="" />';
    for (iCounter = 2; iCounter <= 6; iCounter++) {
        sContent += '<img id="topBanner' + iCounter + '" style="border: none; display: none; opacity:0; filter: alpha(opacity=0);" src="' + THEME_URL + 'images/banners/top-banner-' + iCounter + '.jpg" width="450" height="333" alt="" /></a>';
    }
    document.getElementById("switchingImages").innerHTML = sContent;
    timerDoBanner();
}

//Change banner opacity
function opacityChangeBanner(iID, iOpacStart, iOpacEnd, iMilliSec) {
    //Speed for each frame
    var iSpeed = Math.round(iMilliSec / 100);
    var iTimer = 0;

    //Determine the direction for the blending, if start and end are the same nothing happens
    if (iOpacStart > iOpacEnd) {
        for(iCounter = iOpacStart; iCounter >= iOpacEnd; iCounter--) {
            setTimeout("changeOpacBanner(" + iCounter + ",'" + iID + "', 'down')", (iTimer * iSpeed));
            iTimer++;
        }
    } else if (iOpacStart < iOpacEnd) {
        if (iOpacStart == 0) {
            document.getElementById(iID).style.display = 'block';
        }
        for(iCounter = iOpacStart; iCounter <= iOpacEnd; iCounter++)
            {
            setTimeout("changeOpacBanner(" + iCounter + ",'" + iID + "', 'up')", (iTimer * iSpeed));
            iTimer++;
        }
    }
}

//Change the opacity for different browsers
function changeOpacBanner(iOpacity, iID, iStatus) {
    var object = document.getElementById(iID).style;
    object.opacity = (iOpacity / 100);
    object.MozOpacity = (iOpacity / 100);
    object.KhtmlOpacity = (iOpacity / 100);
    object.filter = "alpha(opacity=" + iOpacity + ")";

    //Check if picture needs to be changed, and do if necessary
    if ((iStatus == "down") && (iOpacity == 0))
    {
        object.display = 'none';
        if (iThumb < 6) {
            iThumb++;
        } else {
            iThumb = 1;
        }
        opacityChangeBanner("topBanner" + iThumb, 0, 100, 500);
    }
}
