
function setupMenubar()
{
    $('#menubar div.submenu').hide();

    $('#menubar li.dropdown').mouseenter(function()
    {
        $(this).children('div.submenu').fadeIn('fast');
    });

    $('#menubar li.dropdown').mouseleave(function()
    {
        $(this).children('div.submenu').fadeOut('fast');
    });
}

function setupPageLayout()
{
    $('#footer-containment').addClass('footer-containment-absolute');

    $('#containment-heightsensor').resize(function() { updatePageLayout(); });
    $('#footer-containment').resize(function() { updatePageLayout(); });
    $(window).resize(function() { updatePageLayout(); });

    updatePageLayout();
}

function updatePageLayout()
{
    if($(window).height() > $('#containment-heightsensor').outerHeight() && 
       !$('#containment').hasClass('containment-fullheight'))
    {
        $('#containment').addClass('containment-fullheight');
        $('#containment-shadow-left').addClass('containment-fullheight');
        $('#containment-shadow-right').addClass('containment-fullheight');
        $('#containment-background').addClass('containment-fullheight');
        $('body').addClass('body-noscroll');
    }

    if($(window).height() < $('#containment-heightsensor').outerHeight() && 
       $('#containment').hasClass('containment-fullheight'))
    {
        $('#containment').removeClass('containment-fullheight');
        $('#containment-shadow-left').removeClass('containment-fullheight');
        $('#containment-shadow-right').removeClass('containment-fullheight');
        $('#containment-background').removeClass('containment-fullheight');
        $('body').removeClass('body-noscroll');
    }

    $('#containment-heightsensor').css('padding-bottom', $('#footer-containment').outerHeight());
}

function setupLoginRegister()
{
    $('#login-link').attr('href', '#');
    $('#register-link').attr('href', '#');

    $('#login-link').click(function() 
    {
        $('#login-menu').slideUp('fast', function()
        {
            $('#login-dialog').slideDown('fast', function()
            {
                $('#login-dialog input').first().focus();
            });
        });

        return false;
    });

    $('#cancel-login').click(function()
    {
        $('#login-dialog').slideUp('fast', function()
        {
            $('#login-menu').slideDown('fast');
        });
    });

    $('#register-link').click(function() 
    {
        $('#login-menu').slideUp('fast', function()
        {
            $('#register-dialog').slideDown('fast', function()
            {
                $('#register-dialog input').first().focus();
            });
        });

        return false;
    });

    $('#cancel-register').click(function()
    {
        $('#register-dialog').slideUp('fast', function()
        {
            $('#login-menu').slideDown('fast');
        });
    });
}

$(document).ready(function() 
{
    setupMenubar();
    setupPageLayout();
    setupLoginRegister();
});

