
$(document).ready(function() {
    banner();
    footer();
    if ($('#cycle').length > 0) {
        slideshow();
    }
})

$(window).resize(function() {
    banner();
    footer();
});

function footer() {
    var windowHeight = $(window).height();
    var containerHeight = $('#container').height();
    var footerHeight = $('#footer').height();
    var totalHeight = windowHeight - (containerHeight + footerHeight);
    if (totalHeight >= 0) {
        
        $('#footer').css('top', totalHeight); //-52
    }
    else {
        $('#footer').css('top', 0);
    }
}


function banner() {
    var windowwidth = $(window).width();
    if (windowwidth <= 954) { //954 = #fixwt
        $('.varw').width(954);
    } else {
        var w = windowwidth > 1200 ? 1200 : windowwidth;
        $('.varw').width(w);
    }
}

function slideshow() {

    if ($('#cycle #img1').is(':visible')) {
        $('#navCycle').hide();
    }

    $('#cycle').cycle({
        fx: 'scrollHorz',
        speed: 500,
        timeout: 4500,
        next: '#prv',
        prev: '#nxt',
        after: onAfter,
        before: onBefore
    });
}

function onAfter(curr, next, opts) {
    if ($('#' + this.id + 'Cap').length > 0) {
        $('#capCycle').fadeIn('fast');
        $('#capCycle p').html($('#' + this.id + 'Cap').html());
    }
}

function onBefore(curr, next, opts) {
    $('#capCycle').fadeOut('slow');
}