﻿var showCurSlide = 0
var showDivIDTop = "Main1LeftImg2"
var showDivIDBot = "Main1LeftImg1"
var showTimeTrans = 1500
var showTimeWait = 8500
var showFPS = 29

function RunShow() {
    document.getElementById(showDivIDTop).style.backgroundImage = "url(" + imgArr1[showCurSlide] + ")";
    showCurSlide = showCurSlide + 1
    document.getElementById(showDivIDBot).style.backgroundImage = "url(" + imgArr1[showCurSlide] + ")";
    setTimeout("RunShowTrans1()", showTimeWait)
}

function RunShowTrans1() {
    var steps = Math.ceil(showFPS * (showTimeTrans / 1000));
    var delta = 100 / steps //(toOpacity - fromOpacity) / steps;
    RunShowTrans1Step(0, steps, delta, (showTimeTrans / steps));
}
function RunShowTrans1Step(stepNum, steps, delta, timePerStep) {
    //fade out top, load next pic into top
    SetOpacity(document.getElementById(showDivIDTop), 100 - Math.round(delta * stepNum));
    if (stepNum < steps) {
        setTimeout("RunShowTrans1Step(" + (stepNum + 1) + ", " + steps + ", " + delta + ", " + timePerStep + ");", timePerStep);
    }
    else {
        showCurSlide = (showCurSlide >= (imgArr1.length - 1)) ? 0 : showCurSlide + 1;
        document.getElementById(showDivIDTop).style.backgroundImage = "url(" + imgArr1[showCurSlide] + ")";
        setTimeout("RunShowTrans2()", showTimeWait)
    }
}
function RunShowTrans2() {
    var steps = Math.ceil(showFPS * (showTimeTrans / 1000));
    var delta = 100 / steps //(toOpacity - fromOpacity) / steps;
    RunShowTrans2Step(0, steps, delta, (showTimeTrans / steps));
}
function RunShowTrans2Step(stepNum, steps, delta, timePerStep) {
    //fade in top, load next pic into bottom
    SetOpacity(document.getElementById(showDivIDTop), Math.round(delta * stepNum));
    if (stepNum < steps) {
        setTimeout("RunShowTrans2Step(" + (stepNum + 1) + ", " + steps + ", " + delta + ", " + timePerStep + ");", timePerStep);
    }
    else {
        showCurSlide = (showCurSlide >= (imgArr1.length - 1)) ? 0 : showCurSlide + 1;
        document.getElementById(showDivIDBot).style.backgroundImage = "url(" + imgArr1[showCurSlide] + ")";
        setTimeout("RunShowTrans1()", showTimeWait)
    }
}


function SetOpacity(elem, opacityAsInt) {
    var opacityAsDecimal = opacityAsInt;

    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100;
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0;

    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0

    if (navigator.appName == 'Microsoft Internet Explorer') {
        elem.style.filter = "alpha(opacity=" + opacityAsInt + ")";
    }
    else {
        elem.style.opacity = (opacityAsDecimal);
    }
}

//---------------------------------Gallery
function galLoadImg(img, title) {
    img = "images/galleryl/" + img + ".jpg"

    var linWrite = "<img src=\"" + img + "\"/>"
    if (title) {
        linWrite = linWrite + "<p>" + title + "</p>";
    }
    document.getElementById("galRightDisplay").innerHTML = linWrite;
}

//--------------------------------Menu (master page)
function menOver(elem) {
    elem.src = elem.src.replace("1.png", "2.png")
}
function menOut(elem) {
    elem.src = elem.src.replace("2.png", "1.png")
}
function preloadImages() {
    img1 = new Image();
    img1.src = "_common/men_about2.png";
    img2 = new Image();
    img2.src = "_common/men_contact2.png";
    img3 = new Image();
    img3.src = "_common/men_gallery2.png";
    img4 = new Image();
    img4.src = "_common/men_home2.png";
}
