﻿var initializeCustomSelectSmall = false;
$(window).resize(function () {
    setFooterPosition();
});

function setFooterPosition() {
    // if height of page is bigger than "content + 40px + footer" then
    // lock footer to the bottom of the page
    var windowHeight = $(window).height();
    var bodyHeight = $('body').height();
    if (bodyHeight < windowHeight) {
        var $footer = $('.footer');
        var footerMargin = parseInt($footer.css('margin-top'));
        footerMargin = footerMargin + windowHeight - bodyHeight;
        if (footerMargin < 50) {
            footerMargin = 50;
        }

        $footer.css('margin-top', footerMargin + 'px');
    }
};

$(document).ready(function () {
    setFooterPosition();

    if ($('.processComplete').length) {        
        $('html, body').animate({ scrollTop: $(document).height() }, 300);
    }

    if ($('.module-contact.xform').length) {
        $('html, body').animate({ scrollTop: $('.module-contact.xform').offset().top }, 300);
    }

    //scroll to page top
    $('.footer ul.right li.top a').click(function () {
        $('html, body').animate({ scrollTop: '0px' }, 300);
    });

    if ($('img.light-box').length) {
        $('img.light-box').each(function () {
            var $this = $(this);
            var src = $this.attr('src');
            var title = $this.attr('alt');
            var a = $('<a/>').attr('href', src);
            a.attr('title', title);
            a.attr('class', 'light-box');
            a.fancybox({ titlePosition: 'inside' });
            $this.wrap(a);
        });
    }

    //main navigation
    $('ul.nav li').mouseover(function () {
        $(this).children('div.sub-nav-wrapper').show();
    }).mouseout(function () {
        $(this).children('div.sub-nav-wrapper').hide();
    });

    $('.header ul.nav li.sub').mouseover(function () {
        $(this).addClass('hover');
    }).mouseout(function () {
        $(this).removeClass('hover');
    });

    $('div.content.blue ul.page-nav a:not(.current)').hover(function () {
        $(this).animate({ backgroundColor: '#0066b1' }, 300);
    },
    function () {
        $(this).animate({ backgroundColor: '#ffffff' }, 300);
    });

    $('div.content.violet ul.page-nav a:not(.current)').hover(function () {
        $(this).animate({ backgroundColor: '#3a0055' }, 300);
    },
    function () {
        $(this).animate({ backgroundColor: '#ffffff' }, 300);
    });

    $('div.content.purple ul.page-nav a:not(.current)').hover(function () {
        $(this).animate({ backgroundColor: '#5a214a' }, 300);
    },
    function () {
        $(this).animate({ backgroundColor: '#ffffff' }, 300);
    });

    $('div.content.light-blue ul.page-nav a:not(.current)').hover(function () {
        $(this).animate({ backgroundColor: '#00aeee' }, 300);
    },
    function () {
        $(this).animate({ backgroundColor: '#ffffff' }, 300);
    });
});
