var currentOffsetX;
var baseWidth;
var slideOffsetX;

function initsub() {
    currentOffsetX = 0;
    baseWidth = 1200;
    slideOffsetX = baseWidth;

    $('a.lightbox').lightBox();
    doResize();
    //           try {
    //               initpage();
    //           }
    //           catch (err) {
    //           }
    if ($('#Body_hidAutoShowContent').val() == 1) { showInfo(); }
    if ($('#Body_hidIsDynamicPage').val() == 1) {
        $('#divBackgroundImages').hide(); $('#divMenuButtons').hide();
    } else {
        $('#divBackgroundImages').show(); $('#divMenuButtons').show();
    }
}
window.onscroll = function () { doResize(); }
window.onresize = function () { doResize(); }

function showInfo() {
    $('#divContent').fadeIn('slow');
}
function hideInfo() {
    $('#divContent').fadeOut('slow');
}

function doSlide(dir) {
    if (dir == 1) {
        currentOffsetX -= slideOffsetX;
    }
    else if (dir == -1) {
        currentOffsetX += slideOffsetX;
    }
    else{
        currentOffsetX = 0;
    }

    doButtons();

    $('#divBackgroundImages').animate({
        'margin-left': currentOffsetX + (($(window).width() - slideOffsetX) / 2)
    }, {
        duration: 4000,
        easing: 'easeInOutExpo'
    });


}

function doResize() {
    // document.getElementById("divFooter").style.bottom = (-$(window).scrollTop()) + "px";
    var origWidth = slideOffsetX;
    var origHeight = parseInt(slideOffsetX * 0.75);
    var winWidth = $(window).width();
    var winHeight = $(window).height();
    var newWidth = parseInt(winHeight * (origWidth / origHeight));
    var newHeight = winHeight;
    var imgScaleRatio =0.9;


    $(".divImage").width(newWidth);
    $(".divImage").height(newHeight);
    $(".imgBackground").height(newHeight * imgScaleRatio);
    $(".imgBackground").css('margin-top', (winHeight - (newHeight * imgScaleRatio)) / 2);


    slideOffsetX = newWidth;
    if ($('#divBackgroundImages').width() > 0) { currentOffsetX = (currentOffsetX / $('#divBackgroundImages').width()) * (newWidth * $('#divBackgroundImages div').size()); }

    $('#divBackgroundImages').width(newWidth * ($('#divBackgroundImages div').size()));
    $('#divBackgroundImages').css('margin-left', currentOffsetX + (($(window).width() - slideOffsetX) / 2));

    if ($('#Body_hidIsDynamicPage').val() == 1) {
        $("#divContent").css({ top: 16, left: 248, right: 16, bottom: 16 });
    } else {
        $("#divContent").css({ top: 132, left: 364, right: 132, bottom: 132 });
    }
    
    doButtons();
}

function doButtons() {
    if (currentOffsetX >= 0) { $('#aButtonPrev').hide(); } else { $('#aButtonPrev').show() }
    if (currentOffsetX >= 0) { $('#aButtonRewind').hide(); } else { $('#aButtonRewind').show() }
    if (currentOffsetX > -($('#divBackgroundImages').width() - slideOffsetX)) { $('#aButtonNext').show(); } else { $('#aButtonNext').hide() }
}
