function enableFooterDialogTab (textId) {

    // Disable active tabs
    $('#footerDialog').find('.active')
        .removeClass('active')
    .end()
        .find('#'+textId+'_headline, #'+textId+'_body')
            .addClass('active');
    
}

var hideFooterDialog = function ()
{
    var int = 250;
    if (mariaBrowser_ie)
        int=0;
    
    // Fade in both
    $('#footerDialogOverlay').fadeOut(int);
    $('#footerDialog').fadeOut(int);
}

function showFooterDialog(textId) {
    log ("showing footerDialog for "+textId);
    
    // Get the overlay
    var overlay = $('#footerDialogOverlay');

    // Get the dialog
    var dialog = $('#footerDialog');

    
    // Enable the prefered tab
    enableFooterDialogTab(textId);

    var int = 250;
    if (mariaBrowser_ie)
        int=0;
    
    // Fade in both
    overlay.fadeIn(int);
    dialog.fadeIn(int);
    
    // Get the header list
    var headerList = dialog.find('#footerDialogHeader ul');
  
//     // Set up the header events
//     headerList.find('li[class!=close]').click(function()
//     {
//         // Get the tab index of the clicked tab
//         var newIndex = $(this).parent().find('li').index(this);
//         
//         // Enable the tab
//         enableFooterDialogTab(newIndex, true);
//     });
    
    // Set up the close events
    dialog.find('.close').click(function()
    {
        hideFooterDialog();
    });
    
}

function tryOpenFooterOverlay (hash) {
    if (hash === 'terms' && $("#gtcText_headline").length > 0) {
        showFooterDialog('gtcText');
    } else if (hash === 'privacy' && $("#privacyText_headline").length > 0) {
        showFooterDialog('privacyText');
    } else if (hash === 'imprint' && $("#imprintText_headline").length > 0) {
        showFooterDialog('imprintText');
    } else if (hash === 'revocation' && $("#revocationText_headline").length > 0) {
        showFooterDialog('revocationText');
    }
}

var oldHash = location.hash;

function startHashSupervisor () {

    setInterval(function () {
        if (location.hash != oldHash) {
            switch (location.hash) {
                case "#terms":  $("#openTerms").click(); break;
                case "#privacy":  $("#openPrivacy").click(); break;
                case "#imprint":  $("#openImprint").click(); break;
                case "#revocation":  $("#openRevocation").click(); break;
            }
            oldHash = location.hash;
        }
    },100);
    
}


