﻿// Opacity and Fade in script.
// Script copyright (C) 2008 http://www.cryer.co.uk/.
// Script is free to use provided this copyright header is included.
var c = 0;
var t;
var timer_is_on = 0;
var g = 1;
if (document.images) {
    pic1 = new Image(667, 264);
    pic1.src = "images/mbgu_slide6_01.jpg";

    pic2 = new Image(667, 264);
    pic2.src = "images/mbgu_slide1_01.jpg";

    pic3 = new Image(667, 264);
    pic3.src = "images/mbgu_slide2_01.jpg";
    pic4 = new Image(667, 264);
    pic4.src = "images/mbgu_slide3_01.jpg";

    pic5 = new Image(667, 264);
    pic5.src = "images/mbgu_slide4_01.jpg";

    pic6 = new Image(667, 264);
    pic6.src = "images/mbgu_slide5_01.jpg";


}

function SetOpacity(object, opacityPct) {
    // IE.
    object.style.filter = 'alpha(opacity=' + opacityPct + ')';
    // Old mozilla and firefox
    object.style.MozOpacity = opacityPct / 100;
    // Everything else.
    object.style.opacity = opacityPct / 100;
}
function ChangeOpacity(id, msDuration, msStart, fromO, toO) {
    var element = document.getElementById(id);
    var opacity = element.style.opacity * 100;
    var msNow = (new Date()).getTime();
    opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
    if (opacity < 0)
        SetOpacity(element, 0)
    else if (opacity > 100)
        SetOpacity(element, 100)
    else {
        SetOpacity(element, opacity);
        element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")", 1);
    }
}
function FadeIn(id) {
    var element = document.getElementById(id);
    if (element.timer) window.clearTimeout(element.timer);
    var startMS = (new Date()).getTime();
    element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)", 1);
}
function FadeOut(id) {
    var element = document.getElementById(id);
    if (element.timer) window.clearTimeout(element.timer);
    var startMS = (new Date()).getTime();
    element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)", 1);
}
function FadeInImage(foregroundID, newImage, backgroundID) {
    var foreground = document.getElementById(foregroundID);
    if (backgroundID) {
        var background = document.getElementById(backgroundID);
        if (background) {
            background.style.backgroundImage = 'url(' + foreground.src + ')';
            background.style.backgroundRepeat = 'no-repeat';
        }
    }
    SetOpacity(foreground, 0);
    foreground.src = newImage;
    if (foreground.timer) window.clearTimeout(foreground.timer);
    var startMS = (new Date()).getTime();
    foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)", 10);
}
function timedCount() {
    //document.getElementById('txt').value = c;

    //alert('hello world');
    if (g == 7) {
        g = 1;
    }
    if (c % 10 == 0) {
        FadeInImage('sid', 'images/mbgu_slide' + g + '_01.jpg', 'did');
        g = g + 1;
    }
    c = c + 1;
    t = setTimeout("timedCount()", 1000);
}

// bad implementation
function sleep(milliSeconds) {
    var startTime = new Date().getTime(); // get the current time
    while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}

