function showLoginForm() {
    $('#login_form').toggle('blind', 800);
}

function showFAQForm(target) {
    $('#' + target).toggle('blind', 800);
}

function showFAQResponse(target) {
    $('#' + target).toggle('blind', 800);
}

function closeBox(target) {
    $('#box_modal_background').css('display', 'none');
    $('#' + target).css('display', 'none');
}

$(function() {
    $( "#tabs" ).tabs();
});

function addClass(father, target) {
    $('#' + father + ' > li').removeClass('active');
    $('#' + target).addClass('active');
    getContent(father, target);
}

function getContent(father, target) {
    showWaiter('content_box', 'loading');
    $.ajax({
        type: 'GET',
        url: host_address + 'contents/' + father + '/' + target + '.php',
        success: function(response) {
            hideWaiter();
            $('#content_box').html(response);
            $('#menu_box').css('position', 'relative');
            $('#menu_box').css('top', 'auto');
        }
    });
}

function showWaiter(target, waiter) {
    $('#' + target).html('<div id="waiter" style="text-align: center"><img alt="Attendere" src="img/icons/animated/' + waiter + '.gif" />&nbsp; caricamento in corso...</div>');
}

function hideWaiter() {
    $('#waiter').css('display', 'none');
}

$(window).scroll(function() {
    if ($(window).scrollTop() > 150) {
        $('#menu_box').css('position', 'fixed');
        $('#menu_box').css('top', 5);
    } else {
        $('#menu_box').css('position', 'relative');
        $('#menu_box').css('top', 'auto');
    }
});

function showQuestion(target) {
    showWaiter('faq_q_' + target + ' p', 'retrieving');
    if ($('#faq_q_' + target + ' img.operation').attr('alt') == 'more') {
        $.ajax({
            type: 'GET',
            url: host_address + 'scripts/transact_faq.php?action=show&faq_id=' + target,
            success: function(response) {
                hideWaiter();
                $('#faq_q_' + target).html(response);
                $('#faq_q_' + target + ' img.operation').attr('src', 'img/icons/16/read_less.png');
                $('#faq_q_' + target + ' img.operation').attr('alt', 'less');
            }
        });
    } else {
        $.ajax({
            type: 'GET',
            url: host_address + 'scripts/transact_faq.php?action=hide&faq_id=' + target,
            success: function(response) {
                hideWaiter();
                $('#faq_q_' + target + ' p').html(response);
                $('#faq_q_' + target + ' img.operation').attr('src', 'img/icons/16/read_more.png');
                $('#faq_q_' + target + ' img.operation').attr('alt', 'more');
            }
        });
    }
}

function showResponse(target) {
    $('#faq_r_' + target).toggle('slide', 1000, changeIcon(target));
}

function changeIcon(target) {
    if ($('#faq_q_' + target + ' img.folder').attr('alt') == 'close') {
        $('#faq_q_' + target + ' img.folder').attr('src', 'img/icons/16/open_folder.png');
        $('#faq_q_' + target + ' img.folder').attr('alt', 'open');
    } else {
        $('#faq_q_' + target + ' img.folder').attr('src', 'img/icons/16/close_folder.png');
        $('#faq_q_' + target + ' img.folder').attr('alt', 'close');
    }
}

